// ==UserScript==
// @name MCBBS Extender
// @namespace https://i.zapic.cc
// @version release-1.0.0
// @description MCBBS行为拓展/样式修复
// @author Zapic
// @match https://www.mcbbs.net/*
// @run-at document-body
// @downloadURL none
// ==/UserScript==
(function () {
var conf = {
//美化代码块样式
"fixCodeBlock": true,
//修复代码块"复制代码"换行消失的问题
"fixCodeCopy": true,
//修复表格排版内含有多媒体导致元素戳破表格的问题
"fixTableLayout": true,
//后台轮询新消息
"QueryMessage": true,
//后台轮询消息间隔,单位为秒
"QueryMessageInterval": 60,
//板块页点击"下一页"按钮是否记住当前页码
"rememberPage": true,
//美化右侧回到顶部按钮
"animateGoToTopButton": true,
//固定顶栏在顶部
"pinnedTopBar": true,
//顶栏弹出菜单美化&对齐
"fixTopBarPopMenu": true,
//主题悬浮预览
"hoverPreviewTheme": true,
//玻璃质感勋章
"hoverableMedal": true
};
if (typeof jQuery == "undefined") {
console.log("This page does NOT contain JQuery,MCBBS Extender will not work.");
return false;
}
var jq = jQuery;
if (conf.fixCodeBlock) {
jq("head").append("");
}
if (conf.fixTableLayout) {
jq("head").append("");
}
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) {
var queryId = hash(new Date().getTime().toLocaleString(),16);
var starttime = Math.floor(new Date().getTime()/1000);
if (!window.Html5notification) {
jq.getScript("data/cache/html5notification.js?xm6");
}
var RunningTimer = setInterval(function () {
if(getcookie("MExt_LastQuery")==""){
setcookie("MExt_LastQuery",0,0);
}
var nowtime = Math.floor(new Date().getTime()/1000);
if(getcookie("MExt_ActiveQueryId") == "" || nowtime - getcookie("MExt_LastQuery") > 5){
setcookie("MExt_ActiveQueryId",queryId,0);
}
if(getcookie("MExt_ActiveQueryId") !== queryId){
if(typeof QueryTimer != "undefined"){
clearInterval(QueryTimer);
QueryTimer = undefined;
}
return false;
}
setcookie("MExt_LastQuery",nowtime,0);
if(typeof QueryTimer == "undefined"){
QueryTimer = setInterval(function(){
localStorage.setItem('notifica-time',new Date().getTime());
jq.getJSON("https://www.mcbbs.net/api/mobile/index.php?module=profile",function(data){
var notices = data.Variables.notice;
var noticecontent = JSON.stringify(notices);
if(notices.newpm + notices.newprompt + notices.newmypost > 0){
jq.get("https://www.mcbbs.net/forum.php?mod=misc", 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);
var s = el.nextUntil("div").last().text();
if(noticecontent != getcookie("MExt_LastNoticeContent")){
localStorage.setItem('notifica-time',1);
eval(s);
}
setcookie("MExt_LastNoticeContent",noticecontent,0);
});
}
});
},conf.QueryMessageInterval*1000);
}
}, 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("");
showTopLink = function () {
var ft = $('ft');
if (ft) {
var scrolltop = $('scrolltop');
var scrolltopbtn = jq(".scrolltopa");
var viewPortHeight = parseInt(document.documentElement.clientHeight);
var scrollHeight = parseInt(document.body.getBoundingClientRect().top);
var basew = parseInt(ft.clientWidth);
var sw = scrolltop.clientWidth;
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 (scrollHeight < -100) {
scrolltopbtn.addClass("scrolltopashow");
} else {
scrolltopbtn.removeClass("scrolltopashow");
}
}
}
showTopLink();
}
if (conf.pinnedTopBar) {
jq("head").append("");
}
if (conf.fixTopBarPopMenu) {
jq("head").append("");
var __extstyle = extstyle;
extstyle = function (style) {
__extstyle(style);
jq("#fixTopBarPopMenuWinter").remove();
if (style == "./template/mcbbs/style/winter") {
jq("head").append("");
}
}
var theme = getcookie('extstyle');
if (theme == "./template/mcbbs/style/winter") {
jq("head").append("");
}
}
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);
});
});
}
if (conf.hoverableMedal) {
jq(document).ready(() => {
jq('.md_ctrl').each((t, v) => {
jq(v).children(0).children('img').each((b, n) => {
var id = 'md' + new RegExp('\\_\\d*$').exec(jq(n).attr('id'))[0];
jq(v).append(jq(jq('').on('mouseover', () => {
showMenu({
'ctrlid': jq(n).attr('id'),
'menuid': id + '_menu',
'pos': '12!'
});
})));
jq("#" + id + "_menu .tip_horn").css("background-image", "url(" + jq(n).attr('src') + ")");
jq(n).remove();
})
})
});
jq("head").append("");
}
})();