Auto Close Twitch Ads

Close, mute or hide Twitch video ads automatically while watching a stream!

  1. /**
  2. MIT License
  3.  
  4. Copyright (c) 2018+, Kiran Murmu
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. SOFTWARE.
  23. **/
  24. // ==UserScript==
  25. // @name Auto Close Twitch Ads
  26. // @namespace https://github.com/kiranmurmuone
  27. // @description Close, mute or hide Twitch video ads automatically while watching a stream!
  28. // @copyright 2018+, Kiran Murmu
  29. // @match *://*.twitch.tv/*
  30. // @author kiranmurmuone
  31. // @version 1.3.95
  32. // @source https://github.com/kiranmurmuone/auto-close-twitch-ads
  33. // @license MIT
  34. // @grant GM_info
  35. // @grant GM_setValue
  36. // @grant GM_getValue
  37. // @grant GM_deleteValue
  38. // @grant GM_addStyle
  39. // @grant GM_registerMenuCommand
  40. // ==/UserScript==
  41.  
  42. (function() { var _video = {interval: 250, duration: 5, skipped: true, hidden: false, muted: true, console: true, present: null, advert: null,
  43. player: null, dstyle: null, addstyle: function (_key) { if (typeof GM_addStyle !== 'undefined' && typeof _key === 'string') { GM_addStyle(
  44. '.player-ad-notice > p {display: ' + _key + ';}'); return true; } return false; }, scriptName: function (_key) { if (typeof GM_info !== 'undefined') {
  45. if (_key) { return GM_info.script.name.replace(new RegExp(' ', 'g'), '-'); } else { return GM_info.script.name; }} return 'undefined'; }, volume: null,
  46. playerQuery: 'div.player-video video', styleSheet: '.player-ad-notice > p {display: none;}', unmuted: 'mute-button', dstyleQuery:
  47. 'div.js-ima-ads-container.ima-ads-container', presentQuery: 'div.persistent-player.tw-border-radius-none', volumeQuery:
  48. 'button.player-button.player-button--volume span', advertQuery: 'div.js-ima-ads-container.ima-ads-container video', setStore: function(_key, _val) {
  49. if (typeof GM_setValue !== 'undefined') { return GM_setValue(_key, _val); } return _val; }, getStore: function(_key, _val) {
  50. if (typeof GM_getValue !== 'undefined') { return GM_getValue(_key, _val); } return _val; }, delStore: function(_key) {
  51. if (typeof GM_deleteValue !== 'undefined') { return GM_deleteValue(_key); } return 'undefined'; }}; _video.duration = _video.getStore(_video.scriptName(true) +
  52. '.duration', _video.duration); _video.skipped = _video.getStore(_video.scriptName(true) + '.skipped', _video.skipped); _video.hidden = _video.getStore(
  53. _video.scriptName(true) + '.hidden', _video.hidden); _video.muted = _video.getStore(_video.scriptName(true) + '.muted', _video.muted);
  54. function noticeAd() { _video.present = document.querySelector(_video.presentQuery); if (typeof _video.present !== 'undefined' && _video.present) {
  55. _video.volume = document.querySelector(_video.volumeQuery); _video.dstyle = document.querySelector(_video.dstyleQuery);
  56. _video.advert = document.querySelector(_video.advertQuery); _video.player = document.querySelector(_video.playerQuery);
  57. if (typeof _video.dstyle !== 'undefined' && _video.dstyle) { if (_video.hidden && !_video.dstyle.style.display) { _video.dstyle.style.display = 'none';
  58. if (typeof _video.addstyle !== 'undefined') { if (_video.addstyle('none') && _video.console) { console.log(_video.scriptName() + ': video ad hidden.');
  59. }} }} if ((typeof _video.volume !== 'undefined' && _video.volume) && (typeof _video.advert !== 'undefined' && _video.advert) &&
  60. (typeof _video.player !== 'undefined' && _video.player)) { if (_video.muted && !_video.advert.muted && _video.advert.volume) {
  61. _video.advert.muted = true; _video.advert.volume = 0; if (_video.player.muted && _video.volume.className === _video.unmuted) { _video.player.muted = false;}
  62. if (_video.console) { console.log(_video.scriptName() + ': video ad muted.'); }} if (_video.skipped && _video.advert.duration && _video.advert.src) {
  63. if (_video.advert.currentTime !== _video.advert.duration && _video.advert.currentTime >= (_video.duration ? _video.duration + 1 : 0)) {
  64. _video.advert.currentTime = _video.advert.duration; if (_video.console) { console.log(_video.scriptName() + ': video ad skipped.');}} }} }}
  65. setInterval(noticeAd, _video.interval); if (typeof GM_registerMenuCommand !== 'undefined') { GM_registerMenuCommand(_video.scriptName() +
  66. ': Set video ad duration.', function() { var _wait = parseInt( prompt('Current video ad duration is ' + _video.duration +
  67. ' sec. Enter new duration value, 0 means no ads.')); if (!isNaN(_wait)) { _video.duration = _wait; _video.setStore(_video.scriptName(true) +
  68. '.duration', _video.duration); }}); GM_registerMenuCommand(_video.scriptName() + ': ' + (_video.skipped ? 'Disable' : 'Enable') +
  69. ' video ad skip.', function() { _video.setStore(_video.scriptName(true) + '.skipped', !_video.skipped); location.reload(); });
  70. GM_registerMenuCommand(_video.scriptName() + ': ' + (_video.hidden ? 'Disable' : 'Enable') + ' video ad hide.', function() {
  71. _video.setStore(_video.scriptName(true) + '.hidden', !_video.hidden); if (!_video.hidden) { _video.setStore(_video.scriptName(true) + '.muted',
  72. !_video.hidden);} location.reload(); }); GM_registerMenuCommand(_video.scriptName() + ': ' + (_video.muted ? 'Disable' : 'Enable') + ' video ad mute.',
  73. function() { _video.setStore(_video.scriptName(true) + '.muted', !_video.muted); location.reload(); }); GM_registerMenuCommand(_video.scriptName() +
  74. ': Restore default setting.', function() { _video.delStore(_video.scriptName(true) + '.duration'); _video.delStore(_video.scriptName(true) + '.skipped');
  75. _video.delStore(_video.scriptName(true) + '.hidden'); _video.delStore(_video.scriptName(true) + '.muted'); location.reload(); }) ;} })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址