Greasy Fork - Script Counter

Add number of scripts on user's profile page

2014-03-10 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @id greasy-fork-script-counter@loucypher
  3. // @name Greasy Fork - Script Counter
  4. // @namespace https://github.com/LouCypher/userscripts
  5. // @description Add number of scripts on user's profile page
  6. // @version 1.1
  7. // @author LouCypher
  8. // @license WTFPL
  9. // @screenshot https://raw.github.com/LouCypher/userscripts/master/greasyfork/script-counter/screenshot.png
  10. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Script+Counter
  11. // @homepageURL https://greatest.deepsurf.us/scripts/180
  12. // @supportURL https://greatest.deepsurf.us/scripts/180/feedback
  13. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/script-counter/CHANGELOG.txt
  14. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
  15. // @run-at document-end
  16. // @include https://greatest.deepsurf.us/users/*
  17. // @grant none
  18. // ==/UserScript==
  19. /* This program is free software. It comes without any warranty, to
  20. * the extent permitted by applicable law. You can redistribute it
  21. * and/or modify it under the terms of the Do What The Fuck You Want
  22. * To Public License, Version 2, as published by Sam Hocevar. See
  23. * http://www.wtfpl.net/ for more details. */
  24.  
  25.  
  26.  
  27. function throwError() {
  28. throw new Error("Some thing went wrong.");
  29. }
  30.  
  31. // For blue/brown style in Sonny's script
  32. function addStyle(aNum) {
  33. var css = 'body > h2:after { content: " - ' + aNum + ' Scripts" !important; }';
  34. var style = document.head.appendChild(document.createElement("style"));
  35. style.type = "text/css";
  36. style.textContent = css;
  37. }
  38.  
  39. var scriptList = document.querySelectorAll("#user-script-list > li");
  40. var scriptTable = document.getElementById("script-table");
  41. var scripts;
  42.  
  43. if (scriptList.length)
  44. scripts = scriptList.length; // User has script(s)
  45.  
  46. // If user has script(s) and Sonny's user script is installed
  47. else if (scriptTable) {
  48. var rows = scriptTable.querySelectorAll("tr"); // Count number of rows
  49. scripts = rows.length - 1; // Number of scripts = number of rows - 1
  50. }
  51.  
  52. if (scripts) { // If user has script(s)
  53. var username = document.querySelector("h2");
  54. var title = document.querySelector("body > section:not([id]) h3");
  55. if (title)
  56. // If using brown/blue style by Sonny's script
  57. if (getComputedStyle(title, null).getPropertyValue("display") == "none")
  58. addStyle(scripts); // overwrite style
  59. else // add number of script(s) in Scripts section
  60. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  61. else
  62. throwError(); // Sam ting wen wong
  63. }
  64. // else user didn't post any scripts