Skip to content

Commit

Permalink
add starting page option
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Mar 15, 2023
1 parent e972fd1 commit a3ea37d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
12 changes: 12 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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: [
Expand Down
20 changes: 15 additions & 5 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -127,17 +131,23 @@ 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";
}
}

// 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';
}
Expand Down
22 changes: 22 additions & 0 deletions providers/extracted-data.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit a3ea37d

Please sign in to comment.