Greasy Fork - Script Counter

Add number of scripts on user's profile page

Από την 19/03/2014. Δείτε την τελευταία έκδοση.

  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 3.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 GM_addStyle
  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 $(aSelector, aNode) {
  28. return (aNode || document).querySelector(aSelector);
  29. }
  30.  
  31. function $$(aSelector, aNode) {
  32. return (aNode || document).querySelectorAll(aSelector);
  33. }
  34.  
  35. function createElement(aTagName) {
  36. return document.createElement(aTagName);
  37. }
  38.  
  39. function createText(aText) {
  40. return document.createTextNode(aText);
  41. }
  42.  
  43. function createLink(aURL, aText, aName) {
  44. var link = createElement("a");
  45. aURL && (link.href = aURL);
  46. aText && (link.textContent = aText);
  47. aName && (link.name = aName);
  48. return link;
  49. }
  50.  
  51. function showError() {
  52. var pAlert = $("p.alert");
  53. if (pAlert) { // Display error notification
  54. pAlert.classList.add("important");
  55. pAlert.innerHTML = '<a href="/scripts/180">Script Counter</a>'
  56. + ' user script detects an error.'
  57. + ' Please <a href="/forum/post/discussion?'
  58. + 'Discussion/ScriptID=180">notify</a>'
  59. + ' the author.';
  60. }
  61. else // Log in console
  62. console.log("Some thing went wrong.");
  63. }
  64.  
  65. // Opera UserJS doesn't recognize GM_addStyle so we re-write the function
  66. if (typeof GM_addStyle !== "function") {
  67. function GM_addStyle(aCSS) {
  68. var style = createElement("style");
  69. style.type = "text/css";
  70. style.textContent = aCSS;
  71. $("head").appendChild(style);
  72. }
  73. }
  74.  
  75. GM_addStyle(".discussion-more{list-style-image:url(data:image/png;base64,\
  76. iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A\
  77. /wD/oL2nkwAAAsFJREFUOMulk0FoXFUUhr9377lvplPHkjSTNEXohFYwhibgRjsqrS0mG2EQXdil\
  78. 6xTc6KY4XUwg6FYCbkQRREFwEYqFGFpN1VQQkZimUVEyXbXJmybqZPJm3rv3XTeT2o1uPMvDOf85\
  79. /Pxf4L3nwZq5dHESmAIqwGivvQ4sAwu1+uwXD84H+wIzly6WgQtDR46eHxsfHywfG5GBUgmAZhTR\
  80. uL1h135a2dq8e+cTYK5Wn23cF+gtz5w+N1l96lSlqLuG3R8cO58laJXR91JI4QmDDVO+u/Fta+nq\
  81. 4jxQq9VnG9L75MLpc5PVZytnipsfpTTf28Uoh9EOrTL+WGvzp/IcevUgz7x8pghUl64ubgKva50l\
  82. k0NHht98ofriwL2PM+69H5MXR04sRltEO5AOXrp0bu4ShFB+/kTut19/KV+5PH9TAVNj4xODKjFs\
  83. f9AhJ5ZQpxixBNLBmRbOtMlMjDcpf326haSasfGJQWBKgEr52IjEPzpELDnlEG1x2R7pdgvXsrAt\
  84. KA6gCNF9Qvf7hPLxEQEqAowOlEo03+lixKEyS3xrh260DanCcAjlH8KicSh8M8DNtBn+vAQwum8i\
  85. SmcEmwnxzzukdgcIML4fz0FiBIuQeoUnQGPu50AB680oovicwa3GOBvjsQgPk1GggyH2IXs+R0ye\
  86. PfL0TxeIoghgXQHLjcaGPfBkSEaXjA6KPNoXsRgSb+gQEhPS9jn2fJ6+s0KjsWGBZQUsrK2ubLmC\
  87. pb9+GI9FkcOhSdGkCCmGjg9JjHD8LUVWSLi1urIFLOhrS1//fuXy/FEt5uRjr4zlVKjpfuVw5HvX\
  88. DV0fkogw+jaceC1g+cb11trqyoe1+uy7+ybOXb+2OARUT73xdLF/+hHaX3a5M5cgCI9OC4fPBvhC\
  89. wjf/RHnuX2AaPv/4yYnBcnlESj2Yoiji9n/B9H9w/hupo0mgKfUuDwAAAABJRU5ErkJggg==)};");
  90. // YAY! PINK!
  91.  
  92. var scripts;
  93.  
  94. var scriptEntries = $$("#user-script-list > li");
  95. if (scriptEntries.length)
  96. scripts = scriptEntries.length; // User has script(s)
  97.  
  98. if (scripts) { // If user has script(s)
  99. var userID = location.pathname.match(/\d+/).toString();
  100. var userName = $("h2").textContent;
  101. var userForumURL = "/forum/?Discussion/ScriptAuthorID=" + userID;
  102.  
  103. // Add number of script(s) in Scripts section
  104. var title = $("body > section:not([id]) h3");
  105. if (title)
  106. title.appendChild(createText(" (" + scripts + ")"));
  107. else
  108. showError(); // Sam ting wen wong
  109.  
  110. // Add "discussions on user's scripts" link
  111. var userForum = $("#user-discussions-on-scripts-written ul");
  112. if (userForum) {
  113. var list = userForum.appendChild(createElement("li"));
  114. list.className = "discussion-more";
  115. list.appendChild(createLink(userForumURL, "More discussions\u2026"));
  116. }
  117. else {
  118. var scriptList = $("#user-script-list") || $("#table-container");
  119. if (scriptList) {
  120. $("header", scriptList.parentNode).appendChild(createElement("p")).
  121. appendChild(createLink(userForumURL, "Discussions on " + userName +
  122. "'s scripts"));
  123. }
  124. }
  125. } // else user doesn't have any scripts or the scripts are unlisted/deleted