Greasy Fork is available in English.
自动替你在网页中所有的中文字和半形的英文、数字、符号之间插入空白,让文字变得美观好看。(pangu, 盤古之白)
当前为
// ==UserScript==
// @name 中英文之间加空白
// @name:zh-TW 中英文之間加空白
// @version 0.3.1
// @author CY Fung
// @namespace UserScript
// @license MIT
// @require https://cdn.jsdelivr.net/gh/cyfung1031/pangu.js@bee4aa06b31b63b9a6cc3972439fc523b4dbeeb8/dist/web/pangu.js
// @match http://*/*
// @match https://*/*
// @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
// @grant GM_setValue
// @run-at document-start
// @allFrames true
// @inject-into content
// @description 自动替你在网页中所有的中文字和半形的英文、数字、符号之间插入空白,让文字变得美观好看。(pangu, 盤古之白)
// @description:zh-TW 自動替你在網頁中所有的中文字和半形的英文、數字、符號之間插入空白,讓文字變得美觀好看。(pangu, 盤古之白)
// ==/UserScript==
((__CONTEXT__) => {
const { Promise, requestAnimationFrame, pangu } = __CONTEXT__;
class Mutex {
constructor() {
this.p = Promise.resolve()
}
lockWith(f) {
this.p = this.p.then(() => new Promise(f).catch(console.warn))
}
}
let busy = false;
const mutex = new Mutex();
function executor(f) {
mutex.lockWith(unlock => {
if (busy) {
unlock();
return;
}
busy = true;
Promise.resolve().then(() => {
f();
}).then(() => {
busy = false;
}).then(unlock);
});
}
let mzk = null;
document.addEventListener('DOMNodeInserted', function (e) {
if (!busy) {
if (mzk === null) mzk = e.target;
else mzk = true;
}
}, { capture: false, passive: true });
function f77() {
executor(() => {
if (mzk) {
let t = mzk;
mzk = null;
pangu.spacingPageTitle();
const node = t === true ? document.body : t;
if (node instanceof Node) {
pangu.spacingNode(node);
}
}
});
}
async function onReady() {
window.removeEventListener("DOMContentLoaded", onReady, false);
executor(() => {
pangu.spacingPageTitle();
pangu.spacingPageBody();
});
let bodyDOM = document.body;
let m33 = 0;
const config = {
childList: true,
subtree: true
};
const callback = async (mutations) => {
if (m33++ > 1e9) m33 = 9;
let tid = m33;
await new Promise(requestAnimationFrame);
if (tid !== m33) return;
f77();
await Promise.resolve();
let tmp = document.body;
if (tmp != bodyDOM) {
bodyDOM = tmp;
observer.takeRecords();
observer.disconnect();
observer.observe(bodyDOM, config);
callback();
}
};
const observer = new MutationObserver(callback);
observer.observe(bodyDOM, config);
callback();
}
Promise.resolve().then(() => {
if (document.readyState !== 'loading') {
onReady();
} else {
window.addEventListener("DOMContentLoaded", onReady, false);
}
});
})({ Promise, requestAnimationFrame, pangu });