Greasy Fork is available in English.

GreasyFork Total Scripts

Shows a user's total scripts count on GreasyFork.

  1. // ==UserScript==
  2. // @name GreasyFork Total Scripts
  3. // @namespace -
  4. // @version 3.1.6
  5. // @description Shows a user's total scripts count on GreasyFork.
  6. // @author NotYou
  7. // @match *://greatest.deepsurf.us/*/users/*
  8. // @match *://sleazyfork.org/*/users/*
  9. // @match *://greatest.deepsurf.us/*/scripts*
  10. // @match *://sleazyfork.org/*/scripts*
  11. // @license GPL-3.0-or-later
  12. // @run-at document-end
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. ~function() {
  17. class Utils {
  18. static getColor(amount) {
  19. if (amount >= 100) {
  20. return 'rgb(185, 16, 16)'
  21. } if (amount >= 50) {
  22. return 'rgb(185, 87, 16)'
  23. } if (amount >= 25) {
  24. return 'rgb(185, 159, 16)'
  25. } if (amount >= 10) {
  26. return 'rgb(21, 185, 16)'
  27. } if (amount >= 5) {
  28. return 'rgb(16, 185, 153)'
  29. } if (amount > 1) {
  30. return 'rgb(16, 42, 185)'
  31. } if (amount === 1) {
  32. return 'rgb(125, 125, 125)'
  33. }
  34. }
  35.  
  36. static isSearchPage() {
  37. return Boolean(document.querySelector('#browse-script-list'))
  38. }
  39.  
  40. static getLocale($languageSelectorLocale) {
  41. return $languageSelectorLocale ? $languageSelectorLocale.value || 'en-US' : 'en-US'
  42. }
  43. }
  44.  
  45. class Counter {
  46. static getAmount(selector) {
  47. return document.querySelectorAll(selector).length
  48. }
  49.  
  50. static getScripts() {
  51. return this.getAmount('[data-script-language="js"]:not([data-script-type="library"])')
  52. }
  53.  
  54. static getStyles() {
  55. return this.getAmount('[data-script-language="css"]')
  56. }
  57.  
  58. static getLibraries() {
  59. return this.getAmount('[data-script-type="library"]')
  60. }
  61. }
  62.  
  63. class Stat {
  64. static createItem(data, text, color) {
  65. const node = document.createElement('span')
  66. node.style.fontSize = '15px'
  67. node.style.borderRadius = '3px'
  68. node.style.backgroundColor = 'rgb(45, 45, 45)'
  69. node.style.color = 'rgb(255, 255, 255)'
  70. node.style.margin = '0 4px'
  71. node.style.padding = '0 4px'
  72. node.style.display = 'inline-flex'
  73. node.style.alignItems = 'center'
  74. node.style.gap = '4px'
  75. node.style.boxShadow = `0 0 0 2px ${color}`
  76. node.textContent = data + ' ' + text
  77.  
  78. const circle = document.createElement('span')
  79. circle.style.width = '8px'
  80. circle.style.height = '8px'
  81. circle.style.borderRadius = '50%'
  82. circle.style.background = color
  83.  
  84. node.prepend(circle)
  85.  
  86. return node
  87. }
  88. }
  89.  
  90. class Main {
  91. static init() {
  92. const scripts = Counter.getScripts()
  93. const styles = Counter.getStyles()
  94. const libraries = Counter.getLibraries()
  95. const isSearchPage = Utils.isSearchPage()
  96. const $languageSelectorLocale = document.querySelector('#language-selector-locale')
  97. const userLocale = Utils.getLocale($languageSelectorLocale)
  98. const $scripts = Stat.createItem(scripts.toLocaleString(userLocale), scripts > 1 ? 'Scripts' : 'Script', Utils.getColor(scripts))
  99. const $styles = Stat.createItem(styles.toLocaleString(userLocale), styles > 1 ? 'Styles' : 'Style', Utils.getColor(styles))
  100. const $libraries = Stat.createItem(libraries.toLocaleString(userLocale), libraries > 1 ? 'Libraries' : 'Library', Utils.getColor(libraries))
  101.  
  102. if (isSearchPage) {
  103. const $mainContentParagraph = document.querySelector('.sidebarred-main-content > p')
  104.  
  105. if (scripts) {
  106. $mainContentParagraph.appendChild($scripts)
  107. } if (styles) {
  108. $mainContentParagraph.appendChild($styles)
  109. } if (libraries) {
  110. $mainContentParagraph.appendChild($libraries)
  111. }
  112. } else {
  113. const $header = document.querySelector('div.sidebarred-main-content h3:first-child')
  114.  
  115. if (scripts) {
  116. $header.appendChild($scripts)
  117. } if (styles) {
  118. $header.appendChild($styles)
  119. } if (libraries) {
  120. $header.appendChild($libraries)
  121. }
  122. }
  123. }
  124. }
  125.  
  126. Main.init()
  127. }()