Last active
December 1, 2023 05:54
-
-
Save insanj/181759590f55aca2a180ee35edd0cb97 to your computer and use it in GitHub Desktop.
youtube_like_after_30_seconds
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_like_after_30_seconds | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0.0 | |
// @description like videos after 30 seconds | |
// @author github.com/insanj | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @grant none | |
// @match *://*.youtube.com/* | |
// @run-at document-load | |
// @noframes | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const uuid = window.crypto.randomUUID(); | |
const log = (msg, ...objs) => objs ? console.info(`[youtube_like_after_thirty] <${uuid}> ${msg}`, objs) : console.info(`[youtube_like_after_thirty] ${msg}`); | |
var likeAfterThiry_threshold = 30; // in seconds | |
var likeAfterThiry_duration = 10; // in seconds | |
let likeAfterThirtyRuntime; | |
likeAfterThirtyRuntime = () => { | |
const nothingToDoUntilNextTime = () => { | |
setTimeout(() => { | |
likeAfterThirtyRuntime(); | |
}, likeAfterThiry_duration * 1000); | |
}; | |
log('runtime loop, i am alive :D', new Date()); | |
const video = document.querySelector("video"); | |
if (!video) { | |
nothingToDoUntilNextTime(); | |
log('we may be broken; could not find video'); | |
return; // no currently playing videos | |
} | |
const likeButton = document.querySelector("like-button-view-model button"); | |
if (!likeButton) { | |
nothingToDoUntilNextTime(); | |
log('we may be broken; could not find like button'); | |
return; | |
} | |
const isPressedAlready = likeButton.getAttribute("aria-pressed"); | |
if (isPressedAlready && isPressedAlready === "true") { | |
nothingToDoUntilNextTime(); | |
return; | |
} | |
const srcToLike = video.currentSrc; | |
// likeAfterThiry_currentSrc = srcToLike; | |
if (video.currentTime >= likeAfterThiry_threshold) { | |
likeButton.click(); | |
log(`autoliked video [currentTime ${video.currentTime}] [src ${srcToLike}]`); | |
nothingToDoUntilNextTime(); | |
} else { | |
const timeUntilLike = likeAfterThiry_threshold - video.currentTime; | |
log(`scheduling autoliked video [timeUntilLike ${timeUntilLike}]`); | |
setTimeout(() => { | |
likeAfterThirtyRuntime(); | |
}, timeUntilLike * 1000); | |
} | |
}; | |
setTimeout(() => { | |
likeAfterThirtyRuntime(); | |
}, 2500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment