MCBBS Extender

MCBBS行为拓展/样式修复

目前为 2020-02-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name MCBBS Extender
  3. // @namespace https://i.zapic.cc
  4. // @version beta-0.0.8
  5. // @description MCBBS行为拓展/样式修复
  6. // @author Zapic
  7. // @match https://www.mcbbs.net/*
  8. // @run-at document-body
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. var conf = {
  13. //美化代码块样式
  14. "fixCodeBlock": true,
  15. //修复代码块"复制代码"换行消失的问题
  16. "fixCodeCopy": true,
  17. //修复表格排版内含有多媒体导致元素戳破表格的问题
  18. "fixTableLayout": true,
  19. //后台轮询新消息
  20. "QueryMessage": true,
  21. //后台轮询消息间隔,单位为秒
  22. "QueryMessageInterval": 60,
  23. //板块页点击"下一页"按钮是否记住当前页码
  24. "rememberPage": true,
  25. //美化右侧回到顶部按钮
  26. "animateGoToTopButton": true,
  27. //固定顶栏在顶部
  28. "pinnedTopBar": true,
  29. //顶栏弹出菜单美化&对齐
  30. "fixTopBarPopMenu": true,
  31. //主题悬浮预览
  32. "hoverPreviewTheme": true
  33. };
  34. var jq = jQuery;
  35. if (conf.fixCodeBlock) {
  36. 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>");
  37. }
  38. if (conf.fixTableLayout) {
  39. jq("head").append("<style id=\"fixTableLayout\">.pl table.t_table{table-layout: fixed;}.pl table.t_table[style*=\"px\"]{table-layout: auto;}</style>");
  40. }
  41. if (conf.fixCodeCopy) {
  42. copycode = function (obj) {
  43. if (!obj)
  44. return false;
  45. var count = obj.children[0].children.length;
  46. var code = "";
  47. for (i = 0; i < count; i++) {
  48. code += obj.children[0].children[i].innerText + "\r\n";
  49. }
  50. setCopy(code, '代码已复制到剪贴板');
  51. };
  52. }
  53. if (conf.QueryMessage) {
  54. setInterval(function () {
  55. jq.get("https://www.mcbbs.net/", function (d) {
  56. var dom = jq(d);
  57. var el = dom.filter("script[src*=html5notification]");
  58. var ut = dom.find(".user_tools");
  59. var pum = dom.filter("#myprompt_menu");
  60. jq(".user_tools").html(ut.html());
  61. jq("#myprompt_menu").html(pum.html());
  62. jq("title").text(NOTICECURTITLE);
  63. if (el.length !== 0) {
  64. if (!window.Html5notification) {
  65. jq.get(el[0].src, function (s) {
  66. eval(s);
  67. });
  68. }
  69. var s = el.nextUntil("div").last().text();
  70. eval(s);
  71. noticeTitle();
  72. }
  73. });
  74. }, conf.QueryMessageInterval * 1000);
  75. }
  76. if (conf.rememberPage) {
  77. jq(document).ready(function () {
  78. if ($('autopbn')) {
  79. var npbtn = $('autopbn')
  80. var dc = npbtn.onclick;
  81. npbtn.onclick = function () {
  82. var nextpageurl = this.getAttribute('rel').valueOf();
  83. var curpage = parseInt(this.getAttribute('curpage').valueOf());
  84. this.setAttribute('curpage', curpage + 1);
  85. nextpageurl = nextpageurl.replace(/&page=\d+/, '&page=' + (curpage + 1));
  86. history.replaceState(null, null, nextpageurl);
  87. dc();
  88. };
  89. }
  90. });
  91. }
  92. if (conf.animateGoToTopButton) {
  93. jq("head").append("<style id=\"GoToTopButton\">#scrolltop{bottom: 270px!important;visibility:visible;overflow-x:hidden;width:75px;}.scrolltopa{transition-duration:.15s;margin-left:-40px;opacity:0;}.scrolltopashow{margin-left:0px;opacity:1;}</style>");
  94. showTopLink = function () {
  95. var ft = $('ft');
  96. if (ft) {
  97. var scrolltop = $('scrolltop');
  98. var scrolltopbtn = jq(".scrolltopa");
  99. var viewPortHeight = parseInt(document.documentElement.clientHeight);
  100. var scrollHeight = parseInt(document.body.getBoundingClientRect().top);
  101. var basew = parseInt(ft.clientWidth);
  102. var sw = scrolltop.clientWidth;
  103. if (basew < 1000) {
  104. var left = parseInt(fetchOffset(ft)['left']);
  105. left = left < sw ? left * 2 - sw : left;
  106. scrolltop.style.left = (basew + left + 44) + 'px';
  107. } else {
  108. scrolltop.style.left = 'auto';
  109. scrolltop.style.right = 0;
  110. }
  111. if (scrollHeight < -100) {
  112. scrolltopbtn.addClass("scrolltopashow");
  113. } else {
  114. scrolltopbtn.removeClass("scrolltopashow");
  115. }
  116. }
  117. }
  118. showTopLink();
  119. }
  120. if (conf.pinnedTopBar) {
  121. 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>");
  122. }
  123. if (conf.fixTopBarPopMenu) {
  124. 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>");
  125. var __extstyle = extstyle;
  126. extstyle = function(style){
  127. __extstyle(style);
  128. jq("#fixTopBarPopMenuWinter").remove();
  129. if(style == "./template/mcbbs/style/winter"){
  130. 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>");
  131. }
  132. }
  133. var theme = getcookie('extstyle');
  134. if(theme == "./template/mcbbs/style/winter"){
  135. 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>");
  136. }
  137. }
  138. if (conf.hoverPreviewTheme) {
  139. jq(document).ready(function () {
  140. jq(".sslct_btn").first().on("mouseover", function () {
  141. previewstyle = getcookie('extstyle');
  142. extstyle('./template/mcbbs/style/default');
  143. });
  144. jq(".sslct_btn").last().on("mouseover", function () {
  145. previewstyle = getcookie('extstyle');
  146. extstyle('./template/mcbbs/style/winter');
  147. });
  148. jq(".sslct_btn").last().on("click", function () {
  149. previewstyle = './template/mcbbs/style/winter'
  150. });
  151. jq(".sslct_btn").first().on("click", function () {
  152. previewstyle = './template/mcbbs/style/default'
  153. });
  154. jq(".sslct_btn").on("mouseout", function () {
  155. extstyle(previewstyle);
  156. });
  157. });
  158. }
  159. })();