Skip to content

Instantly share code, notes, and snippets.

@tosaka2
Created January 31, 2019 10:37
Show Gist options
  • Save tosaka2/ea67372aa2323e5acf8f87ff810d6c71 to your computer and use it in GitHub Desktop.
Save tosaka2/ea67372aa2323e5acf8f87ff810d6c71 to your computer and use it in GitHub Desktop.
Shift comments of YouTube Premiers videos
(async function() {
'use strict';
let shift = 9;
console.log("Comment Shifter! shift:" + shift);
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec));
let button = null;
for (let i = 0; i < 100 && !button; i++) {
await sleep(100);
button = document.querySelectorAll("paper-button")[4];
}
if (!button) {
console.log("button NOT found.");
return;
}
if (button) {
console.log("button found");
button.click();
}
let obj = null;
for (let i = 0; i < 100 && !obj; i++) {
await sleep(100);
var chat_frame = document.querySelector("ytd-live-chat-frame");
obj = chat_frame.querySelector("iframe").contentDocument.querySelector("yt-live-chat-renderer");
}
if (!obj) {
console.log("Comment Shifter stopped.");
return;
}
obj.__playerProgressChanged = obj.playerProgressChanged_;
obj.__shift = shift;
obj.playerProgressChanged_ = (time, b, c) => obj.__playerProgressChanged(time + obj.__shift, b, c);
console.log("Successfully Shifted");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment