Greasy Fork - Script Counter

Add number of scripts on user's profile page

As of 2014-03-09. See the latest version.

  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.0pre
  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. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/script-counter/CHANGELOG.txt
  12. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
  13. // @run-at document-end
  14. // @include https://greatest.deepsurf.us/users/*
  15. // @grant none
  16. // ==/UserScript==
  17. /* This program is free software. It comes without any warranty, to
  18. * the extent permitted by applicable law. You can redistribute it
  19. * and/or modify it under the terms of the Do What The Fuck You Want
  20. * To Public License, Version 2, as published by Sam Hocevar. See
  21. * http://www.wtfpl.net/ for more details. */
  22.  
  23.  
  24.  
  25. function throwError() {
  26. throw new Error("Some thing went wrong.");
  27. }
  28.  
  29. var scriptList = document.querySelectorAll("#user-script-list > li");
  30. var scriptTable = document.getElementById("script-table");
  31. var scripts;
  32.  
  33. if (scriptList.length)
  34. scripts = scriptList.length; // User has script(s)
  35.  
  36. // If user has script(s) and Sonny's user script is installed
  37. else if (scriptTable) {
  38. var rows = scriptTable.querySelectorAll("tr"); // Count number of rows
  39. scripts = rows.length - 1; // Number of scripts = number of rows - 1
  40. }
  41.  
  42. if (scripts) { // If user has script(s)
  43. var title = document.querySelector("body > section:not([id]) h3")
  44. if (title) // add number of script(s) in Scripts section
  45. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  46. }
  47. else
  48. throwError(); // Sam ting wen wong
  49. }
  50. // else user didn't post any scripts