用户:QWERTY770/common.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- 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。
/* Wikiplus */
mw.loader.load('https://wikiplus-app.com/Main.js');
/* 部分链接新窗口打开 */
addTarget("mw-changeslist-title");
addTarget("mw-changeslist-diff");
addTarget("mw-changeslist-diff-cur");
addTarget("mw-changeslist-groupdiff");
addTarget("mw-changeslist-history");
addTarget("mw-userlink");
function addTarget (obj) {
var a_mct = document.getElementsByClassName(obj);
for (var i = a_mct.length - 1; i >= 0; i--) {
a_mct[i].setAttribute("target","_blank");
};
}
/* 添加 */
$('#p-personal ul').append('<li><a href="?action=purge">强制刷新</a><li>');
$('#p-personal ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/User:QWERTY_52_38/common.js">js</a></li>');
$('#p-personal ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/User:QWERTY_52_38/common.css">css</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/%E7%89%B9%E6%AE%8A:%E7%BC%96%E8%BE%91%E8%AE%A1%E6%95%B0">编辑数</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/%E6%A8%A1%E6%9D%BF:MCBBS%E6%A2%97%E6%96%87%E5%8C%96">MCBBS梗</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/%E6%A8%A1%E6%9D%BF:MCBBS%E8%AE%BA%E5%9D%9B%E4%BA%8B%E4%BB%B6">MCBBS事件</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/%E6%A8%A1%E6%9D%BF:MCBBS%E8%AE%BA%E5%9D%9B%E6%9C%BA%E5%88%B6">MCBBS机制</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/%E6%A8%A1%E6%9D%BF:MCBBS%E8%AE%BA%E5%9D%9B%E7%94%A8%E6%88%B7">MCBBS用户</a></li>');
$('#p-help ul').append('<li><a href="https://wiki.crash-logs.cn/wiki/MCBBS_Wiki:%E7%94%B3%E8%AF%B7%E8%81%8C%E4%BD%8D">申请职位</a></li>');
/* 删除 */
$('#pt-watchlist').remove();
/* 高亮标记巡查按钮 */
$('#mw-diff-ntitle4 span').css('background-color', '#7FFFD4');
$('#mw-diff-ntitle4 span').css('color', '#7FFFD4');
$('#mw-diff-ntitle4 span a').css('color', '#000');
/*test*/
dlg("Code block fix style appended.");
let LnBuilder = (ln) => {
let str = "";
for (let i = 1; i <= ln; i++) {
str += (i < 10 ? "0" + i.toString() : i.toString()) + ".\n";
}
return str;
};
// 为代码块添加行数显示与复制按钮
let fixCode = () => {
$(".pl pre:not([id]) code").each((i, v) => {
let ln = v.innerHTML.split("\n").length;
let lnC = LnBuilder(ln);
let counter = document.createElement("div");
counter.className = "line-counter";
counter.innerText = lnC;
let copy = document.createElement("em");
copy.className = "code-copy";
copy.addEventListener("click", (e) => {
let n = e.currentTarget.previousSibling.cloneNode(true);
copycode(n);
});
v.prepend(counter);
v.parentElement.append(copy);
});
$(".pl div.blockcode").each((i, v) => {
let ln = v.firstElementChild.firstElementChild.childElementCount;
let lnC = LnBuilder(ln);
let counter = document.createElement("div");
counter.className = "line-counter";
counter.innerText = lnC;
v.firstElementChild.prepend(counter);
});
copycode = (t)=>{
t = t.cloneNode(true);
t.firstElementChild.remove();
setCopy(t.innerText.replace(/\n\n/g, "\n"),"代码已复制到剪贴板");
};
}
$(fixCode);
$(this).on("DiscuzAjaxGetFinished DiscuzAjaxPostFinished",fixCode);