Created
February 22, 2025 05:12
-
-
Save jhauga/4e4b1e29e97aa5dd4383cac435331bcf to your computer and use it in GitHub Desktop.
Bookmarklet - use this bookmarklet for quickly resnc video and audio are out of sync to resynchronize audio to video. Ensure to copy/paste the top condensed line of the bookmarklet. Info at "https://github.com/isocialPractice/bookmarklets".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// *********************************************************** /// | |
| // ****************** BROWSER BOOKMARKLET GIST ***************** // | |
| // ************************************************************* // | |
| // // | |
| // LICENSE ///////////////////////////////////////////////////// | |
| // ******* // | |
| // The code in this gist is public domain. // | |
| // Licensed as Public Domain CC0 // | |
| ////////////////////////////////////////////////////////////////// | |
| // | |
| // COPY / PAST BELOW LINE TO USE | |
| javascript:(function() { /* Configuration Variable - set final quality of video. */ var finalQualityYouTubeSyncAudio = "720p"; /* Select video settings by class name. */ var settingsYouTubeSyncAudio = document.getElementsByClassName("ytp-button ytp-settings-button"); /* Select menu for quality using class name. */ var menuItemYouTubeSyncAudio = document.getElementsByClassName("ytp-menuitem"); /************************************************ MAIN FUNCTION ************************************************/ /* Click by argument being found in loop. */ function changeQualityYouTubeSyncAudio(clickWhat) { /* loop all menu items found by class name */ for (i = 0; i < menuItemYouTubeSyncAudio.length; i++) { /* if text in menu item found matching argument, click */ if ( menuItemYouTubeSyncAudio[i] .textContent .indexOf(clickWhat) > -1 ) { /* menu item matches argument, click and end loop */ menuItemYouTubeSyncAudio[i].click(); break; } } } /* Start process to sync video to audio. */ const syncVideoToAudioYouTubeSyncAudio = (step) => { /* conditional steps for process */ if (step == "Quality") { /* allow a bit of delay for menu dynamics */ setTimeout(function() { /* click video settings gear icon */ settingsYouTubeSyncAudio[0].click(); }, 100); } /* run main function to sync audio, resetting video quality, */ /* allowing a bit of delay for menu dynamics */ setTimeout(function() { changeQualityYouTubeSyncAudio(step); }, 300); }; /* Select video settings icon at bottom of video. **/ syncVideoToAudioYouTubeSyncAudio("Quality"); /* Set video to 144p. **/ syncVideoToAudioYouTubeSyncAudio("144p"); /* Additional delay to ensure menu dynamics. **/ setTimeout(function() { /* Again select video settings icon at bottom of video. **/ syncVideoToAudioYouTubeSyncAudio("Quality"); /* Set final video to config var. finalQualityYouTubeSyncAudio. */ syncVideoToAudioYouTubeSyncAudio(finalQualityYouTubeSyncAudio); }, 1000);})(); | |
| // MAKE ANY EDITS AS NEEDED | |
| // ************************************************************* | |
| // Use the JS Formatted Bookmarklet below to see if any changes | |
| // need to be made in accordance to the page you want to use | |
| // it for. After making needed changes ensure that the revised | |
| // bookmarklet is condensed before using it in your browser. | |
| // For more info on this bookmarklet visit: | |
| // https://github.com/isocialPractice/bookmarklets | |
| // ************************************************************* | |
| // ************************************************************* | |
| // ************************JS-FORMATTED************************* | |
| javascript:(function() { | |
| /* Configuration Variable - set final quality of video. */ | |
| var finalQualityYouTubeSyncAudio = "720p"; | |
| /* Select video settings by class name. */ | |
| var settingsYouTubeSyncAudio = | |
| document.getElementsByClassName("ytp-button ytp-settings-button"); | |
| /* Select menu for quality using class name. */ | |
| var menuItemYouTubeSyncAudio = | |
| document.getElementsByClassName("ytp-menuitem"); | |
| /************************************************ | |
| MAIN FUNCTION | |
| ************************************************/ | |
| /* Click by argument being found in loop. */ | |
| function changeQualityYouTubeSyncAudio(clickWhat) { | |
| /* loop all menu items found by class name */ | |
| for (i = 0; i < menuItemYouTubeSyncAudio.length; i++) { | |
| /* if text in menu item found matching argument, click */ | |
| if ( | |
| menuItemYouTubeSyncAudio[i] | |
| .textContent | |
| .indexOf(clickWhat) > -1 | |
| ) { | |
| /* menu item matches argument, click and end loop */ | |
| menuItemYouTubeSyncAudio[i].click(); | |
| break; | |
| } | |
| } | |
| } | |
| /* Start process to sync video to audio. */ | |
| const syncVideoToAudioYouTubeSyncAudio = (step) => { | |
| /* conditional steps for process */ | |
| if (step == "Quality") { | |
| /* allow a bit of delay for menu dynamics */ | |
| setTimeout(function() { | |
| /* click video settings gear icon */ | |
| settingsYouTubeSyncAudio[0].click(); | |
| }, 100); | |
| } | |
| /* run main function to sync audio, resetting video quality, */ | |
| /* allowing a bit of delay for menu dynamics */ | |
| setTimeout(function() { | |
| changeQualityYouTubeSyncAudio(step); | |
| }, 300); | |
| }; | |
| /* Select video settings icon at bottom of video. **/ | |
| syncVideoToAudioYouTubeSyncAudio("Quality"); | |
| /* Set video to 144p. **/ | |
| syncVideoToAudioYouTubeSyncAudio("144p"); | |
| /* Additional delay to ensure menu dynamics. **/ | |
| setTimeout(function() { | |
| /* Again select video settings icon at bottom of video. **/ | |
| syncVideoToAudioYouTubeSyncAudio("Quality"); | |
| /* Set final video to config var. finalQualityYouTubeSyncAudio. */ | |
| syncVideoToAudioYouTubeSyncAudio(finalQualityYouTubeSyncAudio); | |
| }, 1000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment