From fa5ad535dac6ecaeb071b7b2a76a7e30329aa8c0 Mon Sep 17 00:00:00 2001 From: YuanHui <31339626+alsesa@users.noreply.github.com> Date: Thu, 18 Dec 2025 12:23:54 +0800 Subject: [PATCH] add weread inject js --- src-tauri/src/inject/custom.js | 43 ++++++++++++++++++++++++++++++++++ src-tauri/src/inject/style.js | 16 +++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src-tauri/src/inject/custom.js b/src-tauri/src/inject/custom.js index e69de29..e930dc9 100644 --- a/src-tauri/src/inject/custom.js +++ b/src-tauri/src/inject/custom.js @@ -0,0 +1,43 @@ +// --- 1. 屏蔽无限 debugger (防止控制台卡死) --- +(function() { + var _constructor = window.Function.prototype.constructor; + window.Function.prototype.constructor = function(str) { + if (str === 'debugger') return function() {}; + return _constructor.apply(this, arguments); + }; +})(); + +// --- 2. 解除右键拦截 --- +window.addEventListener('contextmenu', (e) => e.stopPropagation(), true); + +// --- 3. 自动隐藏/显示顶栏和侧边栏 (原生 JS 实现) --- +(function() { + let windowTop = 0; + + // 等待页面加载完成后再执行逻辑 + window.addEventListener('load', () => { + window.addEventListener('scroll', () => { + const scrollS = window.scrollY || document.documentElement.scrollTop; + const topBar = document.querySelector('.readerTopBar'); + const controls = document.querySelector('.readerControls'); + + if (!topBar || !controls) return; // 如果还没加载出这些元素则跳过 + + if (scrollS >= windowTop + 100) { + // 下滑隐藏:设置透明度和位移(比 fadeIn/Out 性能更好) + topBar.style.opacity = '0'; + topBar.style.transition = 'opacity 0.3s ease'; + controls.style.opacity = '0'; + controls.style.transition = 'opacity 0.3s ease'; + windowTop = scrollS; + } + else if (scrollS < windowTop) { + // 上划显示 + topBar.style.opacity = '1'; + controls.style.opacity = '1'; + windowTop = scrollS; + } + }); + }); + console.log("微信读书增强脚本:隐藏顶栏/侧边栏功能已就绪"); +})(); \ No newline at end of file diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.js index a3599b7..8d0868e 100644 --- a/src-tauri/src/inject/style.js +++ b/src-tauri/src/inject/style.js @@ -1,5 +1,21 @@ window.addEventListener("DOMContentLoaded", (_event) => { // Customize and transform existing functions + const wereadCSS = ` + .readerContent .app_content, .readerTopBar { + max-width: 100% !important; + } + .readerControls { + align-items: flex-end !important; + margin-left: 45.5% !important; + } + .readerBottomBar_content { + display: none !important; + } + `; + const wereadStyleElement = document.createElement("style"); + wereadStyleElement.innerHTML = wereadCSS; + document.head.appendChild(wereadStyleElement); + const contentCSS = ` #page #footer-wrapper, .drawing-board .toolbar .toolbar-action,