Greasy Fork is available in English.
1. 去掉 disabled-copy 类及水印遮挡;2. 自动点击“展开”按钮保持全文展开
当前为
// ==UserScript==
// @name 知识星球·解除复制限制+帖子自动展开
// @namespace https://axutongxue.com/
// @version 1.0
// @license MIT
// @description 1. 去掉 disabled-copy 类及水印遮挡;2. 自动点击“展开”按钮保持全文展开
// @author kejin & showerMuggle & 无与伦比
// @match *://wx.zsxq.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
/* ************** 通用工具 ************** */
function waitForKeyElements(selectorOrFunction, callback, waitOnce = true, interval = 300, maxIntervals = -1) {
const select = () => (typeof selectorOrFunction === 'function' ? selectorOrFunction() : document.querySelectorAll(selectorOrFunction));
const tick = () => {
const nodes = select();
if (nodes.length) {
nodes.forEach(n => {
if (n.dataset.alreadyFound) return;
const cancel = callback(n);
if (!cancel) n.dataset.alreadyFound = '1';
});
}
if (--maxIntervals !== 0 && !(waitOnce && nodes.length)) {
setTimeout(tick, interval);
}
};
tick();
}
/* ************** 1. 解除复制限制 ************** */
waitForKeyElements('.disabled-copy', el => el.classList.remove('disabled-copy'), false, 1000);
waitForKeyElements('[watermark]', el => el.setAttribute('style', 'padding:10px;'), false, 1000);
/* ************** 2. 帖子自动展开 ************** */
const processed = new WeakSet();
function smartClick(btn) {
if (!btn || processed.has(btn)) return;
const txt = btn.textContent.trim();
if (!/展[开示]/.test(txt)) return;
btn.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
processed.add(btn);
}
function expandAll() {
document.querySelectorAll('p.showAll, button.showAll, span.showAll').forEach(smartClick);
}
// 首次+动态
window.addEventListener('load', () => {
expandAll();
new MutationObserver(() => expandAll()).observe(document.body, { childList: true, subtree: true });
window.addEventListener('hashchange', expandAll);
});
})();