Created
November 26, 2023 10:01
-
-
Save noaione/e4508c144fae9946356c517bbd3b1f87 to your computer and use it in GitHub Desktop.
OTOTOY - No Volume Playback | Ensure that you don't get ear-raped when you open an album page and the trial song start blasting.
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 OTOTOY - No Volume Playback | |
// @namespace n4o-ototoy-script | |
// @match https://ototoy.jp/_/default/p/* | |
// @grant none | |
// @version 1.0 | |
// @author N4O | |
// @description Ensure that you don't get ear-raped when you open an album page and the trial song start blasting. | |
// ==/UserScript== | |
(() => { | |
// XXX: You can change this timeout, I'm too lazy to use MutationObserver. | |
// Default to 10s | |
const timeout = 10 * 1000; | |
let timeoutHandler; | |
let intervalHandler; | |
function log(...message) { | |
console.log("[OTOTOY Volume]", ...message); | |
} | |
function dispatchVolume(audioJsWrap) { | |
const volumeInput = audioJsWrap.querySelector("div.volume > input"); | |
if (volumeInput) { | |
log("dispatch 0% volume to:", volumeInput); | |
volumeInput.value = "0"; | |
// Dispatch input event since ototoy are doing something with it. | |
volumeInput.dispatchEvent(new Event("input", { bubbles: true })) | |
} | |
} | |
function main() { | |
log("dispatcher ready!"); | |
const audioJs = document.querySelector("#audiojs_wrapper0"); | |
if (audioJs) { | |
log("initial ready get!"); | |
dispatchVolume(audioJs); | |
return; | |
} | |
intervalHandler = setInterval(() => { | |
const audioJs = document.querySelector("#audiojs_wrapper0"); | |
if (audioJs) { | |
log("get audioJs in interval:", audioJs); | |
dispatchVolume(audioJs); | |
clearInterval(intervalHandler); | |
if (timeoutHandler) { | |
clearTimeout(timeoutHandler); | |
} | |
} | |
}, 500); | |
timeoutHandler = setTimeout(() => { | |
log("timeout!"); | |
if (intervalHandler) { | |
clearInterval(intervalHandler); | |
} | |
}, timeout); | |
} | |
if (document.readyState !== "loading") { | |
main(); | |
} else { | |
document.addEventListener("DOMContentLoaded", main); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment