Pornhub autopause

Pause videos playing in background tabs when a video starts playing in the foreground tab

  1. // ==UserScript==
  2. // @name Pornhub autopause
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Pause videos playing in background tabs when a video starts playing in the foreground tab
  6. // @author Kirill Skliarov
  7. // @match https://www.pornhub.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pornhub.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const video = document.querySelector('.mgp_videoWrapper > video');
  16. if (video) {
  17. const channel = new BroadcastChannel('AutoPauseInBackgroundTab');
  18. video.addEventListener('play', () => channel.postMessage(null));
  19. channel.addEventListener('message', () => video.pause());
  20. }
  21. })();