Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Auto-English CC
- // @author Paperlanty
- // @version 1
- // @grant none
- // @include https://w2g.tv/*
- // ==/UserScript==
- var element = document.querySelector("[data-w2g=\"['video.subtitles.length', 'if']\"]");
- var observer = new MutationObserver(function() {
- if (element.style.display != 'none') {
- myFunction();
- }
- });
- observer.observe(element, { attributes: true, childList: true });
- function myFunction() {
- let test = document.querySelector("[data-w2g=\"['video.subtitles.length', 'if']\"]");
- let englishOption = contains('div.dd-item', 'English');
- try {
- setTimeout(function() {
- englishOption[0].click();
- }, 1000)
- } catch {
- console.log('No English option found');
- }
- }
- function contains(selector, text) {
- var elements = document.querySelectorAll(selector);
- return Array.prototype.filter.call(elements, function(element) {
- return RegExp(text).test(element.textContent);
- });
- }
Add Comment
Please, Sign In to add comment