
我糊了个 userscript 用来把盘古之白之类的事交给 han.css 做,安装“greasemonkey”就能使用:
// ==UserScript== // @name Han.css on V2EX // @namespace https://artoria2e5.moe // @version 0.1 // @description what description? // @author You // @match https://v2ex.com/* // @match * // @icon https://www.google.com/s2/favicons?domain=https://v2ex.com/ // @grant unsafeWindow // ==/UserScript== $("head").append( '<link rel="stylesheet" media="all" href="//cdnjs.cloudflare.com/ajax/libs/Han/3.3.0/han.min.css">' ) await $.getScript("//cdnjs.cloudflare.com/ajax/libs/Han/3.3.0/han.min.js") // Undo the terrible space insertion // We know it incorrectly includes punctuations. I *guess* this is what they are using... (intentionally bad and BMP-only) const CJK_BMP = "[\\u2E80-\\u303F" + "\\u31c0-\\u33ff" + "\\u4e00-\\u9fff" + "\\uf900-\\ufaff" + "\\ufe30-\\ufe4f" + "\\uff00-\\uffef]" const ASCII = "[\x21-\x7e]" const NEIGHBOR_REGEX = new RegExp( `(?<c1>${CJK_BMP}) (?<a1>${ASCII})( (?<c1x>${CJK_BMP}))?|(?<a2>${ASCII}) (?<c2>${CJK_BMP})( (?<a2x>{ASCII}))?`, "g" ) function iterate_node(node, operation, predicate) { if (node.nodeType === Node.TEXT_NODE) { node.data = operation(node.data) } else if (node.nodeType === Node.ELEMENT_NODE && predicate(node)) { node.childNodes.forEach((n) => iterate_node(n, operation, predicate)) } } document.querySelectorAll(".reply_content, .topic_content").forEach((e) => { iterate_node( e, (s) => s.replace(NEIGHBOR_REGEX, "$<c1>$<a1>$<c1x>$<a2>$<c2>$<a2x>"), (e) => e.name != "pre" ) Han(e).render() }) (我本来是用来处理 V2EX 在标点周围错误插入的盘古之白的。不过看了一下最近的贴似乎是修了,老帖还是坏的。)我懒得把这个脚本放进任何有版本控制的地方。
1 orzfly 2021-05-14 18:24:54 +08:00 $("head").append => $("head").prepend 不然 desktop.css 里覆盖的例如 h1 的 font-size / magin 就无效了,显得比较怪 |