Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Auto Unmute and Reset Facebook Reels and Videos
- // @namespace http://tampermonkey.net/
- // @version 1.4
- // @description Automatically unmutes Facebook Reels and videos on desktop and resets playback to start
- // @author Grok
- // @match https://www.facebook.com/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Function to unmute video and reset playback to start
- function unmuteVideo(retries = 5) {
- const unmuteButton = document.querySelector('div[aria-label="Unmute"][role="button"]');
- if (unmuteButton) {
- unmuteButton.click();
- console.log('Unmute button clicked successfully');
- // Find the closest video element
- const video = unmuteButton.closest('div').querySelector('video') || document.querySelector('video');
- if (video) {
- video.currentTime = 0;
- console.log('Video playback reset to start');
- } else {
- console.log('Video element not found for reset');
- }
- return;
- }
- // Fallback: directly unmute any muted video elements and reset
- const videos = document.querySelectorAll('video');
- videos.forEach(video => {
- if (video.muted) {W
- video.muted = false;
- video.currentTime = 0;
- console.log('Video directly unmuted and reset to start');
- }
- });
- // Retry if button not found and retries remain
- if (retries > 0) {
- console.log(`Unmute button not found, retrying (${retries} attempts left)`);
- setTimeout(() => unmuteVideo(retries - 1), 500);
- } else {
- console.log('Unmute button not found after all retries');
- }
- }
- // MutationObserver to detect when the unmute button is added
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- if (mutation.type === 'childList') {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.matches('div[aria-label="Unmute"][role="button"]')) {
- console.log('Unmute button detected in DOM');
- setTimeout(() => {
- node.click();
- console.log('Unmute button clicked via observer');
- const video = node.closest('div').querySelector('video') || document.querySelector('video');
- if (video) {
- video.currentTime = 0;
- console.log('Video playback reset to start via observer');
- } else {
- console.log('Video element not found for reset via observer');
- }
- }, 100);
- }
- });
- }
- });
- });
- // Start observing the document for changes
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- // Try unmuting initially (no delay, as per your working version)
- setTimeout(() => unmuteVideo(), 0);
- // Listen for clicks on Reel links
- document.addEventListener('click', (event) => {
- if (event.target.tagName === 'A' && event.target.href.includes('/reel/')) {
- console.log('Reel link clicked, attempting to unmute and reset');
- setTimeout(() => unmuteVideo(), 100);
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement