Greasy Fork - Script Counter

Add number of scripts on user's profile page

As of 2014-03-10. 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 2.0
  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. var scripts;
  32.  
  33. var scriptList = document.querySelectorAll("#user-script-list > li");
  34. if (scriptList.length)
  35. scripts = scriptList.length; // User has script(s)
  36.  
  37. if (scripts) { // If user has script(s)
  38. var username = document.querySelector("h2");
  39. var title = document.querySelector("body > section:not([id]) h3");
  40. if (title) // add number of script(s) in Scripts section
  41. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  42. else
  43. throwError(); // Sam ting wen wong
  44. }
  45. // else user didn't post any scripts