Greasy Fork: fix wrong charset css

To fix the wrong characters like arrow symbols

当前为 2023-09-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Greasy Fork: fix wrong charset css
  3. // @namespace UserScripts
  4. // @match https://greasyfork.org/*
  5. // @grant none
  6. // @version 1.0.1
  7. // @author CY Fung
  8. // @license MIT
  9. // @description To fix the wrong characters like arrow symbols
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. for (const link of document.querySelectorAll('link[rel="stylesheet"][media="screen"][href]:not([href*=":"])')) {
  14. const href = link.getAttribute('href');
  15. fetch(href).then(r => r.text()).then(text => {
  16. const blob = new Blob([text], { type: 'text/css; charset=UTF-8' });
  17. const blobURL = URL.createObjectURL(blob);
  18. const newLink = link.cloneNode(false);
  19. newLink.setAttribute('href', blobURL);
  20. const onLoad = () => {
  21. link.remove();
  22. newLink.removeEventListener('load', onLoad, false);
  23. }
  24. newLink.addEventListener('load', onLoad, false);
  25. link.parentNode.insertBefore(newLink, link);
  26. }).catch(console.warn);
  27. }