Created
May 16, 2019 09:29
-
-
Save RafalJDev/5396c3dacda9c76ed879cce3850a4f3e to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name Youtube quality | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.youtube.com/* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
(async function() { | |
console.log("I am here :D ") | |
await waitTillElementAppear("ytp-button ytp-settings-button",0) | |
click("ytp-button ytp-settings-button", 0) | |
sleep(100) | |
await waitTillElementAppear("ytp-menuitem", 3) | |
click("ytp-menuitem", 4) | |
//await waitTillElementAppear("ytp-menuitem-label", 4) | |
//click("ytp-menuitem-label", 4) | |
console.log("I am here :P ") | |
//ytp-popup ytp-settings-menu | |
//ytp-menuitem | |
})(); | |
async function waitTillElementAppear(className, elementIndex) { | |
var wasExceptionThrown; | |
do{ | |
console.log("1234" + className) | |
wasExceptionThrown = false; | |
try{ | |
var hasPopupAppeared = document.getElementsByClassName(className)[elementIndex].innerText != null | |
} catch(e){ | |
wasExceptionThrown = true | |
await sleep(100) | |
} | |
} while(wasExceptionThrown || !hasPopupAppeared); | |
} | |
function click(className, elementIndex) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
document.getElementsByClassName(className)[elementIndex].dispatchEvent(evt); | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment