Skip to content

Commit efc9ba9

Browse files
committed
优化 弹出式脚本设置(点击周围空白处可以关闭设置)
1 parent bcb57ef commit efc9ba9

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

Zhihu-Beautification.user.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 知乎美化
3-
// @version 1.3.3
3+
// @version 1.3.4
44
// @author X.I.U
55
// @description 宽屏显示、暗黑模式(4种)、暗黑模式跟随浏览器、隐藏文章开头大图、调整图片最大高度、向下翻时自动隐藏顶栏、文章编辑页面与实际文章宽度一致、屏蔽登录提示
66
// @match *://www.zhihu.com/*
@@ -146,21 +146,21 @@
146146
if (line) _br = '<br>'
147147
for (let i=0; i<menu.length; i++) {
148148
if (GM_getValue(menu[i][0])) {
149-
_html += `<input name="zhihuE_Setting" id="${menu[i][0]}" type="checkbox" value="${menu[i][0]}" checked="checked"><label for="${menu[i][0]}">${menu[i][1]}</label>${_br}`
149+
_html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}`
150150
} else {
151-
_html += `<input name="zhihuE_Setting" id="${menu[i][0]}" type="checkbox" value="${menu[i][0]}"><label for="${menu[i][0]}">${menu[i][1]}</label>${_br}`
151+
_html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}">${menu[i][1]}</label>${_br}`
152152
}
153153
}
154154
_html += `</div></div></div>`
155155
document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾
156-
setTimeout(function() { // 延迟 100 毫秒
156+
setTimeout(function() { // 延迟 100 毫秒,避免太快
157157
// 关闭按钮 点击事件
158158
document.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();}
159+
// 点击周围空白处 = 点击关闭按钮
160+
document.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};}
159161
// 复选框 点击事件
160162
document.getElementsByName('zhihuE_Setting').forEach(function (checkBox) {
161-
checkBox.addEventListener('click', function(){
162-
if (this.checked) {GM_setValue(this.id, true);} else {GM_setValue(this.id, false);}
163-
});
163+
checkBox.addEventListener('click', function(){if (this.checked) {GM_setValue(this.value, true);} else {GM_setValue(this.value, false);}});
164164
})
165165
}, 100)
166166
}

Zhihu-Enhanced.user.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name 知乎增强
3-
// @version 1.6.7
3+
// @version 1.6.8
44
// @author X.I.U
55
// @description 移除登录弹窗、默认收起回答、一键收起回答、收起当前回答/评论(点击两侧空白处)、快捷回到顶部(右键两侧空白处)、屏蔽用户 (发布的内容)、屏蔽关键词(标题/评论)、屏蔽指定类别(视频/文章等)、屏蔽盐选内容、展开问题描述、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认高清原图、默认站外直链
66
// @match *://www.zhihu.com/*
@@ -116,21 +116,21 @@ function menu_setting(type, title, tips, line, menu) {
116116
if (line) _br = '<br>'
117117
for (let i=0; i<menu.length; i++) {
118118
if (GM_getValue(menu[i][0])) {
119-
_html += `<input name="zhihuE_Setting" id="${menu[i][0]}" type="checkbox" value="${menu[i][0]}" checked="checked"><label for="${menu[i][0]}">${menu[i][1]}</label>${_br}`
119+
_html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}`
120120
} else {
121-
_html += `<input name="zhihuE_Setting" id="${menu[i][0]}" type="checkbox" value="${menu[i][0]}"><label for="${menu[i][0]}">${menu[i][1]}</label>${_br}`
121+
_html += `<label><input name="zhihuE_Setting" type="checkbox" value="${menu[i][0]}">${menu[i][1]}</label>${_br}`
122122
}
123123
}
124124
_html += `</div></div></div>`
125125
document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾
126-
setTimeout(function() { // 延迟 100 毫秒
126+
setTimeout(function() { // 延迟 100 毫秒,避免太快
127127
// 关闭按钮 点击事件
128128
document.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();}
129+
// 点击周围空白处 = 点击关闭按钮
130+
document.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};}
129131
// 复选框 点击事件
130132
document.getElementsByName('zhihuE_Setting').forEach(function (checkBox) {
131-
checkBox.addEventListener('click', function(){
132-
if (this.checked) {GM_setValue(this.id, true);} else {GM_setValue(this.id, false);}
133-
});
133+
checkBox.addEventListener('click', function(){if (this.checked) {GM_setValue(this.value, true);} else {GM_setValue(this.value, false);}});
134134
})
135135
}, 100)
136136
}

0 commit comments

Comments
 (0)