Guest User

Auto-English CC W2G

a guest
Oct 6th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     Auto-English CC
  3. // @author   Paperlanty
  4. // @version  1
  5. // @grant    none
  6. // @include  https://w2g.tv/*
  7. // ==/UserScript==
  8.  
  9. var element = document.querySelector("[data-w2g=\"['video.subtitles.length', 'if']\"]");
  10.  
  11. var observer = new MutationObserver(function() {
  12.     if (element.style.display != 'none') {
  13.         myFunction();
  14.     }
  15. });
  16.  
  17. observer.observe(element, { attributes: true, childList: true });
  18.  
  19. function myFunction() {
  20.     let test = document.querySelector("[data-w2g=\"['video.subtitles.length', 'if']\"]");
  21.     let englishOption = contains('div.dd-item', 'English');
  22.  
  23.     try {
  24.         setTimeout(function() {
  25.             englishOption[0].click();
  26.         }, 1000)
  27.     } catch {
  28.         console.log('No English option found');
  29.     }
  30. }
  31.  
  32. function contains(selector, text) {
  33.     var elements = document.querySelectorAll(selector);
  34.     return Array.prototype.filter.call(elements, function(element) {
  35.         return RegExp(text).test(element.textContent);
  36.     });
  37. }
Add Comment
Please, Sign In to add comment