From 4eeed976cab6d6d5c98d611f0c3b03a79b0c3623 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Thu, 8 Jul 2021 22:09:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Beautification.user.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Zhihu-Beautification.user.js b/Zhihu-Beautification.user.js index 2c87cf8..f044538 100644 --- a/Zhihu-Beautification.user.js +++ b/Zhihu-Beautification.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 知乎美化 -// @version 1.2.4 +// @version 1.2.5 // @author X.I.U // @description 宽屏显示、暗黑模式(4种)、隐藏文章开头大图、调整图片最大高度、向下翻时自动隐藏顶栏、文章编辑页面与实际文章宽度一致、屏蔽登录提示 // @match *://www.zhihu.com/* @@ -281,13 +281,13 @@ html {filter: brightness(75%) sepia(30%) !important; background-image: url();} if (menu_value('menu_darkModeType') === 1) { if (getTheme() === 'light') { document.cookie="theme=dark; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/"; - document.getElementsByTagName('html')[0].setAttribute('data-theme', 'dark'); + document.lastChild.setAttribute('data-theme', 'dark'); location.reload(); // 刷新网页 } } else { if (getTheme() === 'dark') { document.cookie="theme=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; - document.getElementsByTagName('html')[0].setAttribute('data-theme', 'light'); + document.lastChild.setAttribute('data-theme', 'light'); location.reload(); // 刷新网页 } if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { @@ -313,7 +313,7 @@ html {filter: brightness(75%) sepia(30%) !important; background-image: url();} } else { if (getTheme() === 'dark'){ document.cookie="theme=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; - document.getElementsByTagName('html')[0].setAttribute('data-theme', 'light'); + document.lastChild.setAttribute('data-theme', 'light'); location.reload(); // 刷新网页 } } @@ -345,7 +345,7 @@ html {filter: brightness(75%) sepia(30%) !important; background-image: url();} } } - style_Add.innerHTML = style; + /*style_Add.innerHTML = style; if (document.head) { document.head.appendChild(style_Add); } else { @@ -355,6 +355,17 @@ html {filter: brightness(75%) sepia(30%) !important; background-image: url();} clearInterval(timer); } }, 1); + }*/ + + if (document.lastChild) { + document.lastChild.appendChild(style_Add).textContent = style; + } else { // 避免网站加载速度太慢的备用措施 + let timer1 = setInterval(function(){ // 每 5 毫秒检查一下 html 是否已存在 + if (document.lastChild) { + clearInterval(timer1); // 取消定时器 + document.lastChild.appendChild(style_Add).textContent = style; + } + }, 5); } } function getTheme() {