Greasy Fork - Script Counter

Add number of scripts on user's profile page

Verze ze dne 18. 03. 2014. Zobrazit nejnovější verzi.

  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==/* This program is free software. It comes without any warranty, to
  19. * the extent permitted by applicable law. You can redistribute it
  20. * and/or modify it under the terms of the Do What The Fuck You Want
  21. * To Public License, Version 2, as published by Sam Hocevar. See
  22. * http://www.wtfpl.net/ for more details. */
  23.  
  24.  
  25.  
  26. function showError() {
  27. var pAlert = document.querySelector("p.alert");
  28. if (pAlert) { // Display error notification
  29. pAlert.classList.add("important");
  30. pAlert.innerHTML = '<a href="/scripts/180">Script Counter</a>'
  31. + ' user script detects an error.'
  32. + ' Please <a href="/forum/post/discussion?'
  33. + 'Discussion/ScriptID=180">notify</a>'
  34. + ' the author.';
  35. }
  36. else // Show error in console
  37. throw new Error("Some thing went wrong.");
  38. }
  39.  
  40. var scripts;
  41.  
  42. var scriptList = document.querySelectorAll("#user-script-list > li");
  43. if (scriptList.length)
  44. scripts = scriptList.length; // User has script(s)
  45.  
  46. if (scripts) { // If user has script(s)
  47. var username = document.querySelector("h2");
  48. var title = document.querySelector("body > section:not([id]) h3");
  49. if (title) // add number of script(s) in Scripts section
  50. title.appendChild(document.createTextNode(" (" + scripts + ")"));
  51. else
  52. showError(); // Sam ting wen wong
  53. }
  54. // else user didn't post any scripts