// ==UserScript== // @name 得到网页版单栏居中限宽显示 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 通过得到网页版阅读书籍时,单栏模式默认铺满全屏,跨度较大,使用该脚本可以使文字居中显示,且宽度显示为1200. // @author You // @match https://www.dedao.cn/* /* 匹配所有网站,或者你可以指定具体的网站 */ // @match https://*.dedao.cn/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; const LOCKED_VIEWPORT_WIDTH = 1200; function lockViewportWidth() { const htmlElement = document.documentElement; ['width', 'min-width', 'max-width'].forEach(prop => { htmlElement.style.setProperty(prop, `${LOCKED_VIEWPORT_WIDTH}px`, 'important'); }); htmlElement.style.setProperty('margin', '0 auto', 'important'); htmlElement.style.setProperty('overflow-x', 'auto', 'important'); } // 双保险事件监听 document.addEventListener('DOMContentLoaded', lockViewportWidth); window.addEventListener('load', lockViewportWidth); window.addEventListener('resize', lockViewportWidth); // 动态内容适配 new MutationObserver(lockViewportWidth).observe(document.body, { childList: true, subtree: true }); })();