|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 知乎美化 |
3 | | -// @version 1.5.16 |
| 3 | +// @version 1.5.17 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 宽屏显示、暗黑模式(4种)、暗黑模式跟随浏览器、屏蔽首页活动广告、隐藏文章开头大图、调整图片最大高度、向下翻时自动隐藏顶栏 |
6 | 6 | // @match *://www.zhihu.com/* |
|
138 | 138 | .zhihuE_SettingRoot .zhihuE_SettingHeader {padding: 10px 20px;color: #fff;font-weight: bold;background-color: #3994ff;border-radius: 3px 3px 0 0;} |
139 | 139 | .zhihuE_SettingRoot .zhihuE_SettingMain {padding: 10px 20px;border-radius: 0 0 3px 3px;} |
140 | 140 | .zhihuE_SettingHeader span {float: right;cursor: pointer;} |
141 | | -.zhihuE_SettingMain input {margin: 10px 6px 10px 0;cursor: pointer;vertical-align:middle} |
142 | | -.zhihuE_SettingMain label {margin-right: 20px;user-select: none;cursor: pointer;vertical-align:middle} |
| 141 | +.zhihuE_SettingMain input {margin: 10px 6px 10px 0;vertical-align:middle;} |
| 142 | +.zhihuE_SettingMain input[type=text] {margin: 5px 6px 5px 0;padding-block: 0;} |
| 143 | +.zhihuE_SettingMain input[name=zhihuE_Setting_Checkbox] {cursor: pointer;} |
| 144 | +.zhihuE_SettingMain label {margin-right: 20px;user-select: none;cursor: pointer;vertical-align:middle;} |
143 | 145 | .zhihuE_SettingMain hr {border: 0.5px solid #f4f4f4;} |
144 | 146 | [data-theme="dark"] .zhihuE_SettingRoot {color: #adbac7;background-color: #343A44;} |
145 | 147 | [data-theme="dark"] .zhihuE_SettingHeader {color: #d0d0d0;background-color: #2D333B;} |
|
150 | 152 | if (line) _br = '<br>' |
151 | 153 | for (let i=0; i<menu.length; i++) { |
152 | 154 | if (menu[i][0] === 'menu_widescreenDisplayWidth') { |
153 | | - _html += `<label>${menu[i][2]}:<input name="${menu[i][0]}" type="text" value="${GM_getValue(menu[i][0])}" style="width: 40px;"></label>${_br}` |
| 155 | + _html += `<label>${menu[i][2]}:<input name="${menu[i][0]}" type="text" oninput="value=value.replace(/[^\\d]/g,'')" value="${GM_getValue(menu[i][0])}" style="width: 50px;"></label>${_br}` |
154 | 156 | } else if (GM_getValue(menu[i][0])) { |
155 | 157 | _html += `<label><input name="zhihuE_Setting_Checkbox" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}` |
156 | 158 | } else { |
|
160 | 162 | _html += `</div></div></div>` |
161 | 163 | document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾 |
162 | 164 | setTimeout(function() { // 延迟 100 毫秒,避免太快 |
| 165 | + const doc = document.querySelector('.zhihuE_SettingBackdrop_1'); |
| 166 | + if (!doc) return |
163 | 167 | // 关闭按钮 点击事件 |
164 | | - document.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();} |
| 168 | + doc.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();} |
165 | 169 | // 点击周围空白处 = 点击关闭按钮 |
166 | | - document.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};} |
| 170 | + doc.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};} |
167 | 171 | // 复选框 点击事件 |
168 | | - document.getElementsByName('zhihuE_Setting_Checkbox').forEach(function (checkBox) { |
| 172 | + doc.querySelectorAll('input[name=zhihuE_Setting_Checkbox]').forEach(function (checkBox) { |
169 | 173 | checkBox.addEventListener('click', function(){if (this.checked) {GM_setValue(this.value, true);} else {GM_setValue(this.value, false);}}); |
170 | 174 | }) |
171 | | - document.getElementsByName('menu_widescreenDisplayWidth')[0].onchange = function(){GM_setValue(this.name, this.value);}; |
| 175 | + // 输入框 变化事件 |
| 176 | + doc.querySelectorAll('input[type=text]').forEach(function (checkBox) { |
| 177 | + checkBox.onchange = function(){GM_setValue(this.name, this.value);}; |
| 178 | + }) |
172 | 179 | }, 100) |
173 | 180 | } |
174 | 181 |
|
|
0 commit comments