mirror of
https://github.com/XIU2/UserScript.git
synced 2026-07-24 11:03:23 +00:00
优化 [暗黑模式] 开启关闭逻辑
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// ==UserScript==
|
||||
// @name 知乎美化
|
||||
// @version 1.1.17
|
||||
// @version 1.1.18
|
||||
// @author X.I.U
|
||||
// @description 宽屏显示、暗黑模式(4种)、隐藏文章开头大图、调整图片最大高度、向下翻时自动隐藏顶栏、文章编辑页面与实际文章宽度一致、屏蔽登录提示
|
||||
// @match *://www.zhihu.com/*
|
||||
@@ -66,7 +66,7 @@
|
||||
if (menu_status === 1) { // 设置 Cookie
|
||||
if (getTheme() === 'light') document.cookie="theme=dark; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/";
|
||||
} else {
|
||||
if (getTheme() === 'dark') document.cookie="theme=light; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/";
|
||||
if (getTheme() === 'dark') document.cookie="theme=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
|
||||
}
|
||||
if (menu_value('menu_darkMode')) {
|
||||
location.reload(); // 刷新网页
|
||||
@@ -82,7 +82,7 @@
|
||||
GM_setValue(`${Name}`, false);
|
||||
|
||||
if (Name === 'menu_darkMode') { // 暗黑模式
|
||||
if (getTheme() === 'dark') document.cookie="theme=light; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/";
|
||||
if (getTheme() === 'dark') document.cookie="theme=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
|
||||
location.reload(); // 刷新网页
|
||||
} else {
|
||||
GM_notification({text: `已关闭 [${Tips}] 功能\n(刷新网页后生效)`, timeout: 3500});
|
||||
@@ -94,7 +94,7 @@
|
||||
if (menu_value('menu_darkModeType') === 1) {
|
||||
if (getTheme() === 'light') document.cookie="theme=dark; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/";
|
||||
} else {
|
||||
if (getTheme() === 'dark') document.cookie="theme=light; expires=Thu, 18 Dec 2031 12:00:00 GMT; path=/";
|
||||
if (getTheme() === 'dark') document.cookie="theme=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
|
||||
}
|
||||
location.reload(); // 刷新网页
|
||||
} else {
|
||||
@@ -152,7 +152,7 @@ header.is-hidden {display: none;}
|
||||
style_5 = `/* 调整图片最大高度 */
|
||||
.ztext .content_image, .ztext .origin_image, .GifPlayer img {max-height: 500px;width: auto;}
|
||||
`,
|
||||
style_6 = `/* 暗黑模式(方案 1) */
|
||||
style_darkMode_1 = `/* 暗黑模式(方案 1) */
|
||||
/* 文字颜色 */
|
||||
html[data-theme=dark] body, html[data-theme=dark] .ContentItem-title, html[data-theme=dark] .QuestionHeader-title, html[data-theme=dark] .Tabs-link, html[data-theme=dark] .CreatorEntrance-title, html[data-theme=dark] .Search-container, html[data-theme=dark] .HotItem-excerpt, html[data-theme=dark] .PushNotifications-item, html[data-theme=dark] .Notifications-Main>header h1, html[data-theme=dark] .Notifications-Section-header h2, html[data-theme=dark] .NotificationList-Item-content, html[data-theme=dark] .Reward {color: #adbac7 !important;}
|
||||
/* 热榜标题 */
|
||||
@@ -164,7 +164,7 @@ html[data-theme=dark] .ContentItem-title a:hover, html[data-theme=dark] .RichCon
|
||||
/* 背景颜色 - 网页 */
|
||||
html[data-theme=dark] body {background: #22272E !important;}
|
||||
/* 背景颜色 - 问题 */
|
||||
html[data-theme=dark] .AppHeader, html[data-theme=dark] .QuestionHeader, html[data-theme=dark] .QuestionHeader-footer, html[data-theme=dark] .Input-wrapper.Input-wrapper--grey, html[data-theme=dark] .EmoticonsFooter-item--selected, html[data-theme=dark] .Card, html[data-theme=dark] .ContentItem-actions, html[data-theme=dark] .MoreAnswers .List-headerText, html[data-theme=dark] .CommentsV2-withPagination, html[data-theme=dark] .Topbar, html[data-theme=dark] .CommentsV2-footer, html[data-theme=dark] .CommentEditorV2-inputWrap--active, html[data-theme=dark] .InputLike, html[data-theme=dark] .Popover-content, html[data-theme=dark] .Notifications-footer, html[data-theme=dark] .Messages-footer, html[data-theme=dark] .Modal-inner, html[data-theme=dark] .Emoticons, html[data-theme=dark] .EmoticonsFooter, html[data-theme=dark] .SearchTabs, html[data-theme=dark] .Popover-arrow:after, html[data-theme=dark] .CommentEditorV2-inputWrap, html[data-theme=dark] .ProfileHeader-wrapper, html[data-theme=dark] .UserCover, html[data-theme=dark] .AnswerForm-footer, html[data-theme=dark] .Editable-toolbar, html[data-theme=dark] .AnswerForm-fullscreenContent .Editable-toolbar, html[data-theme=dark] .KfeCollection-PcCollegeCard-wrapper, html[data-theme=dark] .KfeCollection-PcCollegeCard-root, html[data-theme=dark] .HotItem, html[data-theme=dark] .HotList, html[data-theme=dark] .HotListNavEditPad, html[data-theme=dark] .QuestionWaiting-typesTopper, html[data-theme=dark] .QuestionWaiting-types, html[data-theme=dark] .PostItem, html[data-theme=dark] .ClubSideBar section, html[data-theme=dark] .SearchSubTabs, html[data-theme=dark] .Club-SearchPosts-Content, html[data-theme=dark] .Club-content, html[data-theme=dark] .ClubJoinOrCheckinButton, html[data-theme=dark] .ClubEdit, html[data-theme=dark] .CornerButton, html[data-theme=dark] .Notifications-Section-header, html[data-theme=dark] .NotificationList, .NotificationList-Item.NotificationList-Item:after, .NotificationList-DateSplit.NotificationList-DateSplit:after, html[data-theme=dark] .Chat, .ChatUserListItem:after, .ChatListGroup-SectionTitle--bottomBorder:after, html[data-theme=dark] .ActionMenu, .ChatSideBar-Search--active, html[data-theme=dark] .ChatSideBar-Search-ResultListWrap, html[data-theme=dark] .QuestionMainDivider-inner, html[data-theme=dark] .Topic-bar, html[data-theme=dark] .AnnotationTag {background: #2D333B !important;}
|
||||
html[data-theme=dark] .AppHeader, html[data-theme=dark] .QuestionHeader, html[data-theme=dark] .QuestionHeader-footer, html[data-theme=dark] .Input-wrapper.Input-wrapper--grey, html[data-theme=dark] .EmoticonsFooter-item--selected, html[data-theme=dark] .Card, html[data-theme=dark] .ContentItem-actions, html[data-theme=dark] .MoreAnswers .List-headerText, html[data-theme=dark] .CommentsV2-withPagination, html[data-theme=dark] .Topbar, html[data-theme=dark] .CommentsV2-footer, html[data-theme=dark] .CommentEditorV2-inputWrap--active, html[data-theme=dark] .InputLike, html[data-theme=dark] .Popover-content, html[data-theme=dark] .Notifications-footer, html[data-theme=dark] .Messages-footer, html[data-theme=dark] .Modal-inner, html[data-theme=dark] .Emoticons, html[data-theme=dark] .EmoticonsFooter, html[data-theme=dark] .SearchTabs, html[data-theme=dark] .Popover-arrow:after, html[data-theme=dark] .CommentEditorV2-inputWrap, html[data-theme=dark] .ProfileHeader-wrapper, html[data-theme=dark] .UserCover, html[data-theme=dark] .AnswerForm-footer, html[data-theme=dark] .Editable-toolbar, html[data-theme=dark] .AnswerForm-fullscreenContent .Editable-toolbar, html[data-theme=dark] .KfeCollection-PcCollegeCard-wrapper, html[data-theme=dark] .KfeCollection-PcCollegeCard-root, html[data-theme=dark] .HotItem, html[data-theme=dark] .HotList, html[data-theme=dark] .HotListNavEditPad, html[data-theme=dark] .QuestionWaiting-typesTopper, html[data-theme=dark] .QuestionWaiting-types, html[data-theme=dark] .PostItem, html[data-theme=dark] .ClubSideBar section, html[data-theme=dark] .SearchSubTabs, html[data-theme=dark] .Club-SearchPosts-Content, html[data-theme=dark] .Club-content, html[data-theme=dark] .ClubJoinOrCheckinButton, html[data-theme=dark] .ClubEdit, html[data-theme=dark] .CornerButton, html[data-theme=dark] .Notifications-Section-header, html[data-theme=dark] .NotificationList, .NotificationList-Item.NotificationList-Item:after, .NotificationList-DateSplit.NotificationList-DateSplit:after, html[data-theme=dark] .Chat, .ChatUserListItem:after, .ChatListGroup-SectionTitle--bottomBorder:after, html[data-theme=dark] .ActionMenu, .ChatSideBar-Search--active, html[data-theme=dark] .ChatSideBar-Search-ResultListWrap, html[data-theme=dark] .QuestionMainDivider-inner, html[data-theme=dark] .Topic-bar, html[data-theme=dark] .AnnotationTag, html[data-theme=dark] .HoverCard, html[data-theme=dark] .HoverCard-loading {background: #2D333B !important;}
|
||||
html[data-theme=dark] .CommentListV2-header-divider, html[data-theme=dark] .CommentsV2-openComment-divider, html[data-theme=dark] .AnswerForm-fullscreenScroller, html[data-theme=dark] .HotListNav-item {background-color: #222933 !important;}
|
||||
html[data-theme=dark] .CornerButton:hover {background: #3f4752 !important;} /* 右下角按钮 */
|
||||
|
||||
@@ -218,21 +218,61 @@ html[data-theme=dark] .ColumnPageHeader {background: #1c2129 !important;}
|
||||
.TopstoryTabs-link.is-active, html[data-theme=dark] .TopstoryTabs-link.is-active, html[data-theme=dark] .VoteButton, .Tag, html[data-theme=dark] .Tag, html[data-theme=dark] .HotListNav-item.is-active, html[data-theme=dark] .RichText a.UserLink-link {color: #3faaff !important;}
|
||||
/*html[data-theme=dark] .Tabs-link.is-active:after {background: #2196F3 !important;}*/
|
||||
html[data-theme=dark] .Reward-rewardBtn {color: #ffffff !important;}
|
||||
|
||||
/* 关闭查看回复时的高闪 */
|
||||
html[data-theme=dark] .CommentItemV2--highlighted {-webkit-animation: nano !important;animation: nano !important;}
|
||||
`,
|
||||
style_7 = `/* 暗黑模式(方案 2) */
|
||||
style_darkMode_2 = `/* 暗黑模式(方案 2) */
|
||||
html {filter: invert(80%) !important;}
|
||||
img, .ZVideoItem-video, .ZVideo-video {filter: invert(1) !important;}
|
||||
.GifPlayer img, .GifPlayer.isPlaying video {filter: invert(1) !important;}
|
||||
.GifPlayer.isPlaying img.ztext-gif.GifPlayer-gif2mp4Image {filter: none !important;}
|
||||
`,
|
||||
style_8 = `/* 暗黑模式(方案 3) */
|
||||
style_darkMode_3 = `/* 暗黑模式(方案 3) */
|
||||
html {filter: brightness(75%) !important;}
|
||||
`,
|
||||
style_9 = `/* 暗黑模式(方案 4) */
|
||||
style_darkMode_4 = `/* 暗黑模式(方案 4) */
|
||||
html {filter: brightness(75%) sepia(30%) !important;}
|
||||
`
|
||||
let style_Add = document.createElement('style');
|
||||
|
||||
// 暗黑模式
|
||||
if (menu_value('menu_darkMode')) {
|
||||
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');
|
||||
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');
|
||||
location.reload(); // 刷新网页
|
||||
}
|
||||
}
|
||||
switch(menu_value('menu_darkModeType')) {
|
||||
case 1:
|
||||
style += style_darkMode_1;
|
||||
break;
|
||||
case 2:
|
||||
style += style_darkMode_2;
|
||||
break;
|
||||
case 3:
|
||||
style += style_darkMode_3;
|
||||
break;
|
||||
case 4:
|
||||
style += style_darkMode_4;
|
||||
break;
|
||||
}
|
||||
} 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');
|
||||
location.reload(); // 刷新网页
|
||||
}
|
||||
}
|
||||
|
||||
// 宽屏显示
|
||||
if (menu_value('menu_widescreenDisplay')) {
|
||||
style += style_1;
|
||||
@@ -253,29 +293,6 @@ html {filter: brightness(75%) sepia(30%) !important;}
|
||||
style += style_4;
|
||||
}
|
||||
|
||||
// 暗黑模式
|
||||
if (menu_value('menu_darkMode')) {
|
||||
switch(menu_value('menu_darkModeType')) {
|
||||
case 1:
|
||||
style += style_6;
|
||||
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')
|
||||
location.reload(); // 刷新网页
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
style += style_7;
|
||||
break;
|
||||
case 3:
|
||||
style += style_8;
|
||||
break;
|
||||
case 4:
|
||||
style += style_9;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 文章编辑页面与实际文章宽度一致
|
||||
if(window.location.href.indexOf("zhuanlan") > -1){
|
||||
if(window.location.href.indexOf("/edit") > -1){
|
||||
@@ -284,14 +301,23 @@ html {filter: brightness(75%) sepia(30%) !important;}
|
||||
}
|
||||
|
||||
style_Add.innerHTML = style;
|
||||
document.head.appendChild(style_Add);
|
||||
if (document.head) {
|
||||
document.head.appendChild(style_Add);
|
||||
} else {
|
||||
let timer = setInterval(function(){
|
||||
if (document.head) {
|
||||
document.head.appendChild(style_Add);
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
function getTheme() {
|
||||
var name = "theme=";
|
||||
var ca = document.cookie.split(';');
|
||||
for(var i=0; i<ca.length; i++)
|
||||
let name = "theme=";
|
||||
let ca = document.cookie.split(';');
|
||||
for(let i=0; i<ca.length; i++)
|
||||
{
|
||||
var c = ca[i].trim();
|
||||
let c = ca[i].trim();
|
||||
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
|
||||
}
|
||||
return "light";
|
||||
|
||||
Reference in New Issue
Block a user