binary2Text

Convert html source text to dom elements.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/410151/919981/binary2Text.js

  1. // ==UserScript==
  2. // @name binary2Text
  3. // @namespace https://greatest.deepsurf.us
  4. // @version 0.1.1
  5. // @description Convert html source text to dom elements.
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. /** 解决 Fetch 直接输出的中文乱码问题
  11. * https://segmentfault.com/q/1010000004338890
  12. * https://blog.shovonhasan.com/using-promises-with-filereader/
  13. * @param {Binary} https://developer.mozilla.org/docs/Web/API/FileReader/readAsText
  14. * @return {String}
  15. */
  16. const binary2Text = async (input) => {
  17. let reader = new FileReader();
  18. return new Promise((resolve, reject) => {
  19. reader.onerror = () => {
  20. reader.abort();
  21. reject(new DOMException('Problem parsing input.'));
  22. };
  23. reader.onload = () => {
  24. resolve(reader.result);
  25. };
  26. reader.readAsText(input);
  27. });
  28. };