|
1 | 1 | // ==UserScript== |
2 | 2 | // @name HTML5 视频音频默认音量 |
3 | | -// @version 1.0.1 |
| 3 | +// @version 1.0.2 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 避免被一些默认 100% 音量的视频/音频吓一跳(或社死)!且支持各网站分别记住音量... |
6 | 6 | // @match *://*/* |
|
25 | 25 | // 如果菜单ID数组多于菜单数组,说明不是首次添加菜单,需要卸载所有脚本菜单 |
26 | 26 | if (menu_ID.length > 0){for (let i=0;i<menu_ID.length;i++){GM_unregisterMenuCommand(menu_ID[i]);}} |
27 | 27 | menu_ID[0] = GM_registerMenuCommand('#️⃣ 修改全局默认音量 [ ' + GM_getValue('menu_defaultVolume', 30) + '% ]', function(){customDefaultVolume()}); |
28 | | - menu_ID[1] = GM_registerMenuCommand('🔁 忘记当前网站音量 (即跟随全局)', function(){resetCurrentVolume()}); |
| 28 | + let nowVolume = ' (跟随全局)' |
| 29 | + if (localStorage.getItem('html5_xiu_currentVolume')) nowVolume = ' [ ' + parseInt(localStorage.getItem('html5_xiu_currentVolume')) + '% ]' |
| 30 | + menu_ID[1] = GM_registerMenuCommand('🔁 忘记当前网站音量' + nowVolume, function(){resetCurrentVolume()}); |
29 | 31 | 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});}); |
30 | 32 | } |
31 | 33 |
|
|
66 | 68 | function volumeChangeEvent(event) { |
67 | 69 | if (event.target.muted) { // 判断是否静音 |
68 | 70 | localStorage.setItem('html5_xiu_currentVolume', 0) |
| 71 | + registerMenuCommand(); // 修改脚本菜单 |
69 | 72 | } else if (localStorage.getItem('html5_xiu_currentVolume') || ((event.target.volume * 100) !== GM_getValue('menu_defaultVolume', 30))) { |
70 | 73 | localStorage.setItem('html5_xiu_currentVolume', event.target.volume * 100) |
| 74 | + registerMenuCommand(); // 修改脚本菜单 |
71 | 75 | } |
72 | 76 | } |
73 | 77 |
|
|
78 | 82 | let nowVolume = parseFloat(localStorage.getItem('html5_xiu_currentVolume')); // 先看看 localStorage 有没有(即用户是否手动调整过音量) |
79 | 83 | if (!nowVolume && nowVolume !== 0) nowVolume = GM_getValue('menu_defaultVolume', 30); // 如果 localStorage 没有,那就从脚本配置中获取 |
80 | 84 | if (!((typeof nowVolume === 'number') && nowVolume <= 100)) nowVolume = 30; // 如果获取到的音量数值不是数字,或大于 100,则重置为 30 |
| 85 | + //console.log(_this, _this.volume) |
81 | 86 | _this.volume = nowVolume / 100; // 设置音量为 0~1 范围 |
| 87 | + //console.log(_this.volume) |
82 | 88 | } |
83 | 89 |
|
84 | 90 |
|
|
0 commit comments