Greasyfork/Sleazyfork Script Icon Display

Displays the clickable favicon of scripts.

  1. // ==UserScript==
  2. // @name Greasyfork/Sleazyfork Script Icon Display
  3. // @description Displays the clickable favicon of scripts.
  4. // @icon https://greasyfork.org/vite/assets/blacklogo96-CxYTSM_T.png
  5. // @version 1.1
  6. // @author afkarxyz
  7. // @namespace https://github.com/afkarxyz/misc-scripts/
  8. // @supportURL https://github.com/afkarxyz/misc-scripts/issues
  9. // @license MIT
  10. // @match https://greasyfork.org/*/scripts/*
  11. // @match https://sleazyfork.org/*/scripts/*
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. function addIconToHeader() {
  19. const firstListItem = document.querySelector('.script-show-applies-to .block-list li:first-child');
  20. const h2Element = document.querySelector('header h2');
  21. if (!firstListItem || !h2Element || h2Element.querySelector('img')) return false;
  22.  
  23. const domain = (firstListItem.querySelector('a')?.textContent || firstListItem.textContent).trim();
  24. if (!domain) return false;
  25.  
  26. h2Element.style.cssText = 'display:flex;align-items:center;gap:10px;margin:0;min-height:32px;';
  27. const iconLink = document.createElement('a');
  28. iconLink.href = `http://${domain}`;
  29. iconLink.target = '_blank';
  30. iconLink.style.cssText = 'text-decoration:none;display:flex;align-items:center;';
  31. const iconImg = document.createElement('img');
  32. iconImg.src = `https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://${domain}&size=64`;
  33. iconImg.style.cssText = 'width:32px;height:32px;flex-shrink:0;cursor:pointer;display:block;';
  34. iconImg.title = `Visit ${domain}`;
  35. const textSpan = document.createElement('span');
  36. textSpan.style.cssText = 'display:flex;align-items:center;flex:1;';
  37. textSpan.textContent = h2Element.textContent;
  38. iconLink.appendChild(iconImg);
  39. h2Element.replaceChildren(iconLink, textSpan);
  40. return true;
  41. }
  42.  
  43. function init(attempts = 10) {
  44. if (addIconToHeader() || attempts < 1) return;
  45. setTimeout(() => init(attempts - 1), 50);
  46. }
  47.  
  48. document.readyState === 'loading'
  49. ? document.addEventListener('DOMContentLoaded', () => init())
  50. : init();
  51.  
  52. new MutationObserver(() => init(5)).observe(document.documentElement, {
  53. childList: true,
  54. subtree: true
  55. });
  56. })();