Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add starting page option #1073

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const defaultConfig = {
autoResetAppCache: false,
resumeOnStart: true,
proxy: "",
startingPage: "",
},
plugins: {
// Enabled plugins
Expand Down
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) => ({
th-ch marked this conversation as resolved.
Show resolved Hide resolved
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,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 && 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";
}
Expand All @@ -139,7 +149,7 @@ function onApiLoaded() {
// Hide / Force show like buttons
const likeButtonsOptions = config.get("options.likeButtons");
if (likeButtonsOptions) {
const likeButtons = document.querySelector("ytmusic-like-button-renderer");
const likeButtons = $("ytmusic-like-button-renderer");
if (likeButtons) {
likeButtons.style.display =
{
Expand Down
23 changes: 23 additions & 0 deletions providers/extracted-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const startingPages = {
Default: '',
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,
};