// ==UserScript== // @name MCBBS Extender // @namespace https://i.zapic.cc // @version release-1.0.6 // @description MCBBS行为拓展/样式修复 // @author Zapic // @match https://*.mcbbs.net/* // @run-at document-body // @downloadURL none // ==/UserScript== (function () { var version = "v1.0.6"; var vercode = 111046; var updatecontent = "1. 修正 全屏编辑时顶栏覆盖掉工具栏的问题.
2. 瞎优化 消息推送逻辑.在阅读消息时刷新消息缓存,使推送更及时.
3. 优化 玻璃质感勋章信息样式,现在终于居中了."; if (typeof jQuery == "undefined") { console.error("This page does NOT contain JQuery,MCBBS Extender will not work."); return false; } var dlg = function (m) { console.debug("[MCBBS Extender]" + m) }; var jq = jQuery; try { var conf = JSON.parse(getcookie("MExt_config")); } catch (e) { dlg("Failed to load config\n" + e); } if (!conf) { setcookie("MExt_config", JSON.stringify({ "version": vercode, "fixCodeBlock": true, "fixCodeCopy": true, "fixTableLayout": true, "queryMessage": true, "queryMessageInterval": 60, "rememberPage": true, "animateGoToTopButton": true, "pinnedTopBar": true, "fixTopBarPopMenu": true, "hoverPreviewTheme": true, "hoverableMedal": true, "ljyysSearch": true }), 2147483647); conf = JSON.parse(getcookie("MExt_config")); showDialog("欢迎使用MCBBS Extender.
本脚本的设置按钮已经放进入了您的个人信息菜单里,如需调整设置请在个人信息菜单里寻找.","right","欢迎",function(){showMenu('user_info');jq("#MExt_config").css("background-color","#E91E63").css("color","#fff");setTimeout(function(){hideMenu('user_info_menu');jq("#MExt_config").css("background-color","").css("color","");},3000);}); dlg("Config init."); } if(typeof conf.version == "undefined" || conf.version < vercode){ showDialog("MCBBS Extender 已经更新至 "+version+"
"+updatecontent, "right"); conf.version = vercode; setcookie("MExt_config", JSON.stringify(conf), 2147483647); } jq(document).ready(function () { jq("#user_info_menu .user_info_menu_btn").append("
  • MCBBS Extender 设置
  • "); dlg("Appended Config button"); jq("head").append(''); dlg("Appended Config window style") jq("#MExt_config").on("click", function () { hideMenu("user_info_menu"); showDialog( '

    美化代码块样式
    优化代码块样式,如滚动条

    "复制代码"换行修复
    在复制代码时自动加上换行

    快捷键修复当前页面表格
    某些情况可能导致元素顶破表格,通过Shift+F快速修复此类问题.

    后台轮询消息
    在后台自动查询是否有新的消息并推送,需保证至少打开一个页面.

    后台轮询消息间隔
    两次轮询消息之间的间隔,单位秒.

    板块内翻页记忆
    点击板块内下一页按钮时记忆当前页.

    美化右侧回到顶部按钮
    为右侧回到顶部按钮增加动画

    固定顶栏
    将顶栏固定到页面顶部,不随页面滚动

    弹出菜单美化
    美化弹出菜单的样式,如个人信息菜单

    主题悬浮预览
    将鼠标指针放在切换主题按钮上即可预览主题

    玻璃质感勋章
    亮闪闪的勋章~

    ljyys搜索
    使用站外搜索代替站内搜索,绕过搜索限制,降低论坛负载,提高搜索效率.

    ', "confirm", "MCBBS Extender 设置", function () { var cf = {}; cf.fixCodeBlock = jq("#c_fixcodeblock").prop("checked"); cf.fixCodeCopy = jq("#c_fixcopycode").prop("checked"); cf.fixTableLayout = jq("#c_fixtablelayout").prop("checked"); cf.queryMessage = jq("#c_querymsg").prop("checked"); cf.queryMessageInterval = jq("#i_querymsginterval").val(); cf.rememberPage = jq("#c_rempage").prop("checked"); cf.animateGoToTopButton = jq("#c_fixgoupbtn").prop("checked"); cf.pinnedTopBar = jq("#c_fixtopbar").prop("checked"); cf.fixTopBarPopMenu = jq("#c_fixpopmenu").prop("checked"); cf.hoverPreviewTheme = jq("#c_hoverpreview").prop("checked"); cf.hoverableMedal = jq("#c_glassmedal").prop("checked"); cf.ljyysSearch = jq("#c_ljyyssearch").prop("checked"); setcookie("MExt_config", JSON.stringify(cf), 2147483647); dlg("Config cookie set."); setTimeout(function () { showDialog("设置已保存,刷新生效", "right"); }); }, true, function () {}, "MCBBS Extender "+version ); jq("#c_fixcodeblock").prop("checked", conf.fixCodeBlock); jq("#c_fixcopycode").prop("checked", conf.fixCodeCopy); jq("#c_fixtablelayout").prop("checked", conf.fixTableLayout); jq("#c_querymsg").prop("checked", conf.queryMessage); jq("#i_querymsginterval").val(conf.queryMessageInterval); jq("#c_rempage").prop("checked", conf.rememberPage); jq("#c_fixgoupbtn").prop("checked", conf.animateGoToTopButton); jq("#c_fixtopbar").prop("checked", conf.pinnedTopBar); jq("#c_fixpopmenu").prop("checked", conf.fixTopBarPopMenu); jq("#c_hoverpreview").prop("checked", conf.hoverPreviewTheme); jq("#c_glassmedal").prop("checked", conf.hoverableMedal); jq("#c_ljyyssearch").prop("checked", conf.ljyysSearch); dlg("Config cookie loaded."); }); dlg("Config button event attached."); }); if (conf.fixCodeBlock) { jq("head").append(""); dlg("Code block fix style appended."); } if (conf.fixTableLayout) { document.onkeydown = (e) => { if (e.shiftKey && e.keyCode == 70 && jq("#fixTableLayout").length == 0) { dlg("Table layout fix actived"); showDialog("是否尝试修复此页表格?", "confirm", "MCBBS Extender", function () { jq("head").append(""); }) } }; dlg("Table layout fix event attached."); } if (conf.fixCodeCopy) { copycode = function (obj) { if (!obj) { dlg("Code copy with invalid object."); 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, '代码已复制到剪贴板'); dlg("Code copied."); }; dlg("Code copy fix actived."); } if (conf.queryMessage) { var GetRequest = function(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i 200000){ jq.getJSON("/api/mobile/index.php?module=profile", function (data) { setcookie("MExt_LastNoticeContent", JSON.stringify(data.Variables.notice), 0); dlg("Last notice is 200s or more ago,flush cache."); }); } var queryId = hash(new Date().getTime().toLocaleString(), 16); dlg("Query id is " + queryId + "."); if (!window.Html5notification) { jq.getScript("data/cache/html5notification.js?xm6"); dlg("Html5notification added."); } 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) && getcookie("MExt_ActiveQueryId") != queryId) { setcookie("MExt_ActiveQueryId", queryId, 0); dlg("Kick off inactive querier,start query."); } if(getcookie("MExt_ActiveQueryId") == queryId){ setcookie("MExt_LastQuery", nowtime, 0); } }, 1000); dlg("Running checker actived."); setInterval(function () { dlg("Start to check message."); localStorage.setItem('notifica-time', new Date().getTime()); jq.getJSON("/api/mobile/index.php?module=profile", function (data) { var notices = data.Variables.notice; var noticecontent = JSON.stringify(notices); jq.get("/forum.php?mod=misc", function (d) { var dom = jq(d); 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 = dom.filter("script[src*=html5notification]").nextUntil("div").last().text(); if (getcookie("MExt_ActiveQueryId") == queryId && noticecontent != getcookie("MExt_LastNoticeContent")) { localStorage.setItem('notifica-time', 1); eval(s); dlg("Notification sent."); } setcookie("MExt_LastNoticeContent", noticecontent, 0); }); }); }, conf.queryMessageInterval * 1000); dlg("Message querier actived."); } 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(); }; } dlg("Page remember actived."); }); } if (conf.animateGoToTopButton) { jq("head").append(""); dlg("Animate go to top buttom style appended."); showTopLink = function () { var ft = $('ft'); if (ft) { var scrolltop = $('scrolltop'); if (!scrolltop) { return false; } 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(); dlg("Animate go to top buttom actived."); } if (conf.pinnedTopBar) { jq("head").append(""); dlg("Pinned top bar style appended."); } if (conf.fixTopBarPopMenu) { jq("head").append(""); dlg("Pop menu fix style appended."); 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(""); } dlg("Overwrite extstyle function"); } if (conf.hoverPreviewTheme) { jq(document).ready(function () { jq(".sslct_btn").on("mouseenter",function(){ var that = this; var timer = setTimeout(function(){ clearTimeout(timer); var previewstyle = getcookie('extstyle'); jq(that).trigger('click'); setcookie('extstyle', previewstyle); },300); }); jq(".sslct_btn").on("mouseleave", function () { extstyle(getcookie('extstyle')); }); dlg("Hover preview theme event attached."); }); } if (conf.hoverableMedal) { var rewriteMedal = function () { jq('.md_ctrl:not([glassmedal])').attr("glassmedal","true").each(function (t, v) { jq(v).children(0).children('img').each(function (b, n) { var id = 'md' + new RegExp('\\_\\d*$').exec(jq(n).attr('id'))[0]; jq(v).append( jq( jq('
    ').on('mouseover', function () { 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(); }); }); dlg("Hoverable medal rewrote."); }; jq(document).ready(rewriteMedal).ready( function(){ var __ajaxget = ajaxget; var __ajaxpost = ajaxpost; ajaxpost = function (formid, showid, waitid, showidclass, submitbtn, recall) { var relfunc = function(){ if (typeof recall == 'function') { recall(); } else { eval(recall); } setTimeout(rewriteMedal); } __ajaxpost(formid,showid,waitid,showidclass,submitbtn,relfunc); } ajaxget = function (url, showid, waitid, loading, display, recall) { var relfunc = function(){ if (typeof recall == 'function') { recall(); } else { eval(recall); } setTimeout(rewriteMedal); } __ajaxget(url, showid, waitid, loading, display,relfunc); } } ); jq("head").append(""); dlg("Hoverable medal style appended."); } if(conf.ljyysSearch){ jq(document).ready(function(){ jq("#scbar_form [type*=hidden]").remove(); jq("#scbar_txt").attr("name","search").css("background-color","#00000000"); jq(".scbar_type_td").html("ljyys搜索").css("background","url(https://www.mcbbs.net/template/mcbbs/image/scbar_txt.png) -94px center no-repeat").css("width","62px").css("cursor","pointer"); jq("#scbar_form").attr("method","get").attr("action","//search.ljyys.xyz/search.php"); dlg("ljyys search actived"); }); } })();