Greasy Fork - Script Counter

Add number of scripts on user's profile page

Pada tanggal 18 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 2.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 showError() {
  28. var pAlert = document.querySelector("p.alert");
  29. if (pAlert) { // Display error notification
  30. pAlert.classList.add("important");
  31. pAlert.innerHTML = '<a href="/scripts/180">Script Counter</a>'
  32. + ' user script detects an error.'
  33. + ' Please <a href="/forum/post/discussion?'
  34. + 'Discussion/ScriptID=180">notify</a>'
  35. + ' the author.';
  36. }
  37. else // Show error in console
  38. throw new Error("Some thing went wrong.");
  39. }
  40.  
  41. var scripts;
  42.  
  43. var scriptList = document.querySelectorAll("#user-script-list > li");
  44. if (scriptList.length)
  45. scripts = scriptList.length; // User has script(s)
  46.  
  47. if (scripts) { // If user has script(s)
  48. var username = document.querySelector("h2");
  49. var title = document.querySelector("body > section:not([id]) h3");
  50. if (title) // add number of script(s) in Scripts section
  51. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  52. else
  53. showError(); // Sam ting wen wong
  54. }
  55. // else user didn't post any scripts