Advertisement
jcunews

RedditAutoUnmuteVideos.user.js

Jun 4th, 2021 (edited)
702
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ==UserScript==
  2. // @name         Reddit Auto Unmute Videos
  3. // @namespace    https://greasyfork.org/en/users/85671-jcunews
  4. // @version      1.0.1
  5. // @license      AGPLv3
  6. // @author       jcunews
  7. // @description  https://www.reddit.com/r/userscripts/comments/eizq63/is_there_a_userscript_to_automatically_unmute_all/
  8. // @match        https://*.reddit.com/*
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (e => {
  13.   //old layout
  14.   document.querySelectorAll('button.volume[data-action="unmute"]').forEach(e => e.click());
  15.   //new layout
  16.   (new MutationObserver(rs => {
  17.     rs.forEach(r => {
  18.       r.addedNodes.forEach((n, b) => {
  19.         if (n.querySelector && (n = b = n.querySelector("._2W9KLflUho3xU7KURAaHwH>button"))) {
  20.           while (n = n.parentNode) {
  21.             if (n.classList.contains("_3QOPLw8PZipW3i8kDxod81")) {
  22.               if ((n = n.querySelector("video")) && n.muted) b.click();
  23.               break
  24.             }
  25.           }
  26.         }
  27.       });
  28.     });
  29.   })).observe(document.body, {childList: true, subtree: true})
  30. })()
  31.  
Advertisement
RAW Paste Data Copied
Advertisement