Greasy Fork is available in English.

Greasy Fork - Script Counter

Add number of scripts on user's profile page

  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The Fuck You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://www.wtfpl.net/ for more details. */
  6.  
  7. // ==UserScript==
  8. // @id greasy-fork-script-counter@loucypher
  9. // @name Greasy Fork - Script Counter
  10. // @namespace https://github.com/LouCypher/userscripts
  11. // @description Add number of scripts on user's profile page
  12. // @version 3.1
  13. // @author LouCypher
  14. // @license WTFPL
  15. // @screenshot https://raw.github.com/LouCypher/userscripts/master/greasyfork/script-counter/screenshot.png
  16. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Greasy+Fork+-+Script+Counter
  17. // @homepageURL https://greatest.deepsurf.us/scripts/180
  18. // @supportURL https://greatest.deepsurf.us/scripts/180/feedback
  19. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/greasyfork/script-counter/CHANGELOG.txt
  20. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
  21. // @run-at document-end
  22. // @include https://greatest.deepsurf.us/users/*
  23. // @grant GM_addStyle
  24. // ==/UserScript==
  25.  
  26. function $(aSelector, aNode) {
  27. return (aNode || document).querySelector(aSelector);
  28. }
  29.  
  30. function $$(aSelector, aNode) {
  31. return (aNode || document).querySelectorAll(aSelector);
  32. }
  33.  
  34. function createElement(aTagName) {
  35. return document.createElement(aTagName);
  36. }
  37.  
  38. function createText(aText) {
  39. return document.createTextNode(aText);
  40. }
  41.  
  42. function createLink(aURL, aText, aName) {
  43. var link = createElement("a");
  44. aURL && (link.href = aURL);
  45. aText && (link.textContent = aText);
  46. aName && (link.name = aName);
  47. return link;
  48. }
  49.  
  50. function showError() {
  51. var pAlert = $("p.alert");
  52. if (pAlert) { // Display error notification
  53. pAlert.classList.add("important");
  54. pAlert.innerHTML = '<a href="/scripts/180">Script Counter</a>'
  55. + ' user script detects an error.'
  56. + ' Please <a href="/forum/post/discussion?'
  57. + 'Discussion/ScriptID=180">notify</a>'
  58. + ' the author.';
  59. }
  60. else // Log in console
  61. console.log("Some thing went wrong.");
  62. }
  63.  
  64. // Opera UserJS doesn't recognize GM_addStyle so we re-write the function
  65. if (typeof GM_addStyle !== "function") {
  66. function GM_addStyle(aCSS) {
  67. var style = createElement("style");
  68. style.type = "text/css";
  69. style.textContent = aCSS;
  70. $("head").appendChild(style);
  71. }
  72. }
  73.  
  74. GM_addStyle(".discussion-more{list-style-image:url(data:image/png;base64,\
  75. iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\
  76. /wD/oL2nkwAAAsFJREFUOMulk0FoXFUUhr9377lvplPHkjSTNEXohFYwhibgRjsqrS0mG2EQXdil\
  77. 6xTc6KY4XUwg6FYCbkQRREFwEYqFGFpN1VQQkZimUVEyXbXJmybqZPJm3rv3XTeT2o1uPMvDOf85\
  78. /Pxf4L3nwZq5dHESmAIqwGivvQ4sAwu1+uwXD84H+wIzly6WgQtDR46eHxsfHywfG5GBUgmAZhTR\
  79. uL1h135a2dq8e+cTYK5Wn23cF+gtz5w+N1l96lSlqLuG3R8cO58laJXR91JI4QmDDVO+u/Fta+nq\
  80. 4jxQq9VnG9L75MLpc5PVZytnipsfpTTf28Uoh9EOrTL+WGvzp/IcevUgz7x8pghUl64ubgKva50l\
  81. k0NHht98ofriwL2PM+69H5MXR04sRltEO5AOXrp0bu4ShFB+/kTut19/KV+5PH9TAVNj4xODKjFs\
  82. f9AhJ5ZQpxixBNLBmRbOtMlMjDcpf326haSasfGJQWBKgEr52IjEPzpELDnlEG1x2R7pdgvXsrAt\
  83. KA6gCNF9Qvf7hPLxEQEqAowOlEo03+lixKEyS3xrh260DanCcAjlH8KicSh8M8DNtBn+vAQwum8i\
  84. SmcEmwnxzzukdgcIML4fz0FiBIuQeoUnQGPu50AB680oovicwa3GOBvjsQgPk1GggyH2IXs+R0ye\
  85. PfL0TxeIoghgXQHLjcaGPfBkSEaXjA6KPNoXsRgSb+gQEhPS9jn2fJ6+s0KjsWGBZQUsrK2ubLmC\
  86. pb9+GI9FkcOhSdGkCCmGjg9JjHD8LUVWSLi1urIFLOhrS1//fuXy/FEt5uRjr4zlVKjpfuVw5HvX\
  87. DV0fkogw+jaceC1g+cb11trqyoe1+uy7+ybOXb+2OARUT73xdLF/+hHaX3a5M5cgCI9OC4fPBvhC\
  88. wjf/RHnuX2AaPv/4yYnBcnlESj2Yoiji9n/B9H9w/hupo0mgKfUuDwAAAABJRU5ErkJggg==)};");
  89. // YAY! PINK!
  90.  
  91. var scripts;
  92.  
  93. var scriptEntries = $$("#user-script-list > li");
  94. if (scriptEntries.length)
  95. scripts = scriptEntries.length; // User has script(s)
  96.  
  97. if (scripts) { // If user has script(s)
  98. var userID = location.pathname.match(/\d+/).toString();
  99. var userName = $("h2").textContent;
  100. var userForumURL = "/forum/?Discussion/ScriptAuthorID=" + userID;
  101.  
  102. // Add number of script(s) in Scripts section
  103. var title = $("body > section:not([id]) h3");
  104. if (title)
  105. title.appendChild(createText(" (" + scripts + ")"));
  106. else
  107. showError(); // Sam ting wen wong
  108.  
  109. // Add "discussions on user's scripts" link
  110. var userForum = $("#user-discussions-on-scripts-written ul");
  111. if (userForum) {
  112. var list = userForum.appendChild(createElement("li"));
  113. list.className = "discussion-more";
  114. list.appendChild(createLink(userForumURL, "More discussions\u2026"));
  115. }
  116. else {
  117. var scriptList = $("#user-script-list") || $("#table-container");
  118. if (scriptList) {
  119. $("header", scriptList.parentNode).appendChild(createElement("p")).
  120. appendChild(createLink(userForumURL, "Discussions on " + userName +
  121. "'s scripts"));
  122. }
  123. }
  124. } // else user doesn't have any scripts or the scripts are unlisted/deleted