Last active
February 24, 2025 06:03
-
-
Save langheran/e6dc8de5e71864dd41bf8c38d8c89754 to your computer and use it in GitHub Desktop.
C:\Users\NisimHurst\Utilities\Autohotkey\UserScripts\BrainFM autoplay.user.js
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
// ==UserScript== | |
// @name BrainFM autoplay | |
// @namespace http://tampermonkey.net/ | |
// @version 2025-01-24 | |
// @description try to take over the world! | |
// @author You | |
// @match https://my.brain.fm/player/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_notification | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var shiftDown = false; | |
var ctrlDown = false; | |
var altDown = false; | |
function doc_keyUp(e) { | |
switch (e.keyCode) { | |
case 16: | |
shiftDown = false; | |
break; | |
case 17: | |
ctrlDown = false; | |
break; | |
case 18: | |
altDown = false; | |
break; | |
default: | |
break; | |
} | |
} | |
function doc_keyDown(e) { | |
switch (e.keyCode) { | |
case 16: | |
shiftDown = true; | |
break; | |
case 17: | |
ctrlDown = true; | |
break; | |
case 18: | |
altDown = true; | |
break; | |
case 87: //w | |
togglePlayW(); | |
break; | |
} | |
} | |
document.addEventListener('keyup', doc_keyUp, false); | |
document.addEventListener('keydown', doc_keyDown, false); | |
const notificationDetails = { | |
title: "Brain.FM", | |
timeout: 2000 | |
}; | |
function findall(selector) { | |
return document.querySelectorAll(selector); | |
} | |
function clickAudio() { | |
findall('*[aria-label^="Play"]').forEach(function(item) { | |
item.click(); | |
}); | |
} | |
function waitVideo() { | |
if (findall('*[aria-label^="Play"]').length == 0) { | |
setTimeout(waitVideo, 20); | |
} else { | |
setTimeout(clickAudio, 1000); | |
setPlayW(); | |
} | |
} | |
waitVideo(); | |
var playwHandle= false; | |
function setPlayW() { | |
if (playwHandle){ | |
clearInterval(playwHandle); | |
playwHandle = false; | |
} | |
var playw = GM_getValue('playw', true); | |
if (playw) { | |
//playwHandle = setInterval(watchDogPlay, 3600000); // 1 hour | |
//playwHandle = setInterval(watchDogPlay, 1800000); // 30 mins | |
playwHandle = setInterval(watchDogPlay, 900000); // 15 mins | |
// playwHandle = setInterval(watchDogPlay, 5000); | |
// watchDogPlay(); | |
} | |
} | |
function watchDogPlay(){ | |
var hasVideo = false; | |
findall("audio").forEach(function(item) { | |
hasVideo = true; | |
playItem(); | |
}); | |
} | |
function togglePlayW(){ | |
var playw = GM_getValue('playw', true) | |
playw = !playw | |
GM_setValue('playw', playw) | |
notificationDetails.text = playw?"Play Watchdog: ON":"Play Watchdog: OFF"; | |
GM_notification(notificationDetails); | |
// alert('aaa'); | |
setPlayW(); | |
} | |
function playItem(){ | |
var foundItem = false; | |
findall("audio").forEach(function(item) { | |
foundItem = true; | |
try{ | |
if (item.paused){ | |
// item.play(); | |
clickAudio(); | |
item.muted = 0; | |
item.removeAttribute("muted"); | |
} | |
}catch{ | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment