From c19ed5cdcf106e99e825a12f5c4bc9cd70b879db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=9F=92?= <893177236@qq.com> Date: Sun, 2 Jun 2024 16:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(=E4=BF=AE=E5=A4=8DenvIsMobil?= =?UTF-8?q?e=E6=A3=80=E6=B5=8Bdz=E6=A8=A1=E6=9D=BF=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MT\350\256\272\345\235\233.user.js" | 27713 ++++++++-------- 1 file changed, 13857 insertions(+), 13856 deletions(-) diff --git "a/MT\350\256\272\345\235\233/MT\350\256\272\345\235\233.user.js" "b/MT\350\256\272\345\235\233/MT\350\256\272\345\235\233.user.js" index 08141d369..6103847f6 100644 --- "a/MT\350\256\272\345\235\233/MT\350\256\272\345\235\233.user.js" +++ "b/MT\350\256\272\345\235\233/MT\350\256\272\345\235\233.user.js" @@ -4,8 +4,8 @@ // @namespace https://greasyfork.org/zh-CN/scripts/401359 // @supportURL https://github.com/WhiteSevs/TamperMonkeyScript/issues // @description MT论坛效果增强,如自动签到、自动展开帖子、滚动加载评论、显示UID、自定义屏蔽、手机版小黑屋、编辑器优化、在线用户查看、便捷式图床、自定义用户标签、积分商城商品上架提醒等 -// @description 更新日志: 修复环境内缺失unsafeWindow; -// @version 2024.5.28 +// @description 更新日志: 修复envIsMobile检测dz模板失败问题; +// @version 2024.6.2 // @author WhiteSevs // @run-at document-start // @match *://bbs.binmt.cc/* @@ -39,160 +39,160 @@ // ==/UserScript== (async function () { - "use strict"; - if (typeof unsafeWindow === "undefined") { - var unsafeWindow = window; - } - const console = unsafeWindow.console; - /** - * @type {import("../库/Utils")} - */ - const utils = (window.Utils || Utils).noConflict(); - let $jq = null; - /** - * @type {import("../库/any-touch/index.umd")} - */ - let AnyTouch = window.AnyTouch; - /** - * @type {import("../库/Viewer/index")} - */ - let Viewer = window.Viewer; - /** - * @type {import("../库/js-watermark/index")} - */ - let Watermark = window.Watermark; - /** - * @type {import("../库/Xtiper/index")} - */ - let xtip = window.xtip; - - let WhiteSev_GM_Cookie = new utils.GM_Cookie(); - /** - * 自定义新的popups弹窗代替popup - */ - const popups = { - config: { - mask: { - zIndex: 1000000, - style: `#force-mask{width:100%;height:100%;position:fixed;top:0;left:0;background:#000;opacity:.6;z-index:1000000;display:flex;align-content:center;justify-content:center;align-items:center}`, - }, - confirm: { - zIndex: 1000100, - style: `#popups-confirm .popups-confirm-cancel,#popups-confirm .popups-confirm-ok{user-select:none;width:100%!important;background:0 0!important;border-radius:unset}`, - }, - toast: { - zIndex: 1100000, - style: `.popups-toast{width:fit-content;padding:10px 16px;color:#fff;background:rgba(0,0,0,.65);position:fixed;margin:0 auto;left:0;right:0;bottom:0;border-radius:4px;font-size:14px;z-index:1100000;max-width:80vw;opacity:1;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-font-smoothing:antialiased/subpixel-antialiased;touch-action:pan-y;-webkit-user-select:none;user-select:none;transform:translateY(160px)} + "use strict"; + if (typeof unsafeWindow === "undefined") { + var unsafeWindow = window; + } + const console = unsafeWindow.console; + /** + * @type {import("../库/Utils")} + */ + const utils = (window.Utils || Utils).noConflict(); + let $jq = null; + /** + * @type {import("../库/any-touch/index.umd")} + */ + let AnyTouch = window.AnyTouch; + /** + * @type {import("../库/Viewer/index")} + */ + let Viewer = window.Viewer; + /** + * @type {import("../库/js-watermark/index")} + */ + let Watermark = window.Watermark; + /** + * @type {import("../库/Xtiper/index")} + */ + let xtip = window.xtip; + + let WhiteSev_GM_Cookie = new utils.GM_Cookie(); + /** + * 自定义新的popups弹窗代替popup + */ + const popups = { + config: { + mask: { + zIndex: 1000000, + style: `#force-mask{width:100%;height:100%;position:fixed;top:0;left:0;background:#000;opacity:.6;z-index:1000000;display:flex;align-content:center;justify-content:center;align-items:center}`, + }, + confirm: { + zIndex: 1000100, + style: `#popups-confirm .popups-confirm-cancel,#popups-confirm .popups-confirm-ok{user-select:none;width:100%!important;background:0 0!important;border-radius:unset}`, + }, + toast: { + zIndex: 1100000, + style: `.popups-toast{width:fit-content;padding:10px 16px;color:#fff;background:rgba(0,0,0,.65);position:fixed;margin:0 auto;left:0;right:0;bottom:0;border-radius:4px;font-size:14px;z-index:1100000;max-width:80vw;opacity:1;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-font-smoothing:antialiased/subpixel-antialiased;touch-action:pan-y;-webkit-user-select:none;user-select:none;transform:translateY(160px)} .popups-toast-show{transform:translateY(-80px)!important;transition:all .2s ease 0s;-webkit-transition:all .2s ease 0s} `, - }, - }, - /** - * 初始化 - */ - init() { - Object.keys(popups.config).forEach((key) => { - let style = popups.config[key].style; - if (style !== "") { - GM_addStyle(style); - } - }); - }, - /** - * 初始化遮罩层 - * @param {number} zIndex - */ - initMask(zIndex) { - document.documentElement.style.overflow = "hidden"; - if (!$jq("#force-mask").length) { - $jq("body").append($jq('
')); - } else { - $jq("#force-mask").html(""); - } - if (!zIndex) { - /* 遮罩层z-index为最大的>10 */ - $jq("#force-mask").css("z-index", utils.getMaxZIndex() + 10); - } - }, - /** - * 确认弹窗 - * @param {string|{ - * text: string, - * reverse: boolean, - * mask: boolean, - * only: boolean, - * ok: { - * enable: boolean, - * text: string, - * callback: Function, - * }, - * cancel: { - * enable: boolean, - * text: string, - * callback: Function, - * }, - * other: { - * enable: boolean, - * text: string, - * callback: Function, - * }, - * }} paramOptions - * @returns - */ - confirm(paramOptions) { - let options = { - text: "Call By popups.confirm", - reverse: false /* 底部按钮倒序 */, - mask: true, - only: true, - ok: { - enable: true, - text: "确定", - callback: () => { - popups.closeConfirm(); - }, - }, - cancel: { - enable: true, - text: "取消", - callback: () => { - popups.closeConfirm(); - }, - }, - other: { - enable: false, - text: "另一个按钮", - callback: () => { - popups.closeConfirm(); - }, - }, - }; - if (typeof paramOptions == "string") { - options.text = paramOptions; - } else { - options = utils.assign(options, paramOptions); - } - let bottomBtnHTML = ""; - let confirmHTML = ""; - /* confirm层z-index为最大的>110 */ - let maxZIndex = utils.getMaxZIndex() + 10; - let confirmZIndex = - popups.config.confirm.zIndex > maxZIndex - ? popups.config.confirm.zIndex - : maxZIndex + 100; - if (!options.reverse) { - bottomBtnHTML = `${options.cancel.text} + }, + }, + /** + * 初始化 + */ + init() { + Object.keys(popups.config).forEach((key) => { + let style = popups.config[key].style; + if (style !== "") { + GM_addStyle(style); + } + }); + }, + /** + * 初始化遮罩层 + * @param {number} zIndex + */ + initMask(zIndex) { + document.documentElement.style.overflow = "hidden"; + if (!$jq("#force-mask").length) { + $jq("body").append($jq('')); + } else { + $jq("#force-mask").html(""); + } + if (!zIndex) { + /* 遮罩层z-index为最大的>10 */ + $jq("#force-mask").css("z-index", utils.getMaxZIndex() + 10); + } + }, + /** + * 确认弹窗 + * @param {string|{ + * text: string, + * reverse: boolean, + * mask: boolean, + * only: boolean, + * ok: { + * enable: boolean, + * text: string, + * callback: Function, + * }, + * cancel: { + * enable: boolean, + * text: string, + * callback: Function, + * }, + * other: { + * enable: boolean, + * text: string, + * callback: Function, + * }, + * }} paramOptions + * @returns + */ + confirm(paramOptions) { + let options = { + text: "Call By popups.confirm", + reverse: false /* 底部按钮倒序 */, + mask: true, + only: true, + ok: { + enable: true, + text: "确定", + callback: () => { + popups.closeConfirm(); + }, + }, + cancel: { + enable: true, + text: "取消", + callback: () => { + popups.closeConfirm(); + }, + }, + other: { + enable: false, + text: "另一个按钮", + callback: () => { + popups.closeConfirm(); + }, + }, + }; + if (typeof paramOptions == "string") { + options.text = paramOptions; + } else { + options = utils.assign(options, paramOptions); + } + let bottomBtnHTML = ""; + let confirmHTML = ""; + /* confirm层z-index为最大的>110 */ + let maxZIndex = utils.getMaxZIndex() + 10; + let confirmZIndex = + popups.config.confirm.zIndex > maxZIndex + ? popups.config.confirm.zIndex + : maxZIndex + 100; + if (!options.reverse) { + bottomBtnHTML = `${options.cancel.text} ${options.ok.text} `; - } else { - bottomBtnHTML = `${options.ok.text} + } else { + bottomBtnHTML = `${options.ok.text} ${options.cancel.text} `; - } + } - confirmHTML = ` + confirmHTML = `${error.toString()}
`, - }); - }) - .run(item["js"], that); - }; - } - mtUidDomInsertElement.parentElement.append(labelElement); - }); - }); - }, - run() { - let that = this; - this.setCSS(); - utils.mutationObserver(document.documentElement, { - callback: (mutations, observer) => { - /* 判断是否已找到 */ - if (that.isFind) { - that.handleForum(); - /* console.log("成功找到帖子DOM"); */ - observer.disconnect(); - return; - } - /* 正在寻找中 */ - if (that.isFinding) { - return; - } - that.isFinding = true; - that.forumList = utils.getNodeListValue( - DOM_CONFIG.element.comiisForumList, - DOM_CONFIG.element.comiisPostli, - DOM_CONFIG.element.comiisMmlist - ); - that.isFind = Boolean(that.forumList.length); - !that.isFind && (that.forumList = null); - setTimeout(() => { - that.isFinding = false; - }, 250); - }, - config: { subtree: true, childList: true }, - }); - }, - }; - - handleShowUserLabels.run(); - } - }, - /** - * 页面小窗浏览帖子 - */ - pageSmallWindowBrowsingForumPost() { - if ( - !GM_getValue("v45", false) && - (!window.location.href.match(DOM_CONFIG.urlRegexp.forumGuideUrl) || - !window.location.href.match(DOM_CONFIG.urlRegexp.searchUrl)) - ) { - return; - } - - let small_icon_width = 24; - let small_right_btn_width = 115; - let small_title_width = `calc(100% - ${ - small_icon_width + small_right_btn_width - }px)`; - function initCSS() { - GM_addStyle(` + labelElement.innerHTML = item["labels"]; + if (utils.isNotNull(item["js"])) { + labelElement.onclick = function () { + let that = this; + utils + .tryCatch() + .error(function (error) { + popups.confirm({ + title: "执行JS失败", + text: `${error.toString()}
`, + }); + }) + .run(item["js"], that); + }; + } + mtUidDomInsertElement.parentElement.append(labelElement); + }); + }); + }, + run() { + let that = this; + this.setCSS(); + utils.mutationObserver(document.documentElement, { + callback: (mutations, observer) => { + /* 判断是否已找到 */ + if (that.isFind) { + that.handleForum(); + /* console.log("成功找到帖子DOM"); */ + observer.disconnect(); + return; + } + /* 正在寻找中 */ + if (that.isFinding) { + return; + } + that.isFinding = true; + that.forumList = utils.getNodeListValue( + DOM_CONFIG.element.comiisForumList, + DOM_CONFIG.element.comiisPostli, + DOM_CONFIG.element.comiisMmlist + ); + that.isFind = Boolean(that.forumList.length); + !that.isFind && (that.forumList = null); + setTimeout(() => { + that.isFinding = false; + }, 250); + }, + config: { subtree: true, childList: true }, + }); + }, + }; + + handleShowUserLabels.run(); + } + }, + /** + * 页面小窗浏览帖子 + */ + pageSmallWindowBrowsingForumPost() { + if ( + !GM_getValue("v45", false) && + (!window.location.href.match(DOM_CONFIG.urlRegexp.forumGuideUrl) || + !window.location.href.match(DOM_CONFIG.urlRegexp.searchUrl)) + ) { + return; + } + + let small_icon_width = 24; + let small_right_btn_width = 115; + let small_title_width = `calc(100% - ${ + small_icon_width + small_right_btn_width + }px)`; + function initCSS() { + GM_addStyle(` .xtiper_sheet,.xtiper_sheet .xtiper_sheet_tit{border-radius:18px 18px 0 0} .xtiper_sheet_tit.xtiper_sheet_left{display:block;background:#fff;width:100%;box-sizing:border-box} .xtiper_sheet_tit.xtiper_sheet_left img.xtiper_tit_ico{background: #fff;filter: invert(100%);width: ${small_icon_width}px;height: ${small_icon_width}px;align-self: center;border-radius: 3px} @@ -2856,7 +2857,7 @@ .xtiper_sheet_tit_top_drag{width:100%;position:relative;height:10px} .xtiper_sheet_tit_top_drag div{width:50px;margin:0 auto;height:4px;background:#d9d9d9;border-radius:15px;bottom:3px;position:relative} `); - GM_addStyle(` + GM_addStyle(` .refresh-icon{width:40px;display:flex;align-items:center} .refresh-icon-in,.refresh-icon-out{position:absolute;border:5px solid rgba(0,183,229,.9);opacity:.9;border-radius:50px;box-shadow:0 0 15px #2187e7;width:20px;height:20px;margin:0 auto} .refresh-icon-out{background-color:rgba(0,0,0,0);border-right:5px solid transparent;border-left:5px solid transparent;-moz-animation:spinPulse 1s infinite ease-in-out;-webkit-animation:spinPulse 1s infinite ease-in-out;-o-animation:spinPulse 1s infinite ease-in-out;-ms-animation:spinPulse 1s infinite ease-in-out} @@ -2917,100 +2918,100 @@ @-ms-keyframes spinoffPulse{0%{-ms-transform:rotate(0)} 100%{-ms-transform:rotate(360deg)} }`); - } - - /** - * 获取当前页面所有帖子 - * @returns - */ - function getForumList() { - return utils.getNodeListValue( - DOM_CONFIG.element.comiisForumList, - DOM_CONFIG.element.comiisPostli, - DOM_CONFIG.element.comiisMmlist - ); - } - let forumlist = null; /* 帖子列表 */ - let isFind = false; /* 是否找到帖子 */ - let isFinding = false; /* 是否正在找到帖子 */ - let smallWindowId = null; /* 小窗对象 */ - utils.mutationObserver(document.documentElement, { - callback: (mutations, observer) => { - /* 判断是否已找到 */ - if (isFind) { - initCSS(); - handleForumPost(); - /* console.log("成功找到小窗"); */ - observer.disconnect(); - return; - } - /* 正在寻找中 */ - if (isFinding) { - return; - } - isFinding = true; - forumlist = getForumList(); - isFind = forumlist.length ? true : false; - !isFind && (forumlist = null); - - setTimeout(() => { - isFinding = false; - }, 250); - }, - config: { subtree: true, childList: true }, - }); - - /** - * 设置浏览器历史地址 - */ - function popstateFunction() { - window.history.pushState("forward", null, "#"); - window.history.forward(1); - resumeBack(); - } - - /** - * 禁止浏览器后退按钮 - */ - function banBack() { - if (window.history && window.history.pushState) { - $jq(window).on("popstate", popstateFunction); - } - /* 在IE中必须得有这两行 */ - window.history.pushState("forward", null, "#"); - window.history.forward(1); - } - - /** - * 允许浏览器后退并关闭小窗 - * @returns - */ - async function resumeBack() { - xtip.close(smallWindowId); - smallWindowId = null; - $jq(window).off("popstate", popstateFunction); - while (1) { - if (window.location.href == "https://bbs.binmt.cc/#") { - console.log("back!"); - await utils.setTimeout("window.history.back();", 100); - await utils.sleep(100); - } else { - return; - } - } - } + } + + /** + * 获取当前页面所有帖子 + * @returns + */ + function getForumList() { + return utils.getNodeListValue( + DOM_CONFIG.element.comiisForumList, + DOM_CONFIG.element.comiisPostli, + DOM_CONFIG.element.comiisMmlist + ); + } + let forumlist = null; /* 帖子列表 */ + let isFind = false; /* 是否找到帖子 */ + let isFinding = false; /* 是否正在找到帖子 */ + let smallWindowId = null; /* 小窗对象 */ + utils.mutationObserver(document.documentElement, { + callback: (mutations, observer) => { + /* 判断是否已找到 */ + if (isFind) { + initCSS(); + handleForumPost(); + /* console.log("成功找到小窗"); */ + observer.disconnect(); + return; + } + /* 正在寻找中 */ + if (isFinding) { + return; + } + isFinding = true; + forumlist = getForumList(); + isFind = forumlist.length ? true : false; + !isFind && (forumlist = null); + + setTimeout(() => { + isFinding = false; + }, 250); + }, + config: { subtree: true, childList: true }, + }); + + /** + * 设置浏览器历史地址 + */ + function popstateFunction() { + window.history.pushState("forward", null, "#"); + window.history.forward(1); + resumeBack(); + } + + /** + * 禁止浏览器后退按钮 + */ + function banBack() { + if (window.history && window.history.pushState) { + $jq(window).on("popstate", popstateFunction); + } + /* 在IE中必须得有这两行 */ + window.history.pushState("forward", null, "#"); + window.history.forward(1); + } + + /** + * 允许浏览器后退并关闭小窗 + * @returns + */ + async function resumeBack() { + xtip.close(smallWindowId); + smallWindowId = null; + $jq(window).off("popstate", popstateFunction); + while (1) { + if (window.location.href == "https://bbs.binmt.cc/#") { + console.log("back!"); + await utils.setTimeout("window.history.back();", 100); + await utils.sleep(100); + } else { + return; + } + } + } - function showSmallWindow(title, url, imagesList = []) { - /* 显示小窗 */ - let constructURL = new URL(url); - let isHTTPS = constructURL.protocol.includes("https:"); - let icon_safe = ``; /* 安全的图标 */ - let icon_unsafe = ``; /* 不安全的图标 */ - let icon_openBlank = ``; /* 新标签页打开的按钮 */ - let icon_close = ``; /* 关闭的按钮 */ - let icon_picture_html = - imagesList.length !== 0 - ? ` + let icon_picture_html = + imagesList.length !== 0 + ? `是否清空脚本签到记录的时间?
", - ok: { - callback: () => { - GM_deleteValue("mt_sign"); - if (GM_getValue("mt_sign", null) != null) { - popups.toast("删除失败"); - } else { - popups.toast("删除成功"); - popups.closeMask(); - popups.closeConfirm(); - } - }, - }, - mask: true, - }); - }); - $jq(".comiis_head.f_top")?.append(deleteLocalStorageSignInfo); - } - - if (!(await checkLogin())) { - popups.toast("当前尚未登录账号"); - GM_deleteValue("mt_sign"); - return; - } - - let formhash = getFormHash(); - if (formhash == null) { - if (document.querySelector("#comiis_picshowbox")) { - /* 当前为评论区的看图模式 */ - console.log("当前为评论区的看图模式 "); - return; - } - console.log("获取账号formhash失败"); - GM_deleteValue("mt_sign"); - popups.toast({ - text: "获取账号formhash失败", - }); - return; - } - if ( - GM_getValue("mt_sign") == - parseInt(utils.formatTime(undefined, "yyyyMMdd")) - ) { - return; - } else { - signIn(formhash); - } - }, - /** - * 附件点击提醒 - */ - attachmentClickReminder() { - if (!DOM_CONFIG.methodRunCheck([DOM_CONFIG.urlRegexp.forumPost], "v57")) { - return; - } - /** - * 处理元素内的a标签的点击 - * @param {HTMLElement} item - */ - function handleClick(item) { - if (item.hasAttribute("href")) { - let attachmentURL = item.getAttribute("href"); - let attachmentNameNode = item.querySelector("span.f_ok"); - let attachmentDownloadInfo = item.querySelector(".attach_size"); - if (attachmentDownloadInfo.innerText.indexOf("金币") === -1) { - return; - } - console.log("发现附件", item); - console.log("该附件是金币附件,拦截!"); - let attachmentName = attachmentNameNode.innerText; - item.setAttribute("data-href", item.getAttribute("href")); - item.removeAttribute("href"); - attachmentNameNode.innerText = "【已拦截】" + attachmentName; - item.onclick = function () { - popups.confirm({ - text: `是否清空脚本签到记录的时间?
", + ok: { + callback: () => { + GM_deleteValue("mt_sign"); + if (GM_getValue("mt_sign", null) != null) { + popups.toast("删除失败"); + } else { + popups.toast("删除成功"); + popups.closeMask(); + popups.closeConfirm(); + } + }, + }, + mask: true, + }); + }); + $jq(".comiis_head.f_top")?.append(deleteLocalStorageSignInfo); + } + + if (!(await checkLogin())) { + popups.toast("当前尚未登录账号"); + GM_deleteValue("mt_sign"); + return; + } + + let formhash = getFormHash(); + if (formhash == null) { + if (document.querySelector("#comiis_picshowbox")) { + /* 当前为评论区的看图模式 */ + console.log("当前为评论区的看图模式 "); + return; + } + console.log("获取账号formhash失败"); + GM_deleteValue("mt_sign"); + popups.toast({ + text: "获取账号formhash失败", + }); + return; + } + if ( + GM_getValue("mt_sign") == + parseInt(utils.formatTime(undefined, "yyyyMMdd")) + ) { + return; + } else { + signIn(formhash); + } + }, + /** + * 附件点击提醒 + */ + attachmentClickReminder() { + if (!DOM_CONFIG.methodRunCheck([DOM_CONFIG.urlRegexp.forumPost], "v57")) { + return; + } + /** + * 处理元素内的a标签的点击 + * @param {HTMLElement} item + */ + function handleClick(item) { + if (item.hasAttribute("href")) { + let attachmentURL = item.getAttribute("href"); + let attachmentNameNode = item.querySelector("span.f_ok"); + let attachmentDownloadInfo = item.querySelector(".attach_size"); + if (attachmentDownloadInfo.innerText.indexOf("金币") === -1) { + return; + } + console.log("发现附件", item); + console.log("该附件是金币附件,拦截!"); + let attachmentName = attachmentNameNode.innerText; + item.setAttribute("data-href", item.getAttribute("href")); + item.removeAttribute("href"); + attachmentNameNode.innerText = "【已拦截】" + attachmentName; + item.onclick = function () { + popups.confirm({ + text: `${value["username"]}
${value["dateline"]}
@@ -4382,9 +4383,9 @@${value["operator"]}
识别链接
@@ -16591,73 +16592,73 @@如果您是第一次使用,请看演示GIF
如果您是第一次使用,请看演示GIF