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.0
  7. // @author CY Fung
  8. // @license MIT
  9. // @description To fix the wrong characters like arrow symbols
  10. // ==/UserScript==
  11.  
  12. for (const link of document.querySelectorAll('link[rel="stylesheet"][media="screen"][href]:not([href*=":"])')) {
  13. const href = link.getAttribute('href');
  14. fetch(href).then(r => r.text()).then(text => {
  15. const blob = new Blob([text], { type: 'text/css; charset=UTF-8' });
  16. const blobURL = URL.createObjectURL(blob);
  17. const newLink = link.cloneNode(false);
  18. newLink.setAttribute('href', blobURL);
  19. const onLoad = () => {
  20. link.remove();
  21. newLink.removeEventListener('load', onLoad, false);
  22. }
  23. newLink.addEventListener('load', onLoad, false);
  24. link.parentNode.insertBefore(newLink, link);
  25. }).catch(console.warn);
  26. }