Greasy Fork is available in English.
auto link for douban
当前为
// ==UserScript==
// @name douban auto-link
// @namespace http://tampermonkey.net/
// @version 0.2.1
// @description auto link for douban
// @author yetone
// @match https://*.douban.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
document.querySelectorAll('p').forEach(p => {
let nodes = [];
let need = false;
p.childNodes.forEach(x => {
if (x.nodeType !== 3) {
nodes.push(x);
return;
}
let text = x.textContent;
let lastIdx = 0;
text.replace(/(《.+?》|「.+?」|『.+?』)/g, (_, c, idx, t) => {
need = true;
nodes.push(new Text(t.substring(lastIdx, idx + 1)));
lastIdx = idx + c.length - 1;
let a = document.createElement('a');
let cc = t.substring(idx + 1, idx + c.length - 1);
a.href = `https://www.douban.com/search?q=${encodeURIComponent(cc)}`;
a.target = '_blank';
a.innerText = cc;
nodes.push(a);
});
nodes.push(new Text(text.substring(lastIdx)));
});
if (nodes.length > 0 && need) {
p.childNodes.forEach(x => {
p.removeChild(x);
});
nodes.forEach(x => {
p.appendChild(x);
});
}
});
})();