Greasy Fork Total Installs

A userscript that shows the total installs for any page on Greasy Fork

  1. // ==UserScript==
  2. // @name Greasy Fork Total Installs
  3. // @version 0.1.1
  4. // @description A userscript that shows the total installs for any page on Greasy Fork
  5. // @license MIT
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @include https://greasyfork.org/*
  9. // @run-at document-idle
  10. // @grant none
  11. // @icon https://greasyfork.org/assets/blacklogo16-bc64b9f7afdc9be4cbfa58bdd5fc2e5c098ad4bca3ad513a27b15602083fd5bc.png
  12. // ==/UserScript==
  13. (() => {
  14. "use strict";
  15.  
  16. const wrapper = $("#browse-script-list, #user-script-list");
  17. if (wrapper) {
  18. const els = [...wrapper.querySelectorAll("dd.script-list-total-installs")];
  19. const nonDigits = /[^\d]/g;
  20. const getNum = txt => parseFloat(txt.replace(nonDigits, ""));
  21. const total = els.reduce((acc, el) => acc + getNum(el.textContent), 0);
  22. if (total) {
  23. const span = document.createElement("span");
  24. let target = $("#script-list-sort .list-option:nth-child(2)");
  25. span.textContent = ` (${(total).toLocaleString()})`;
  26. if ($("a", target)) {
  27. target = $("a", target);
  28. }
  29. target.appendChild(span);
  30. }
  31. }
  32.  
  33. function $(str, el) {
  34. return (el || document).querySelector(str);
  35. }
  36.  
  37. })();