Last active
March 24, 2020 15:55
-
-
Save conundrumer/2acd85c66e7e1cc3f7814df10efd1b7b to your computer and use it in GitHub Desktop.
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
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | |
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | |
function run() { | |
return _run.apply(this, arguments); | |
} | |
function _run() { | |
_run = _asyncToGenerator(function* () { | |
console.info('Toggling visibility!'); | |
// var baseInterval = 1000 * 60 * 90 // 90 minutes | |
// var jitter = 1000 * 60 * 15 // +- 15 minutes | |
var baseInterval = 1000 * 60; // 60 seconds | |
var jitter = 1000 * 10; // +- 10 seconds | |
var timeout = baseInterval + jitter * (Math.random() * 2 - 1); | |
yield setVisibility('PRIVATE'); | |
yield setVisibility('PUBLIC'); | |
console.info(`Toggled at ${new Date().toLocaleString()}, next toggle at ${new Date(Date.now() + timeout).toLocaleString()}`); | |
yield sleep(timeout); | |
while (!navigator.onLine) { | |
yield sleep(1000 * 60); // if offline, try again in 1 minute | |
} | |
run(); | |
}); | |
return _run.apply(this, arguments); | |
} | |
function setVisibility(_x) { | |
return _setVisibility.apply(this, arguments); | |
} | |
function _setVisibility() { | |
_setVisibility = _asyncToGenerator(function* (status) { | |
// open visibility options | |
document.querySelector("ytcp-video-metadata-visibility").firstElementChild.click(); | |
yield sleep(); // click Public/Private radio button | |
document.querySelector(`paper-radio-button[name=${status}]`).click(); | |
yield sleep(); // close visibility options | |
document.querySelector("#save-button").click(); | |
yield sleep(); // click "SAVE" to save changes to video | |
document.querySelector("ytcp-button#save").click(); | |
yield sleep(200); // while saving, editor becomes disabled with "scrim" css class | |
// poll until editor becomes enabled again, which means changes have been saved | |
while (document.querySelector("#edit > ytcp-video-metadata-editor > div").classList.contains("scrim")) { | |
yield sleep(200); | |
} | |
console.info(`Set visibility to ${status}`); | |
}); | |
return _setVisibility.apply(this, arguments); | |
} | |
function sleep(t) { | |
t = t || 0 | |
return new Promise(resolve => setTimeout(resolve, t)); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment