// ==UserScript== // @name X岛-EX // @namespace http://tampermonkey.net/ // @version 1.2.3 // @description X岛揭示板增强 快捷切饼/顶部添加页码/默认关闭图片水印 // @author XY // @match https://www.nmbxd1.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM_deleteValue // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js // @license WTFPL // @note 致谢:切饼代码来自[XD-Enhance](https://greasyfork.org/zh-CN/scripts/438164-xd-enhance) // @note 联动:可使[增强x岛匿名版](https://greasyfork.org/zh-CN/scripts/513156-%E5%A2%9E%E5%BC%BAx%E5%B2%9B%E5%8C%BF%E5%90%8D%E7%89%88)添加的预览中显示当前饼名(如ID:cOoKiEs),而非ID:cookies // @downloadURL none // ==/UserScript== (function($) { 'use strict'; // -------------------- COOKIE 功能(切换饼干、复制翻页、关闭水印) -------------------- function toast(msg) { let toastDiv = $('#ae-toast-inline'); if (!toastDiv.length) { toastDiv = $('
'); $('body').append(toastDiv); } toastDiv.text(msg).fadeIn(300).delay(2000).fadeOut(300); } function getCookiesList() { return GM_getValue('cookies', {}); } function getCurrentCookie() { return GM_getValue('now-cookie', null); } // 辅助函数:去掉 cookie.name 末尾 " - 0000-00-00 00:00:00" 部分 function abbreviateName(name) { return name.replace(/\s*-\s*\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/, ""); } function removeDateString() { $("#cookie-switcher-ui").find("*").addBack().contents().filter(function() { return this.nodeType === 3; }).each(function() { this.nodeValue = this.nodeValue.replace(/ - 0000-00-00 00:00:00/g, ''); }); } // 更新页面中用于显示当前饼干的区域 function updateCurrentCookieDisplay(currentCookie) { const cookieDisplay = $('#current-cookie-display'); if (cookieDisplay.length) { if (currentCookie) { const displayName = abbreviateName(currentCookie.name); const extra = currentCookie.desc ? (' - ' + currentCookie.desc) : ''; cookieDisplay.text(displayName + extra).css('color', 'black'); } else { cookieDisplay.text('已删除').css('color', 'red'); } } removeDateString(); } // 更新下拉菜单中的选项和默认选中 function updateDropdownUI(cookies) { const dropdown = $('#cookie-dropdown'); dropdown.empty(); //dropdown.append(''); for (let id in cookies) { if (cookies.hasOwnProperty(id)) { const cookie = cookies[id]; const displayName = abbreviateName(cookie.name); const optionText = displayName + (cookie.desc ? (' - ' + cookie.desc) : ''); dropdown.append(``); } } let currentCookie = getCurrentCookie(); if (currentCookie && cookies.hasOwnProperty(currentCookie.id)) { dropdown.val(currentCookie.id); } else { dropdown.val(""); } removeDateString(); } // 切换饼干(切换后更新预览区域中的饼干显示) function switch_cookie(cookie) { if (!cookie || !cookie.id) { toast('无效的饼干信息!'); return; } const url = 'https://www.nmbxd1.com/Member/User/Cookie/switchTo/id/' + cookie.id + '.html'; $.ajax({ type: 'GET', url: url, success: function() { toast('切换成功! 当前饼干为 ' + abbreviateName(cookie.name)); GM_setValue('now-cookie', cookie); updateCurrentCookieDisplay(cookie); updateDropdownUI(getCookiesList()); removeDateString(); updatePreviewCookieId(); // 新增:更新预览区中当前饼干显示 }, error: function() { toast('切换失败,请重试'); } }); } // 刷新饼干列表(解析页面后更新) function refreshCookies() { GM_xmlhttpRequest({ method: 'GET', url: 'https://www.nmbxd1.com/Member/User/Cookie/index.html', onload: function(response) { if (response.status === 200) { let parser = new DOMParser(); let doc = parser.parseFromString(response.responseText, "text/html"); let rows = doc.querySelectorAll('tbody > tr'); let newCookies = {}; rows.forEach(function(row) { let tds = row.querySelectorAll('td'); if (tds.length >= 4) { let id = tds[1].textContent.trim(); let nameLink = tds[2].querySelector('a'); let nameOriginal = nameLink ? nameLink.textContent.trim() : ''; let desc = tds[3].textContent.trim(); newCookies[id] = { id: id, name: nameOriginal, desc: desc }; } }); GM_setValue('cookies', newCookies); updateDropdownUI(newCookies); toast('饼干列表已刷新!'); let currentCookie = getCurrentCookie(); if (currentCookie && !newCookies[currentCookie.id]) { currentCookie = null; } GM_setValue('now-cookie', currentCookie); updateCurrentCookieDisplay(currentCookie); removeDateString(); updatePreviewCookieId(); } else { toast('刷新失败,HTTP状态码:' + response.status); } }, onerror: function() { toast('刷新失败,网络错误。'); } }); } // 构造并插入 Cookie 切换 UI——使用页面原有的 uk-grid 布局,确保按钮固定排列向右 function createCookieSwitcherUI() { const postFormTitle = $('.h-post-form-title:contains("回应模式")').first(); let postFormGrid = null; if (postFormTitle.length) { postFormGrid = postFormTitle.closest('.uk-grid.uk-grid-small.h-post-form-grid'); } if (!postFormGrid || !postFormGrid.length) { return; } const currentCookie = getCurrentCookie(); const cookiesList = getCookiesList(); const switcherUI = $(`