Greasy Fork is available in English.

Greasy Fork - Script Counter

Add number of scripts on user's profile page

Version au 19/03/2014. Voir la dernière version.

  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.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==/* 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 $(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. var scripts;
  65.  
  66. var scriptEntries = $$("#user-script-list > li");
  67. if (scriptEntries.length)
  68. scripts = scriptEntries.length; // User has script(s)
  69.  
  70. if (scripts) { // If user has script(s)
  71. var userID = location.pathname.match(/\d+/).toString();
  72. var userName = $("h2").textContent;
  73. var userForumURL = "/forum/?Discussion/ScriptAuthorID=" + userID;
  74.  
  75. // Add number of script(s) in Scripts section
  76. var title = $("body > section:not([id]) h3");
  77. if (title)
  78. title.appendChild(createText(" (" + scripts + ")"));
  79. else
  80. showError(); // Sam ting wen wong
  81.  
  82. // Add "discussions on user's scripts" link
  83. var userForum = $("#user-discussions-on-scripts-written ul");
  84. if (userForum) {
  85. userForum.appendChild(createElement("li"))
  86. .appendChild(createLink(userForumURL, "More discussions\u2026"));
  87. }
  88. else {
  89. var scriptList = $("#user-script-list") || $("#table-container");
  90. if (scriptList) {
  91. $("header", scriptList.parentNode).appendChild(createElement("p")).
  92. appendChild(createLink(userForumURL, "Discussions on " + userName +
  93. "'s scripts"));
  94. }
  95. }
  96. } // else user doesn't have any scripts or the scripts are unlisted/deleted