Greasy Fork: fix wrong charset css

To fix the wrong characters like arrow symbols

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