(type, title, tips, line, menu)
| 129 | |
| 130 | // 脚本设置 |
| 131 | function menu_setting(type, title, tips, line, menu) { |
| 132 | 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;} |
| 133 | .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;} |
| 134 | .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;} |
| 135 | .zhihuE_SettingRoot .zhihuE_SettingHeader {padding: 10px 20px;color: #fff;font-weight: bold;background-color: #3994ff;border-radius: 3px 3px 0 0;} |
| 136 | .zhihuE_SettingRoot .zhihuE_SettingMain {padding: 10px 20px;border-radius: 0 0 3px 3px;} |
| 137 | .zhihuE_SettingHeader span {float: right;cursor: pointer;} |
| 138 | .zhihuE_SettingMain input {margin: 10px 6px 10px 0;vertical-align:middle;} |
| 139 | .zhihuE_SettingMain input[type=text] {margin: 5px 6px 5px 0;padding-block: 0;} |
| 140 | .zhihuE_SettingMain input[name=zhihuE_Setting_Checkbox] {cursor: pointer;} |
| 141 | .zhihuE_SettingMain label {margin-right: 20px;user-select: none;cursor: pointer;vertical-align:middle;} |
| 142 | .zhihuE_SettingMain hr {border: 0.5px solid #f4f4f4;} |
| 143 | [data-theme="dark"] .zhihuE_SettingRoot {color: #adbac7;background-color: #343A44;} |
| 144 | [data-theme="dark"] .zhihuE_SettingHeader {color: #d0d0d0;background-color: #2D333B;} |
| 145 | [data-theme="dark"] .zhihuE_SettingMain hr {border: 0.5px solid #2d333b;}</style> |
| 146 | <div class="zhihuE_SettingBackdrop_1"><div class="zhihuE_SettingBackdrop_2"></div><div class="zhihuE_SettingRoot"> |
| 147 | <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> |
| 148 | <div class="zhihuE_SettingMain"><p>${tips}</p><hr>` |
| 149 | if (line) _br = '<br>' |
| 150 | for (let i=0; i<menu.length; i++) { |
| 151 | if (menu[i][0].indexOf('menu_blockLow') === 0) { |
| 152 | _html += `<label>${menu[i][1]}:<input name="${menu[i][0]}" type="text" oninput="value=value.replace(/[^\\d]/g,'')" value="${GM_getValue(menu[i][0])}" style="width: 50px;"></label>${_br}` |
| 153 | } else if (GM_getValue(menu[i][0])) { |
| 154 | _html += `<label><input name="zhihuE_Setting_Checkbox" type="checkbox" value="${menu[i][0]}" checked="checked">${menu[i][1]}</label>${_br}` |
| 155 | } else { |
| 156 | _html += `<label><input name="zhihuE_Setting_Checkbox" type="checkbox" value="${menu[i][0]}">${menu[i][1]}</label>${_br}` |
| 157 | } |
| 158 | } |
| 159 | _html += `</div></div></div>` |
| 160 | document.body.insertAdjacentHTML('beforeend', _html); // 插入网页末尾 |
| 161 | setTimeout(function() { // 延迟 100 毫秒,避免太快 |
| 162 | const doc = document.querySelector('.zhihuE_SettingBackdrop_1'); |
| 163 | if (!doc) return |
| 164 | // 关闭按钮 点击事件 |
| 165 | doc.querySelector('.zhihuE_SettingClose').onclick = function(){this.parentElement.parentElement.parentElement.remove();document.querySelector('.zhihuE_SettingStyle').remove();} |
| 166 | // 点击周围空白处 = 点击关闭按钮 |
| 167 | doc.querySelector('.zhihuE_SettingBackdrop_2').onclick = function(event){if (event.target == this) {document.querySelector('.zhihuE_SettingClose').click();};} |
| 168 | // 复选框 点击事件 |
| 169 | doc.querySelectorAll('input[name=zhihuE_Setting_Checkbox]').forEach(function (checkBox) { |
| 170 | checkBox.addEventListener('click', function(){if (this.checked) {console.log('this.value',true);GM_setValue(this.value, true);} else {console.log('this.value',false);GM_setValue(this.value, false);}}); |
| 171 | }) |
| 172 | // 输入框 变化事件 |
| 173 | doc.querySelectorAll('input[type=text]').forEach(function (checkBox) { |
| 174 | checkBox.onchange = function(){GM_setValue(this.name, this.value);}; |
| 175 | }) |
| 176 | }, 100) |
| 177 | } |
| 178 | |
| 179 | |
| 180 | // 添加收起回答观察器 |
no outgoing calls
no test coverage detected