更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 此处的JavaScript将加载于所有用户每一个页面。 */
/**
* 自动转换链接
* @author [[User:UnownHearn]]
* @version 1.4 (2019/03/18)
*/
(function () { /* 自动链接 */
var filter = (function (node) {
if (node.nodeType == 3 /* TEXT_NODE */) {
return NodeFilter.FILTER_ACCEPT;
} else if (node.nodeType != 1 /* ELEMENT_NODE */
|| node.tagName.toLowerCase() == "a"
|| node.classList.contains("no-autolink")) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_SKIP;
})
var rules = [{
// id: ["sm", "nm"],
regex: /(sm|nm|im|av|ac)\d+/g,
link: function (text) {
switch (text.slice(0, 2)) {
case "sm": case "nm":
return "https://www.nicovideo.jp/watch/" + text;
case "im":
return "https://seiga.nicovideo.jp/seiga/" + text;
case "av":
return "https://www.bilibili.com/video/" + text;
case "ac":
return "http://www.acfun.cn/v/" + text;
}
}
}, {
// id: ["mylist", "user"],
regex: /(mylist|user)\/\d+/g,
link: "https://www.nicovideo.jp/{}"
}];
var nodes = [];
var as = document.getElementsByClassName("WikiaArticle");
Array.prototype.forEach.call(as, function (a) {
var walker = document.createTreeWalker(a, NodeFilter.SHOW_ALL, { acceptNode: filter });
while (walker.nextNode()) {
nodes.push(walker.currentNode);
}
})
for (var nodeIndex in nodes) {
var node = nodes[nodeIndex];
var html = node.textContent;
for (var ruleIndex in rules) {
var rule = rules[ruleIndex];
html = html.replace(rule.regex, function (old) {
var link;
if (typeof rule.link === "function") {
link = rule.link(old);
} else {
link = rule.link.replace("{}", old);
}
return "<a class=\"autolink\" href=\"" + link + "\">" +
old + "</a>";
});
}
if (html != node.textContent) {
var parentNode = node.parentNode;
var dummy = document.createElement("span");
dummy.innerHTML = html;
parentNode.replaceChild(dummy, node);
}
}
})();