|
3 | 3 | // @name:zh-CN HTML5 视频音频默认音量 |
4 | 4 | // @name:zh-TW HTML5 視訊音訊預設音量 |
5 | 5 | // @name:ru Громкость аудио-видео в формате HTML5 по умолчанию |
6 | | -// @version 1.0.3 |
| 6 | +// @version 1.0.4 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description Avoid being startled by some video/audio with default 100% volume! And support each website to remember the volume separately... |
9 | 9 | // @description:zh-CN 避免被一些默认 100% 音量的视频/音频吓一跳(或社死)!且支持各网站分别记住音量... |
|
34 | 34 | let nowVolume = ' (跟随全局)' |
35 | 35 | if (localStorage.getItem('html5_xiu_currentVolume')) nowVolume = ' [ ' + parseInt(localStorage.getItem('html5_xiu_currentVolume')) + '% ]' |
36 | 36 | menu_ID[1] = GM_registerMenuCommand('🔁 忘记当前网站音量' + nowVolume, function(){resetCurrentVolume()}); |
37 | | - menu_ID[2] = GM_registerMenuCommand('💬 反馈 & 建议', function () {GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true}); GM_openInTab('https://greasyfork.org/zh-CN/scripts/438400/feedback', {active: true,insert: true,setParent: true});}); |
| 37 | + // 强制当前网站使用全局音量(针对部分不支持调节音量的网站) |
| 38 | + if (menu_forcedToEnable('check')) { // 当前网站是否已存在强制列表中 |
| 39 | + menu_ID[2] = GM_registerMenuCommand('✅ 已强制当前网站使用全局音量 (针对不支持调节音量的)', function(){menu_forcedToEnable('del')}); |
| 40 | + menu_ID[4] = GM_registerMenuCommand('#️⃣ 修改当前网站默认音量 (针对不支持调节音量的)', function(){customCurrentDefaultVolume()}); |
| 41 | + } else { |
| 42 | + menu_ID[2] = GM_registerMenuCommand('❌ 未强制当前网站使用全局音量 (针对不支持调节音量的)', function(){menu_forcedToEnable('add')}); |
| 43 | + } |
| 44 | + menu_ID[3] = GM_registerMenuCommand('💬 反馈 & 建议', function () {GM_openInTab('https://github.com/XIU2/UserScript#xiu2userscript', {active: true,insert: true,setParent: true}); GM_openInTab('https://greasyfork.org/zh-CN/scripts/438400/feedback', {active: true,insert: true,setParent: true});}); |
38 | 45 | } |
39 | 46 |
|
40 | 47 | insPage(); |
41 | 48 | currentPage(); |
42 | 49 |
|
| 50 | + // 强制当前网站使用全局音量(针对部分不支持调节音量的网站) |
| 51 | + function menu_forcedToEnable(type) { |
| 52 | + switch(type) { |
| 53 | + case 'check': |
| 54 | + if(check()) return true |
| 55 | + return false |
| 56 | + break; |
| 57 | + case 'add': |
| 58 | + add(); |
| 59 | + break; |
| 60 | + case 'del': |
| 61 | + del(); |
| 62 | + break; |
| 63 | + } |
| 64 | + |
| 65 | + function check() { // 存在返回真,不存在返回假 |
| 66 | + let websiteList = GM_getValue('menu_forcedToEnable',[]); // 读取网站列表 |
| 67 | + if (websiteList.indexOf(location.host) === -1) return false // 不存在返回假 |
| 68 | + return true |
| 69 | + } |
| 70 | + |
| 71 | + function add() { |
| 72 | + if (check()) return |
| 73 | + let websiteList = GM_getValue('menu_forcedToEnable',[]); // 读取网站列表 |
| 74 | + websiteList.push(location.host); // 追加网站域名 |
| 75 | + GM_setValue('menu_forcedToEnable', websiteList); // 写入配置 |
| 76 | + location.reload(); // 刷新网页 |
| 77 | + } |
| 78 | + |
| 79 | + function del() { |
| 80 | + if (!check()) return |
| 81 | + let websiteList = GM_getValue('menu_forcedToEnable',[]), // 读取网站列表 |
| 82 | + index = websiteList.indexOf(location.host); |
| 83 | + websiteList.splice(index, 1); // 删除网站域名 |
| 84 | + GM_setValue('menu_forcedToEnable', websiteList); // 写入配置 |
| 85 | + location.reload(); // 刷新网页 |
| 86 | + } |
| 87 | + } |
| 88 | + |
43 | 89 |
|
44 | 90 | // 网页本身的 Video Audio 标签 |
45 | 91 | function currentPage() { |
|
88 | 134 |
|
89 | 135 | // 判断该视频/音频元素是否已监听事件 |
90 | 136 | function isFirstEvent(target) { |
91 | | - if (!target.controls) return; // 如果视频/音频已经有了自己的控件(即没有使用 HTML5 默认的控件),则退出 |
| 137 | + if (!menu_forcedToEnable('check')) { // 如果未强制当前网站使用全局音量(针对部分不支持调节音量的网站) |
| 138 | + if (!target.controls) return; // 如果视频/音频已经有了自己的控件(即没有使用 HTML5 默认的控件),则退出 |
| 139 | + } |
92 | 140 | modifyVolume(target); |
93 | 141 | // 如果没有该属性,则代表是还未监听事件 |
94 | 142 | if (target.dataset.html5VolumeXiu != 'true') { |
|
111 | 159 |
|
112 | 160 | // 修改全局默认音量 |
113 | 161 | function customDefaultVolume() { |
114 | | - let newValue = parseFloat(prompt('修改全局默认音量,不影响各网站记住的音量,当前网页需刷新后生效~\n范围:0~100 (即 0%~100%,不需要加 % 百分号)\n默认:30', GM_getValue('menu_defaultVolume', 30))); |
| 162 | + let newValue = parseFloat(prompt('修改全局默认音量,不影响各网站记住的音量,修改后当前网页立即生效~\n范围:0~100 (即 0%~100%,不需要加 % 百分号)\n默认:30', GM_getValue('menu_defaultVolume', 30))); |
115 | 163 | if (!Number.isNaN(newValue) && newValue >= 0 && newValue <= 100) {GM_setValue('menu_defaultVolume', newValue);} |
| 164 | + currentPage(); // 重置当前网页的音量 |
| 165 | + registerMenuCommand(); // 重新注册菜单(刷新菜单上的音量值) |
| 166 | + } |
| 167 | + |
| 168 | + |
| 169 | + // 修改当前网站默认音量 (针对不支持调节音量的网站) |
| 170 | + function customCurrentDefaultVolume() { |
| 171 | + let newValue = parseFloat(prompt('修改当前网站默认音量 (针对不支持调节音量的网站),修改后立即生效~\n范围:0~100 (即 0%~100%,不需要加 % 百分号)\n默认:全局默认音量', localStorage.getItem('html5_xiu_currentVolume') || GM_getValue('menu_defaultVolume', 30))); |
| 172 | + if (!Number.isNaN(newValue) && newValue >= 0 && newValue <= 100) {localStorage.setItem('html5_xiu_currentVolume', newValue);} |
| 173 | + currentPage(); // 重置当前网页的音量 |
116 | 174 | registerMenuCommand(); // 重新注册菜单(刷新菜单上的音量值) |
117 | 175 | } |
118 | 176 |
|
|
121 | 179 | function resetCurrentVolume() { |
122 | 180 | if (localStorage.getItem('html5_xiu_currentVolume')) localStorage.removeItem('html5_xiu_currentVolume') // 清理 localStorage |
123 | 181 | currentPage(); // 重置当前网页的音量 |
| 182 | + registerMenuCommand(); // 重新注册菜单(刷新菜单上的音量值) |
124 | 183 | } |
125 | 184 | })(); |
0 commit comments