Greasyfork/Sleazyfork Script Icon Display

Displays the favicon of scripts.

当前为 2024-11-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Greasyfork/Sleazyfork Script Icon Display
  3. // @description Displays the favicon of scripts.
  4. // @icon https://greasyfork.org/vite/assets/blacklogo96-CxYTSM_T.png
  5. // @version 1.0
  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;margin:0';
  27. const iconImg = document.createElement('img');
  28. iconImg.src = `https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://${domain}&size=64`;
  29. iconImg.style.cssText = 'width:32px;height:32px;margin-right:10px;flex-shrink:0';
  30. h2Element.replaceChildren(iconImg, document.createElement('span').appendChild(document.createTextNode(h2Element.textContent)).parentNode);
  31. return true;
  32. }
  33.  
  34. function init(attempts = 10) {
  35. if (addIconToHeader() || attempts < 1) return;
  36. setTimeout(() => init(attempts - 1), 50);
  37. }
  38.  
  39. document.readyState === 'loading'
  40. ? document.addEventListener('DOMContentLoaded', () => init())
  41. : init();
  42.  
  43. new MutationObserver(() => init(5)).observe(document.documentElement, {
  44. childList: true,
  45. subtree: true
  46. });
  47. })();