Greasy Fork is available in English.

binary2Text

Convert html source text to dom elements.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.org/scripts/410151/919981/binary2Text.js

// ==UserScript==
// @name          binary2Text
// @namespace     https://greasyfork.org
// @version       0.1.1
// @description   Convert html source text to dom elements.
// @match         *://*/*
// @grant         none
// ==/UserScript==

/** 解决 Fetch 直接输出的中文乱码问题
 * https://segmentfault.com/q/1010000004338890
 * https://blog.shovonhasan.com/using-promises-with-filereader/
 * @param {Binary} https://developer.mozilla.org/docs/Web/API/FileReader/readAsText
 * @return {String}
 */
const binary2Text = async (input) => {
  let reader = new FileReader();
  return new Promise((resolve, reject) => {
    reader.onerror = () => {
      reader.abort();
      reject(new DOMException('Problem parsing input.'));
    };
    reader.onload = () => {
      resolve(reader.result);
    };
    reader.readAsText(input);
  });
};