Greasy Fork - Script Counter

Add number of scripts on user's profile page

Pada tanggal 09 Maret 2014. Lihat %(latest_version_link).

  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.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 scriptList = document.querySelectorAll("#user-script-list > li");
  32. var scriptTable = document.getElementById("script-table");
  33. var scripts;
  34.  
  35. if (scriptList.length)
  36. scripts = scriptList.length; // User has script(s)
  37.  
  38. // If user has script(s) and Sonny's user script is installed
  39. else if (scriptTable) {
  40. var rows = scriptTable.querySelectorAll("tr"); // Count number of rows
  41. scripts = rows.length - 1; // Number of scripts = number of rows - 1
  42. }
  43.  
  44. if (scripts) { // If user has script(s)
  45. var title = document.querySelector("body > section:not([id]) h3")
  46. if (title) // add number of script(s) in Scripts section
  47. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  48. }
  49. else
  50. throwError(); // Sam ting wen wong
  51. }
  52. // else user didn't post any scripts