MCPcopy Create free account
hub / github.com/XIU2/UserScript / menu_setting

Function menu_setting

Zhihu-Beautification.user.js:136–182  ·  view source on GitHub ↗
(type, title, tips, line, menu)

Source from the content-addressed store, hash-verified

134
135 // 脚本设置
136 function menu_setting(type, title, tips, line, menu) {
137 let _br = '', _html = `<style class="zhihuE_SettingStyle">.zhihuE_SettingRoot {position: absolute;top: 50%;left: 50%;-webkit-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);transform: translate(-50%, -50%);width: auto;min-width: 400px;max-width: 600px;height: auto;min-height: 150px;max-height: 400px;color: #535353;background-color: #fff;border-radius: 3px;}
138.zhihuE_SettingBackdrop_1 {position: fixed;top: 0;right: 0;bottom: 0;left: 0;z-index: 203;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;overflow-x: hidden;overflow-y: auto;-webkit-transition: opacity .3s ease-out;transition: opacity .3s ease-out;}
139.zhihuE_SettingBackdrop_2 {position: absolute;top: 0;right: 0;bottom: 0;left: 0;z-index: 0;background-color: rgba(18,18,18,.65);-webkit-transition: background-color .3s ease-out;transition: background-color .3s ease-out;}
140.zhihuE_SettingRoot .zhihuE_SettingHeader {padding: 10px 20px;color: #fff;font-weight: bold;background-color: #3994ff;border-radius: 3px 3px 0 0;}
141.zhihuE_SettingRoot .zhihuE_SettingMain {padding: 10px 20px;border-radius: 0 0 3px 3px;}
142.zhihuE_SettingHeader span {float: right;cursor: pointer;}
143.zhihuE_SettingMain input {margin: 10px 6px 10px 0;vertical-align:middle;}
144.zhihuE_SettingMain input[type=text] {margin: 5px 6px 5px 0;padding-block: 0;}
145.zhihuE_SettingMain input[name=zhihuE_Setting_Checkbox] {cursor: pointer;}
146.zhihuE_SettingMain label {margin-right: 20px;user-select: none;cursor: pointer;vertical-align:middle;}
147.zhihuE_SettingMain hr {border: 0.5px solid #f4f4f4;}
148[data-theme="dark"] .zhihuE_SettingRoot {color: #adbac7;background-color: #343A44;}
149[data-theme="dark"] .zhihuE_SettingHeader {color: #d0d0d0;background-color: #2D333B;}
150[data-theme="dark"] .zhihuE_SettingMain hr {border: 0.5px solid #2d333b;}</style>
151 <div class="zhihuE_SettingBackdrop_1"><div class="zhihuE_SettingBackdrop_2"></div><div class="zhihuE_SettingRoot">
152 <div class="zhihuE_SettingHeader">${title}<span class="zhihuE_SettingClose" title="点击关闭"><svg class="Zi Zi--Close Modal-closeIcon" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M13.486 12l5.208-5.207a1.048 1.048 0 0 0-.006-1.483 1.046 1.046 0 0 0-1.482-.005L12 10.514 6.793 5.305a1.048 1.048 0 0 0-1.483.005 1.046 1.046 0 0 0-.005 1.483L10.514 12l-5.208 5.207a1.048 1.048 0 0 0 .006 1.483 1.046 1.046 0 0 0 1.482.005L12 13.486l5.207 5.208a1.048 1.048 0 0 0 1.483-.006 1.046 1.046 0 0 0 .005-1.482L13.486 12z" fill-rule="evenodd"></path></svg></span></div>
153 <div class="zhihuE_SettingMain"><p>${tips}</p><hr>`
154 if (line) _br = '<br>'
155 for (let i=0; i<menu.length; i++) {
156 if (menu[i][0] === 'menu_widescreenDisplayWidth') {
157 _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}`
158 } else if (GM_getValue(menu[i][0])) {
159 _html += `<label><input name="zhihuE_Setting_Checkbox" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}`
160 } else {
161 _html += `<label><input name="zhihuE_Setting_Checkbox" type="checkbox" value="${menu[i][0]}">${menu[i][1]}</label>${_br}`
162 }
163 }
164 _html += `</div></div></div>`
165 document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾
166 setTimeout(function() { // 延迟 100 毫秒,避免太快
167 const doc = document.querySelector('.zhihuE_SettingBackdrop_1');
168 if (!doc) return
169 // 关闭按钮 点击事件
170 doc.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();}
171 // 点击周围空白处 = 点击关闭按钮
172 doc.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};}
173 // 复选框 点击事件
174 doc.querySelectorAll('input[name=zhihuE_Setting_Checkbox]').forEach(function (checkBox) {
175 checkBox.addEventListener('click', function(){if (this.checked) {GM_setValue(this.value, true);} else {GM_setValue(this.value, false);}});
176 })
177 // 输入框 变化事件
178 doc.querySelectorAll('input[type=text]').forEach(function (checkBox) {
179 checkBox.onchange = function(){GM_setValue(this.name, this.value);};
180 })
181 }, 100)
182 }
183
184
185 // 添加样式

Callers 1

registerMenuCommandFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected