// ==UserScript== // @name yudao_doc_unlock // @namespace https://doc.iocoder.cn/ // @version 2.1.0 // @description 恢复受支持页面的完整正文显示 // @author mensorigos // @match *://doc.iocoder.cn/* // @match *://www.iocoder.cn/* // @grant none // @run-at document-start // @license MIT // ==/UserScript== (function () { 'use strict'; /* 仅调整本地呈现:不修改正文,不读写站点凭证,不发起额外请求 */ var PAGE_STATES = ['pending', 'guest', 'error']; var LAYER_TAGS = ['doc-access-layer', 'doc-access-pending', 'doc-access-status']; var LAYER_SELECTOR = LAYER_TAGS.join(',') + ',#locker'; var STYLE_ID = 'yd-style'; var STYLE_TEXT = [ 'html[data-doc-access] body .content-wrapper,', 'html[data-doc-access] body .content-wrapper .theme-vdoing-content,', 'html[data-doc-access] body .content-wrapper .content__default {', ' visibility: visible !important;', '}', 'doc-access-layer, doc-access-pending, doc-access-status,', '#doc-access-error { display: none !important; }', '#locker { display: none !important; }', 'article.lock { overflow: visible !important; }', '#post-body { height: auto !important; max-height: none !important; }' ].join('\n'); function applyStyle() { var host = document.head || document.documentElement; if (!host) return; var old = document.getElementById(STYLE_ID); if (old && old.parentNode === host) return; if (old && old.parentNode) old.parentNode.removeChild(old); var style = document.createElement('style'); style.id = STYLE_ID; style.textContent = STYLE_TEXT; host.appendChild(style); } function syncState() { var root = document.documentElement; if (!root) return; var state = root.getAttribute('data-doc-access'); if (state && PAGE_STATES.indexOf(state) !== -1) { root.setAttribute('data-doc-access', 'public'); } } function isLayer(node) { return !!node && node.nodeType === 1 && typeof node.tagName === 'string' && LAYER_TAGS.indexOf(node.tagName.toLowerCase()) !== -1; } function dropLocker() { var node = document.getElementById('locker'); if (node && node.parentNode) node.parentNode.removeChild(node); } function restoreScroll() { if (document.body && document.body.style.overflow === 'hidden') { document.body.style.overflow = ''; } } function dropLayer(node) { if (node && node.parentNode) node.parentNode.removeChild(node); restoreScroll(); } var rawAppendChild = Node.prototype.appendChild; Node.prototype.appendChild = function (node) { if (isLayer(node)) { setTimeout(restoreScroll, 0); return node; } return rawAppendChild.call(this, node); }; var rawInsertBefore = Node.prototype.insertBefore; Node.prototype.insertBefore = function (node, ref) { if (isLayer(node)) { setTimeout(restoreScroll, 0); return node; } return rawInsertBefore.call(this, node, ref); }; function sweep() { var root = document.body || document.documentElement; if (!root || !root.querySelectorAll) return; var list = root.querySelectorAll(LAYER_SELECTOR); for (var i = list.length - 1; i >= 0; i--) dropLayer(list[i]); } function boot() { applyStyle(); syncState(); dropLocker(); sweep(); } if (document.documentElement) { new MutationObserver(function (records) { applyStyle(); for (var i = 0; i < records.length; i++) { var r = records[i]; if (r.type === 'attributes') { syncState(); continue; } for (var j = 0; j < r.addedNodes.length; j++) { if (isLayer(r.addedNodes[j])) dropLayer(r.addedNodes[j]); } } }).observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['data-doc-access'] }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot, { once: true }); } else { boot(); } window.addEventListener('load', function () { setTimeout(boot, 300); }); })();