您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
【原DeepFlood增强】自动签到、无缝翻页帖子评论、快捷回复、代码高亮、屏蔽用户、屏蔽帖子、楼主低等级提醒
当前为
// ==UserScript== // @name DeepFlood X // @namespace http://www.deepflood.com/ // @version 0.4.1 // @description 【原DeepFlood增强】自动签到、无缝翻页帖子评论、快捷回复、代码高亮、屏蔽用户、屏蔽帖子、楼主低等级提醒 // @author dabao // @match *://*.deepflood.com/* // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACz0lEQVR4Ae3B32tVdQAA8M85u7aVHObmzJVD0+ssiphstLEM62CBlCBEIAYhUoGGD/kiRUo+9CIEElFZgZJFSApBVhCUX2WFrVQKf5Qy26SgdK4pN7eZu+cbtyfJ/gLx83HD9SAhlEyXupiPhUSTeonRfNw1ws2aRJeN5jHcolFhJJ9M8Zj99piDTnv12SjzfzIb9dmrC7Pttt8ykjDVLsu8ZZ1GH1oqeDofJLtJh4fMEw3Y72jlCuEO2+W+sNJFr3vOZ1YIi8NIGA29hDWhGgZDJ2Rt2ZvZSBazmMUsZsPZ1qwVQmcYDNWwhtAbRsNIWJx6WLPDfgxNVkm9nR8hm+XduLba7F9RtcXztmUzyY/YJrUqNPvBYc0eSS3CwXxMl4WG7CarsyEuvU2HOkRNujSw3PosxR6DFurKxx3E/akFohPo0aDfEO61os5LdrtLVWG1TzxokifdiSH9GnTjuGhBqsWE39GOo3kVi8wsmeVW00SJ200zA9r0kFcdQzv+MKElVW/S+L5EE86pmUth3BV/SzCOCUjMVXMWzfsSYybVl1SlSlESkagpuOI1nzshFX1gyAF1UKhJEKOkJFVNXVBv+pJoBK1qBkh86z1/SaR+9o5zEgoDaloxsiSart6F1Bkl83ESHWEKvvEbqZJETaokgSH9hCk6cBLtSs6kDqEb/cZ0K+MnO0X/VdhRGUBZjzH9uA+HUl+a0BvmO+J7bVZSKWz1kehqhfe9oWalNoccDmW9JnyV+toxsy3PK3aY9Gx4gMp567ziV4WawpCXra+MEhZ5xqTtecVycxzXlxA22OK4ZYbt9LjvrM5PkNUp6zVPdNpBv1QKwt126Paxp8zwqXu8kG8pYZdHlT2Rvxo2aVG2ObyYn65UnXLKVULZZrP02ZRfCms1OmAXCSHRYqrLzuZFaDFV6s/8omuERs0Kl/LzITVTvTHDeXTD9eAftAsSYhXYOWUAAAAASUVORK5CYII= // @require https://s4.zstatic.net/ajax/libs/layui/2.9.9/layui.min.js // @resource highlightStyle https://s4.zstatic.net/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css // @resource highlightStyle_dark https://s4.zstatic.net/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_notification // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_getResourceURL // @grant GM_addElement // @grant GM_addStyle // @grant GM_openInTab // @grant unsafeWindow // @run-at document-end // @license GPL-3.0 License // @supportURL https://www.deepflood.com/ // @homepageURL https://www.deepflood.com/ // ==/UserScript== (function () { 'use strict'; const { version, author, name, icon } = GM_info.script; // 适配新站点 const BASE_URL = "https://www.deepflood.com"; const util = { clog:(c) => { console.group(`%c %c [${name}]-v${version} by ${author}`, `background:url(${icon}) center/12px no-repeat;padding:3px`, ""); console.log(c); console.groupEnd(); }, getValue: (name, defaultValue) => GM_getValue(name, defaultValue), setValue: (name, value) => GM_setValue(name, value), sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)), addStyle(id, tag, css) { tag = tag || 'style'; let doc = document, styleDom = doc.head.querySelector(`#${id}`); if (styleDom) return; let style = doc.createElement(tag); style.rel = 'stylesheet'; style.id = id; tag === 'style' ? style.innerHTML = css : style.href = css; doc.head.appendChild(style); }, removeStyle(id,tag){ tag = tag || 'style'; let doc = document, styleDom = doc.head.querySelector(`#${id}`); if (styleDom) { doc.head.removeChild(styleDom) }; }, getAttrsByPrefix(element, prefix) { return Array.from(element.attributes).reduce((acc, { name, value }) => { if (name.startsWith(prefix)) acc[name] = value; return acc; }, {}); }, data(element, key, value) { if (arguments.length < 2) return undefined; if (value !== undefined) element.dataset[key] = value; return element.dataset[key]; }, async post(url, data, headers, responseType = 'json') { return this.fetchData(url, 'POST', data, headers, responseType); }, async get(url, headers, responseType = 'json') { return this.fetchData(url, 'GET', null, headers, responseType); }, async fetchData(url, method='GET', data=null, headers={}, responseType='json') { const options = { method, headers: { 'Content-Type':'application/json',...headers}, body: data ? JSON.stringify(data) : undefined }; const response = await fetch(url.startsWith("http") ? url : BASE_URL + url, options); const result = await response[responseType]().catch(() => null); return response.ok ? result : Promise.reject(result); }, getCurrentDate() { const localTimezoneOffset = (new Date()).getTimezoneOffset(); const beijingOffset = 8 * 60; const beijingTime = new Date(Date.now() + (localTimezoneOffset + beijingOffset) * 60 * 1000); const timeNow = `${beijingTime.getFullYear()}/${(beijingTime.getMonth() + 1)}/${beijingTime.getDate()}`; return timeNow; }, createElement(tagName, options = {}, childrens = [], doc = document, namespace = null) { if (Array.isArray(options)) { if (childrens.length !== 0) { throw new Error("If options is an array, childrens should not be provided."); } childrens = options; options = {}; } const { staticClass = '', dynamicClass = '', attrs = {}, on = {} } = options; const ele = namespace ? doc.createElementNS(namespace, tagName) : doc.createElement(tagName); if (staticClass) { staticClass.split(' ').forEach(cls => ele.classList.add(cls.trim())); } if (dynamicClass) { dynamicClass.split(' ').forEach(cls => ele.classList.add(cls.trim())); } Object.entries(attrs).forEach(([key, value]) => { if (key === 'style' && typeof value === 'object') { Object.entries(value).forEach(([styleKey, styleValue]) => { ele.style[styleKey] = styleValue; }); } else { if (value !== undefined) ele.setAttribute(key, value); } }); Object.entries(on).forEach(([event, handler]) => { ele.addEventListener(event, handler); }); childrens.forEach(child => { if (typeof child === 'string') { child = doc.createTextNode(child); } ele.appendChild(child); }); return ele; }, b64DecodeUnicode(str) { return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } }; const opts = { post: { pathPattern: /^\/(categories\/|page|award|search|$)/, scrollThreshold: 1500, nextPagerSelector: '.nsk-pager a.pager-next', postListSelector: 'ul.post-list:not(.topic-carousel-panel)', topPagerSelector: 'div.nsk-pager.pager-top', bottomPagerSelector: 'div.nsk-pager.pager-bottom', }, comment: { pathPattern: /^\/post-/, scrollThreshold: 690, nextPagerSelector: '.nsk-pager a.pager-next', postListSelector: 'ul.comments', topPagerSelector: 'div.nsk-pager.post-top-pager', bottomPagerSelector: 'div.nsk-pager.post-bottom-pager', }, setting: { SETTING_SIGN_IN_STATUS: 'setting_sign_in_status', SETTING_SIGN_IN_LAST_DATE: 'setting_sign_in_last_date', SETTING_SIGN_IN_IGNORE_DATE: 'setting_sign_in_ignore_date', SETTING_AUTO_LOADING_STATUS: 'setting_auto_loading_status' }, settings:{ "version": version, "sign_in": { "enabled": true, "method": 0, "last_date": "", "ignore_date": "" }, "signin_tips": { "enabled": true }, "re_signin": { "enabled": true }, "auto_jump_external_links": { "enabled": true }, "loading_post": { "enabled": true }, "loading_comment": { "enabled": true }, "quick_comment": { "enabled": true }, "open_post_in_new_tab": { "enabled": false }, "block_members": { "enabled": true }, "block_posts": { "enabled": true,"keywords":[] }, "level_tag": { "enabled": true, "low_lv_alarm":false, "low_lv_max_days":30 }, "code_highlight": { "enabled": true }, "image_slide":{ "enabled":true }, "visited_links":{ "enabled": true, "link_color":"","visited_color":"","dark_link_color":"","dark_visited_color":"" }, "user_card_ext": { "enabled":true } } }; layui.use(function () { const layer = layui.layer; const dropdown = layui.dropdown; const message = { info: (text) => message.__msg(text, { "background-color": "#4D82D6" }), success: (text) => message.__msg(text, { "background-color": "#57BF57" }), warning: (text) => message.__msg(text, { "background-color": "#D6A14D" }), error: (text) => message.__msg(text, { "background-color": "#E1715B" }), __msg: (text, style) => { let index = layer.msg(text, { offset: 't', area: ['100%', 'auto'], anim: 'slideDown' }); layer.style(index, Object.assign({ opacity: 0.9 }, style)); } }; const Config = { // 初始化配置数据 initValue() { const value = [ { name: opts.setting.SETTING_SIGN_IN_STATUS, defaultValue: 0 }, { name: opts.setting.SETTING_SIGN_IN_LAST_DATE, defaultValue: '1753/1/1' }, { name: opts.setting.SETTING_SIGN_IN_IGNORE_DATE, defaultValue: '1753/1/1' }, { name: opts.setting.SETTING_AUTO_LOADING_STATUS, defaultValue: 1 }, { name: 'open_post_in_new_tab', defaultValue: 0 }, { name: 'feedback', defaultValue: 0 } ]; this.upgradeConfig(); value.forEach((v) => util.getValue(v.name) === undefined && util.setValue(v.name, v.defaultValue)); }, // 升级配置项 upgradeConfig() { const upgradeConfItem = (oldConfKey, newConfKey) => { if (util.getValue(oldConfKey) && util.getValue(newConfKey) === undefined) { util.clog(`升级配置项 ${oldConfKey} 为 ${newConfKey}`); util.setValue(newConfKey, util.getValue(oldConfKey)); GM_deleteValue(oldConfKey); } }; upgradeConfItem('menu_signInTime', opts.setting.SETTING_SIGN_IN_LAST_DATE); }, initializeConfig() { const defaultConfig = opts.settings; if (!util.getValue('settings')) { util.setValue('settings', defaultConfig); return; } if(this.getConfig('version')===version) return; let storedConfig = util.getValue('settings'); const cleanDefaults = (stored, defaults) => { Object.keys(stored).forEach(key => { if (defaults[key] === undefined) { delete stored[key]; } else if (typeof stored[key] === 'object' && stored[key] !== null && !(stored[key] instanceof Array)) { cleanDefaults(stored[key], defaults[key]); } }); }; const mergeDefaults = (stored, defaults) => { Object.keys(defaults).forEach(key => { if (typeof defaults[key] === 'object' && defaults[key] !== null && !(defaults[key] instanceof Array)) { if (!stored[key]) stored[key] = {}; mergeDefaults(stored[key], defaults[key]); } else { if (stored[key] === undefined) { stored[key] = defaults[key]; } } }); }; mergeDefaults(storedConfig, defaultConfig); cleanDefaults(storedConfig, defaultConfig); storedConfig.version = version; util.setValue('settings',storedConfig); },updateConfig(path, value) { let config = util.getValue('settings'); let keys = path.split('.'); let lastKey = keys.pop(); let lastObj = keys.reduce((obj, key) => obj[key], config); lastObj[lastKey] = value; util.setValue('settings', config); },getConfig(path) { let config = GM_getValue('settings'); let keys = path.split('.'); return keys.reduce((obj, key) => obj[key], config); } }; const FeatureFlags={ isEnabled(featureName) { if (Config.getConfig(featureName)) { return Config.getConfig(`${featureName}.enabled`); } else { console.error(`Feature '${featureName}' does not exist.`); return false; } } }; const main = { loginStatus: false, //检查是否登陆 checkLogin() { if (unsafeWindow.__config__ && unsafeWindow.__config__.user) { this.loginStatus = true; util.clog(`当前登录用户 ${unsafeWindow.__config__.user.member_name} (ID ${unsafeWindow.__config__.user.member_id})`); } }, // 自动签到 autoSignIn(rand) { if(!FeatureFlags.isEnabled('sign_in')) return; if (!this.loginStatus) return if (util.getValue(opts.setting.SETTING_SIGN_IN_STATUS) === 0) return; rand = rand || (util.getValue(opts.setting.SETTING_SIGN_IN_STATUS) === 1); let timeNow = util.getCurrentDate(), timeOld = util.getValue(opts.setting.SETTING_SIGN_IN_LAST_DATE); if (!timeOld || timeOld != timeNow) { util.setValue(opts.setting.SETTING_SIGN_IN_LAST_DATE, timeNow); this.signInRequest(rand); } }, // 重新签到 reSignIn() { if (!this.loginStatus) return; if (util.getValue(opts.setting.SETTING_SIGN_IN_STATUS) === 0) { unsafeWindow.mscAlert('提示', this.getMenuStateText(this._menus[0], 0) + ' 状态时不支持重新签到!'); return; } util.setValue(opts.setting.SETTING_SIGN_IN_LAST_DATE, '1753/1/1'); location.reload(); }, addSignTips() { if(!FeatureFlags.isEnabled('signin_tips')) return; if (!this.loginStatus) return if (util.getValue(opts.setting.SETTING_SIGN_IN_STATUS) !== 0) return; const timeNow = util.getCurrentDate(); const { SETTING_SIGN_IN_IGNORE_DATE, SETTING_SIGN_IN_LAST_DATE } = opts.setting; const timeIgnore = util.getValue(SETTING_SIGN_IN_IGNORE_DATE); const timeOld = util.getValue(SETTING_SIGN_IN_LAST_DATE); if (timeNow === timeIgnore || timeNow === timeOld) return; const _this = this; let tip = util.createElement("div", { staticClass: 'nsplus-tip' }); let tip_p = util.createElement('p'); tip_p.innerHTML = '今天你还没有签到哦! 【<a class="sign_in_btn" data-rand="true" href="javascript:;">随机抽个鸡腿</a>】 【<a class="sign_in_btn" data-rand="false" href="javascript:;">只要5个鸡腿</a>】 【<a id="sign_in_ignore" href="javascript:;">今天不再提示</a>】'; tip.appendChild(tip_p); tip.querySelectorAll('.sign_in_btn').forEach(function (item) { item.addEventListener("click", function (e) { const rand = util.data(this, 'rand'); _this.signInRequest(rand); tip.remove(); util.setValue(SETTING_SIGN_IN_LAST_DATE, timeNow); }) }); tip.querySelector('#sign_in_ignore').addEventListener("click", function (e) { tip.remove(); util.setValue(SETTING_SIGN_IN_IGNORE_DATE, timeNow); }); document.querySelector('header').append(tip); }, async signInRequest(rand) { await util.post('/api/attendance?random=' + (rand || false), {}, { "Content-Type": "application/json" }).then(json => { if (json.success) { message.success(`签到成功!今天午饭+${json.gain}个鸡腿; 积攒了${json.current}个鸡腿了`); } else { message.info(json.message); } }).catch(error => { message.info(error.message || "发生未知错误"); util.clog(error); }); util.clog(`[${name}] 签到完成`); }, is_show_quick_comment: false, quickComment() { if (!this.loginStatus || !opts.comment.pathPattern.test(location.pathname)) return; if (util.getValue(opts.setting.SETTING_AUTO_LOADING_STATUS) === 0) return; const _this = this; const onClick = (e) => { if (_this.is_show_quick_comment) { return; } e.preventDefault(); const mdEditor = document.querySelector('.md-editor'); const clientHeight = document.documentElement.clientHeight, clientWidth = document.documentElement.clientWidth; const mdHeight = mdEditor.clientHeight, mdWidth = mdEditor.clientWidth; const top = (clientHeight / 2) - (mdHeight / 2), left = (clientWidth / 2) - (mdWidth / 2); mdEditor.style.cssText = `position: fixed; top: ${top}px; left: ${left}px; margin: 30px 0px; width: 100%; max-width: ${mdWidth}px; z-index: 999;`; const moveEl = mdEditor.querySelector('.tab-select.window_header'); moveEl.style.cursor = "move"; moveEl.addEventListener('mousedown', startDrag); addEditorCloseButton(); _this.is_show_quick_comment = true; }; const commentDiv = document.querySelector('#fast-nav-button-group #back-to-parent').cloneNode(true); commentDiv.id = 'back-to-comment'; commentDiv.innerHTML = '<svg class="iconpark-icon" style="width: 24px; height: 24px;"><use href="#comments"></use></svg>'; commentDiv.addEventListener("click", onClick); document.querySelector('#back-to-parent').before(commentDiv); document.querySelectorAll('.nsk-post .comment-menu,.comment-container .comments').forEach(x=>x.addEventListener("click",(event) =>{ if(!["引用", "回复", "编辑"].includes(event.target.textContent)) return; onClick(event);},true)); function addEditorCloseButton() { const fullScreenToolbar = document.querySelector('#editor-body .window_header > :last-child'); const cloneToolbar = fullScreenToolbar.cloneNode(true); cloneToolbar.setAttribute('title', '关闭'); cloneToolbar.querySelector('span').classList.replace('i-icon-full-screen-one', 'i-icon-close'); cloneToolbar.querySelector('span').innerHTML = '<svg width="16" height="16" viewBox="0 0 48 48" fill="none"><path d="M8 8L40 40" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path><path d="M8 40L40 8" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path></svg>'; cloneToolbar.addEventListener("click", function (e) { const mdEditor = document.querySelector('.md-editor'); mdEditor.style = ""; const moveEl = mdEditor.querySelector('.tab-select.window_header'); moveEl.style.cursor = ""; moveEl.removeEventListener('mousedown', startDrag); this.remove(); _this.is_show_quick_comment = false; }); fullScreenToolbar.after(cloneToolbar); } function startDrag(event) { if (event.button !== 0) return; const draggableElement = document.querySelector('.md-editor'); const parentMarginTop = parseInt(window.getComputedStyle(draggableElement).marginTop); const initialX = event.clientX - draggableElement.offsetLeft; const initialY = event.clientY - draggableElement.offsetTop + parentMarginTop; document.onmousemove = function (event) { const newX = event.clientX - initialX; const newY = event.clientY - initialY; draggableElement.style.left = newX + 'px'; draggableElement.style.top = newY + 'px'; }; document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; }; } } } main.init(); }); })();