123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { loadFeatureConf } from "./config";
- import { logLevel, scriptInfo } from "./constants";
- import { addGlobalStyle, error, getDomain, initSiteEvents, log, setLogLevel } from "./utils";
- import {
- // layout
- initQueueButtons, addWatermark,
- preInitLayout, removeUpgradeTab, setVolSliderSize,
- setVolSliderStep,
- // lyrics
- addMediaCtrlLyricsBtn, geniUrlBase,
- // input
- initArrowKeySkip, initSiteSwitch, addAnchorImprovements,
- // menu
- initMenu, addMenu, initBeforeUnloadHook,
- } from "./features/index";
- // TODO: add some style
- console.log(`${scriptInfo.name} v${scriptInfo.version} (${scriptInfo.lastCommit}) - ${scriptInfo.namespace}`);
- console.log(`Powered by lots of ambition and my song metadata API: ${geniUrlBase}`);
- const domain = getDomain();
- /** Stuff that needs to be called ASAP, before anything async happens */
- function preInit() {
- setLogLevel(logLevel);
- if(domain === "ytm")
- initBeforeUnloadHook();
- init();
- }
- async function init() {
- await preInitLayout();
- try {
- document.addEventListener("DOMContentLoaded", onDomLoad);
- }
- catch(err) {
- console.error(`${scriptInfo.name} - General Error:`, err);
- }
- try {
- initMenu();
- }
- catch(err) {
- error("Couldn't initialize menu:", err);
- }
- }
- /** Called when the DOM has finished loading and can be queried and altered by the userscript */
- async function onDomLoad() {
- // post-build these double quotes are replaced by backticks
- addGlobalStyle("{{GLOBAL_STYLE}}", "global");
- const features = await loadFeatureConf();
- log(`Initializing features for domain '${domain}'`);
- try {
- if(domain === "ytm") {
- initSiteEvents();
- if(features.arrowKeySupport)
- initArrowKeySkip();
- if(features.removeUpgradeTab)
- removeUpgradeTab();
- if(features.watermarkEnabled)
- addWatermark();
- if(features.geniusLyrics)
- addMediaCtrlLyricsBtn();
- if(features.queueButtons)
- initQueueButtons();
- if(typeof features.volumeSliderSize === "number")
- setVolSliderSize();
- if(features.anchorImprovements)
- addAnchorImprovements();
- setVolSliderStep();
- }
- if(["ytm", "yt"].includes(domain)) {
- if(features.switchBetweenSites)
- initSiteSwitch(domain);
- try {
- addMenu(); // TODO: remove
- }
- catch(err) {
- error("Couldn't add menu:", err);
- }
- }
- }
- catch(err) {
- error("General error while executing feature:", err);
- }
- }
- preInit();
|