Greasy Fork is available in English.
MCBBS行为拓展/样式修复
当前为
// ==UserScript==
// @name MCBBS Extender
// @namespace https://i.zapic.cc
// @version beta-0.0.7
// @description MCBBS行为拓展/样式修复
// @author Zapic
// @match https://www.mcbbs.net/*
// @run-at document-body
// ==/UserScript==
(function () {
var conf = {
//美化代码块样式
"fixCodeBlock": true,
//修复代码块"复制代码"换行消失的问题
"fixCodeCopy": true,
//修复表格排版内含有多媒体导致元素戳破表格的问题
"fixTableLayout": true,
//后台轮询新消息
"QueryMessage": true,
//后台轮询消息间隔,单位为秒
"QueryMessageInterval": 60,
//板块页点击"下一页"按钮是否记住当前页码
"rememberPage": true,
//美化右侧回到顶部按钮
"animateGoToTopButton": true,
//固定顶栏在顶部
"pinnedTopBar": true,
//顶栏弹出菜单美化&对齐
"fixTopBarPopMenu": true,
//主题悬浮预览
"hoverPreviewTheme": true
};
var jq = jQuery;
if (conf.fixCodeBlock) {
jq("head").append("<style id=\"fixCodeBlock\">.hljs > ::-webkit-scrollbar {background: #00000000;height: 7px}.hljs > ::-webkit-scrollbar-thumb:hover{background:#0000005c;}.hljs > ::-webkit-scrollbar-thumb{background:#0000002c;border-radius: 3px}.pl .blockcode{overflow-x:auto;padding: 10px 0 5px 10px;background-attachment: local}.blockcode ol{overflow-x: unset!important;}.hljs{display:unset;}.pl .blockcode ol{margin: 0 0 0px -10px!important;padding: 0 0 0px 20px !important;}.pl .blockcode ol li:hover {background-color: #00000010;color: #666;}.pl .blockcode ol li {margin-left: 23px;min-width: fit-content;padding-right: 10px;}.pl .blockcode em {display: block;margin-top: 5px;}</style>");
}
if (conf.fixTableLayout) {
jq("head").append("<style id=\"fixTableLayout\">.pl table.t_table{table-layout: fixed;}.pl table.t_table[style*=\"px\"]{table-layout: auto;}</style>");
}
if (conf.fixCodeCopy) {
copycode = function (obj) {
if (!obj)
return false;
var count = obj.children[0].children.length;
var code = "";
for (i = 0; i < count; i++) {
code += obj.children[0].children[i].innerText + "\r\n";
}
setCopy(code, '代码已复制到剪贴板');
};
}
if (conf.QueryMessage) {
setInterval(function () {
jq.get("https://www.mcbbs.net/", function (d) {
var dom = jq(d);
var el = dom.filter("script[src*=html5notification]");
var ut = dom.find(".user_tools");
var pum = dom.filter("#myprompt_menu");
jq(".user_tools").html(ut.html());
jq("#myprompt_menu").html(pum.html());
jq("title").text(NOTICECURTITLE);
if (el.length !== 0) {
if (!window.Html5notification) {
jq.get(el[0].src, function (s) {
eval(s);
});
}
var s = el.nextUntil("div").last().text();
eval(s);
noticeTitle();
}
});
}, conf.QueryMessageInterval * 1000);
}
if (conf.rememberPage) {
jq(document).ready(function () {
if ($('autopbn')) {
var npbtn = $('autopbn')
var dc = npbtn.onclick;
npbtn.onclick = function () {
var nextpageurl = this.getAttribute('rel').valueOf();
var curpage = parseInt(this.getAttribute('curpage').valueOf());
this.setAttribute('curpage', curpage + 1);
nextpageurl = nextpageurl.replace(/&page=\d+/, '&page=' + (curpage + 1));
history.replaceState(null, null, nextpageurl);
dc();
};
}
});
}
if (conf.animateGoToTopButton) {
jq("head").append("<style id=\"GoToTopButton\">#scrolltop{opacity:0;transform:scale(0.7);pointer-events:none;bottom: 270px;transform-origin: 0 50%;visibility:visible;margin-left:-5px;}</style>");
showTopLink = function () {
var ft = $('ft');
if (ft) {
var scrolltop = $('scrolltop');
var viewPortHeight = parseInt(document.documentElement.clientHeight);
var scrollHeight = parseInt(document.body.getBoundingClientRect().top);
var basew = parseInt(ft.clientWidth);
var sw = scrolltop.clientWidth;
if (scrolltop.style.transitionDuration == "") scrolltop.style.transitionDuration = ".1s";
if (basew < 1000) {
var left = parseInt(fetchOffset(ft)['left']);
left = left < sw ? left * 2 - sw : left;
scrolltop.style.left = (basew + left + 44) + 'px';
} else {
scrolltop.style.left = 'auto';
scrolltop.style.right = 0;
}
if (BROWSER.ie && BROWSER.ie < 7) {
scrolltop.style.top = viewPortHeight - scrollHeight - 150 + 'px';
}
if (scrollHeight < -100) {
scrolltop.style.opacity = 1;
scrolltop.style.transform = "scale(1)";
scrolltop.style.pointerEvents = "unset";
scrolltop.style.marginLeft = "unset";
} else {
scrolltop.style.opacity = "";
scrolltop.style.transform = "";
scrolltop.style.pointerEvents = "";
scrolltop.style.marginLeft = "";
}
}
}
showTopLink();
}
if (conf.pinnedTopBar) {
jq("head").append("<style id=\"pinnedTopBar\">#toptb{position: fixed;width: 100%;z-index:790;top:0;box-shadow: #0000004f 3px 3px 5px 1px;}.mc_map_wp{padding-top: 45px;}#scbar_type_menu{top:38px!important}#user_info_menu,#myprompt_menu,#usertools_menu,#sslct_menu {position:fixed!important;top:47px!important}</style>");
}
if (conf.fixTopBarPopMenu) {
jq("head").append("<style id=\"fixTopBarPopMenu\">div#user_info_menu {margin-top: 5px;}.user_info_menu_info > li {margin-top: 2px;}a.rank {padding: 2px 7px!important; border-radius: 14px;}a.rank:hover {text-decoration: none;}ul.user_info_menu_btn {padding-top: 6px;}ul.user_info_menu_btn>li>a:hover {background: #36b030;color: white;}ul.user_info_menu_btn>li>a {padding: 5px 8px;border-radius: 5px;}ul.user_info_menu_btn>li>a[onclick]:hover {background: red!important;}#myprompt_menu {margin-left: -10px;}#myprompt_menu,#usertools_menu,#sslct_menu { z-index:791!important;margin-top: 5px!important;border: 1px solid #d1d1d1;min-width: unset;border-radius: 5px;}#myprompt_menu>li>a, #usertools_menu>li>a {border: none; border-radius: 5px;text-align: center;padding: 3px 15px;}#myprompt_menu>li>a:hover, #usertools_menu>li>a:hover {background: #36b030;color: white;}div#sslct_menu {margin-left: 16px;padding-left: 14px;}.sslct_btn {border: none!important;width: 15px;height: 15px;padding: 2px;}.sslct_btn i {border-radius: 50%;width: 13px;height: 13px;}</style>");
var __extstyle = extstyle;
extstyle = function(style){
__extstyle(style);
jq("#fixTopBarPopMenuWinter").remove();
if(style == "./template/mcbbs/style/winter"){
jq("head").append("<style id=\"fixTopBarPopMenuWinter\">.user_info_menu_info li a.rank {background-color: #5c8dff!important;}ul.user_info_menu_btn>li>a:hover,#myprompt_menu>li>a:hover, #usertools_menu>li>a:hover {background: #5c8dff!important;}</style>");
}
}
var theme = getcookie('extstyle');
if(theme == "./template/mcbbs/style/winter"){
jq("head").append("<style id=\"fixTopBarPopMenuWinter\">.user_info_menu_info li a.rank {background-color: #5c8dff!important;}ul.user_info_menu_btn>li>a:hover,#myprompt_menu>li>a:hover, #usertools_menu>li>a:hover {background: #5c8dff!important;}</style>");
}
}
if (conf.hoverPreviewTheme) {
jq(document).ready(function () {
jq(".sslct_btn").first().on("mouseover", function () {
previewstyle = getcookie('extstyle');
extstyle('./template/mcbbs/style/default');
});
jq(".sslct_btn").last().on("mouseover", function () {
previewstyle = getcookie('extstyle');
extstyle('./template/mcbbs/style/winter');
});
jq(".sslct_btn").last().on("click", function () {
previewstyle = './template/mcbbs/style/winter'
});
jq(".sslct_btn").first().on("click", function () {
previewstyle = './template/mcbbs/style/default'
});
jq(".sslct_btn").on("mouseout", function () {
extstyle(previewstyle);
});
});
}
})();