From a3ea37d41277d0cc9b3fdea62979ff93fae6bfcc Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Wed, 15 Mar 2023 23:06:34 +0200 Subject: [PATCH] add starting page option fix #1071 --- menu.js | 12 ++++++++++++ preload.js | 20 +++++++++++++++----- providers/extracted-data.js | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 providers/extracted-data.js diff --git a/menu.js b/menu.js index a741cd5d1a..4c96828bd4 100644 --- a/menu.js +++ b/menu.js @@ -7,6 +7,7 @@ const { restart } = require("./providers/app-controls"); const { getAllPlugins } = require("./plugins/utils"); const config = require("./config"); +const { startingPages } = require("./providers/extracted-data"); const prompt = require("custom-electron-prompt"); const promptOptions = require("./providers/prompt-options"); @@ -81,6 +82,17 @@ const mainMenuTemplate = (win) => { config.setMenuOption("options.resumeOnStart", item.checked); }, }, + { + label: 'Starting page', + submenu: Object.keys(startingPages).map((name) => ({ + label: name, + type: 'radio', + checked: config.get('options.startingPage') === name, + click: () => { + config.set('options.startingPage', name); + }, + })) + }, { label: "Visual Tweaks", submenu: [ diff --git a/preload.js b/preload.js index 492f319225..a4be23901a 100644 --- a/preload.js +++ b/preload.js @@ -5,8 +5,12 @@ const { setupSongControls } = require("./providers/song-controls-front"); const { ipcRenderer } = require("electron"); const is = require("electron-is"); +const { startingPages } = require("./providers/extracted-data"); + const plugins = config.plugins.getEnabled(); +const $ = document.querySelector.bind(document); + let api; plugins.forEach(async ([plugin, options]) => { @@ -79,14 +83,14 @@ document.addEventListener("DOMContentLoaded", () => { }); function listenForApiLoad() { - api = document.querySelector('#movie_player'); + api = $('#movie_player'); if (api) { onApiLoaded(); return; } const observer = new MutationObserver(() => { - api = document.querySelector('#movie_player'); + api = $('#movie_player'); if (api) { observer.disconnect(); onApiLoaded(); @@ -97,7 +101,7 @@ function listenForApiLoad() { } function onApiLoaded() { - const video = document.querySelector("video"); + const video = $("video"); const audioContext = new AudioContext(); const audioSource = audioContext.createMediaElementSource(video); audioSource.connect(audioContext.destination); @@ -127,9 +131,15 @@ function onApiLoaded() { document.dispatchEvent(new CustomEvent('apiLoaded', { detail: api })); ipcRenderer.send('apiLoaded'); + // Navigate to "Starting page" + const startingPage = config.get("options.startingPage"); + if (startingPage !== "home" && startingPages[startingPage]) { + $('ytmusic-app')?.navigate_(startingPages[startingPage]); + } + // Remove upgrade button if (config.get("options.removeUpgradeButton")) { - const upgradeButton = document.querySelector('ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]') + const upgradeButton = $('ytmusic-pivot-bar-item-renderer[tab-id="SPunlimited"]') if (upgradeButton) { upgradeButton.style.display = "none"; } @@ -137,7 +147,7 @@ function onApiLoaded() { // Force show like buttons if (config.get("options.ForceShowLikeButtons")) { - const likeButtons = document.querySelector('ytmusic-like-button-renderer') + const likeButtons = $('ytmusic-like-button-renderer') if (likeButtons) { likeButtons.style.display = 'inherit'; } diff --git a/providers/extracted-data.js b/providers/extracted-data.js new file mode 100644 index 0000000000..31df149fa4 --- /dev/null +++ b/providers/extracted-data.js @@ -0,0 +1,22 @@ +const startingPages = { + Home: 'FEmusic_home', + Explore: 'FEmusic_explore', + 'New Releases': 'FEmusic_new_releases', + Charts: 'FEmusic_charts', + 'Moods & Genres': 'FEmusic_moods_and_genres', + Library: 'FEmusic_library_landing', + Playlists: 'FEmusic_liked_playlists', + Songs: 'FEmusic_liked_videos', + Albums: 'FEmusic_liked_albums', + Artists: 'FEmusic_library_corpus_track_artists', + 'Subscribed Artists': 'FEmusic_library_corpus_artists', + Uploads: 'FEmusic_library_privately_owned_landing', + 'Uploaded Playlists': 'FEmusic_liked_playlists', + 'Uploaded Songs': 'FEmusic_library_privately_owned_tracks', + 'Uploaded Albums': 'FEmusic_library_privately_owned_releases', + 'Uploaded Artists': 'FEmusic_library_privately_owned_artists', +}; + +module.exports = { + startingPages, +};