From 9381b603b5fed67db7f9360a5ae6546be768bcbc Mon Sep 17 00:00:00 2001 From: Honza Cieslar <109418897+honzawashere@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:22:43 +0100 Subject: [PATCH] Version 3.0.6 - Reformatted code. --- scripts/database/PluginManager.js | 23 +- scripts/web/CSS/AmbientModeCSS.js | 5 + scripts/web/CSS/ColorChangerCSS.js | 24 +- scripts/web/CSS/ConsentCSS.js | 4 + scripts/web/CSS/HomepageCSS.js | 20 +- scripts/web/CSS/PlayerCSS.js | 8 +- scripts/web/CSS/PlaylistsCSS.js | 16 +- scripts/web/CSS/PluginsMenuCSS.js | 10 +- scripts/web/CSS/TitlebarCSS.js | 2 +- scripts/web/CSS/WhiteColorCSS.js | 1 + scripts/web/CSS/YouTubeSansCSS.js | 15 +- scripts/web/JS/BackgroundJS.js | 18 + scripts/web/JS/BetterFullscreenJS.js | 3 + scripts/web/JS/ChannelJS.js | 13 + scripts/web/JS/PlaylistJS.js | 35 +- scripts/web/Managers/SongInfo/ColorManager.js | 9 + .../SongInfo/ColorManager/changeColors.js | 11 + .../SongInfo/ColorManager/resetColors.js | 4 + .../SongInfo/ColorManager/setColors.js | 41 ++ .../SongInfo/ColorManager/updateColors.js | 12 + .../Managers/SongInfo/FullscreenManager.js | 3 + .../updateFullscreenMetadata.js | 13 + .../Managers/Window/css/injectAllStyles.js | 29 ++ .../Window/css/injectConsentStyles.js | 5 + scripts/web/Managers/Window/cssManager.js | 5 + .../Managers/Window/js/executeAllScripts.js | 14 + scripts/web/Managers/Window/jsManager.js | 3 + .../Managers/Window/network/bypassNetwork.js | 30 ++ scripts/web/Managers/Window/networkManager.js | 3 + scripts/web/Managers/Window/pluginManager.js | 5 + .../Managers/Window/plugins/loadPlugins.js | 44 ++ .../Managers/Window/plugins/preloadPlugins.js | 15 + scripts/web/Managers/Window/window/events.js | 3 + .../Window/window/events/WindowBlur.js | 12 + .../Window/window/events/WindowClose.js | 15 + .../window/events/WindowEnterFullscreen.js | 5 + .../Window/window/events/WindowFocus.js | 11 + .../window/events/WindowLeaveFullscreen.js | 5 + .../Window/window/events/WindowNavigation.js | 7 + .../Window/window/events/WindowRestore.js | 11 + .../Window/window/events/WindowUnload.js | 5 + .../Window/window/events/WindowUnmaximize.js | 6 + .../Window/window/events/eventManager.js | 21 + .../web/Managers/Window/window/ipcEvents.js | 3 + .../window/ipcEvents/AmbientModeEvent.js | 9 + .../ipcEvents/AudioVideoClickedEvent.js | 18 + .../window/ipcEvents/ButtonClickedEvent.js | 12 + .../Window/window/ipcEvents/CloseEvent.js | 20 + .../Window/window/ipcEvents/MaximizeEvent.js | 7 + .../Window/window/ipcEvents/MinimizeEvent.js | 12 + .../window/ipcEvents/NavigatePageBackEvent.js | 9 + .../Window/window/ipcEvents/PauseEvent.js | 7 + .../Window/window/ipcEvents/PlayEvent.js | 7 + .../window/ipcEvents/RateLimitedEvent.js | 13 + .../Window/window/ipcEvents/RestoreEvent.js | 5 + .../Window/window/ipcEvents/SeekEvent.js | 7 + .../Window/window/ipcEvents/SongInfoEvent.js | 7 + .../window/ipcEvents/ipcEventManager.js | 29 ++ scripts/web/Managers/Window/window/tray.js | 37 ++ .../web/Managers/Window/window/urlChange.js | 8 + scripts/web/Managers/Window/windowManager.js | 6 + scripts/web/SongInfoManager.js | 179 ++----- scripts/web/WebManager.js | 437 +----------------- 63 files changed, 776 insertions(+), 600 deletions(-) create mode 100644 scripts/web/CSS/AmbientModeCSS.js create mode 100644 scripts/web/JS/BackgroundJS.js create mode 100644 scripts/web/JS/BetterFullscreenJS.js create mode 100644 scripts/web/JS/ChannelJS.js create mode 100644 scripts/web/Managers/SongInfo/ColorManager.js create mode 100644 scripts/web/Managers/SongInfo/ColorManager/changeColors.js create mode 100644 scripts/web/Managers/SongInfo/ColorManager/resetColors.js create mode 100644 scripts/web/Managers/SongInfo/ColorManager/setColors.js create mode 100644 scripts/web/Managers/SongInfo/ColorManager/updateColors.js create mode 100644 scripts/web/Managers/SongInfo/FullscreenManager.js create mode 100644 scripts/web/Managers/SongInfo/FullscreenManager/updateFullscreenMetadata.js create mode 100644 scripts/web/Managers/Window/css/injectAllStyles.js create mode 100644 scripts/web/Managers/Window/css/injectConsentStyles.js create mode 100644 scripts/web/Managers/Window/cssManager.js create mode 100644 scripts/web/Managers/Window/js/executeAllScripts.js create mode 100644 scripts/web/Managers/Window/jsManager.js create mode 100644 scripts/web/Managers/Window/network/bypassNetwork.js create mode 100644 scripts/web/Managers/Window/networkManager.js create mode 100644 scripts/web/Managers/Window/pluginManager.js create mode 100644 scripts/web/Managers/Window/plugins/loadPlugins.js create mode 100644 scripts/web/Managers/Window/plugins/preloadPlugins.js create mode 100644 scripts/web/Managers/Window/window/events.js create mode 100644 scripts/web/Managers/Window/window/events/WindowBlur.js create mode 100644 scripts/web/Managers/Window/window/events/WindowClose.js create mode 100644 scripts/web/Managers/Window/window/events/WindowEnterFullscreen.js create mode 100644 scripts/web/Managers/Window/window/events/WindowFocus.js create mode 100644 scripts/web/Managers/Window/window/events/WindowLeaveFullscreen.js create mode 100644 scripts/web/Managers/Window/window/events/WindowNavigation.js create mode 100644 scripts/web/Managers/Window/window/events/WindowRestore.js create mode 100644 scripts/web/Managers/Window/window/events/WindowUnload.js create mode 100644 scripts/web/Managers/Window/window/events/WindowUnmaximize.js create mode 100644 scripts/web/Managers/Window/window/events/eventManager.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/AmbientModeEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/AudioVideoClickedEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/ButtonClickedEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/CloseEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/MaximizeEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/MinimizeEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/NavigatePageBackEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/PauseEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/PlayEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/RateLimitedEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/RestoreEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/SeekEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/SongInfoEvent.js create mode 100644 scripts/web/Managers/Window/window/ipcEvents/ipcEventManager.js create mode 100644 scripts/web/Managers/Window/window/tray.js create mode 100644 scripts/web/Managers/Window/window/urlChange.js create mode 100644 scripts/web/Managers/Window/windowManager.js diff --git a/scripts/database/PluginManager.js b/scripts/database/PluginManager.js index 8a459e5..5c74a84 100644 --- a/scripts/database/PluginManager.js +++ b/scripts/database/PluginManager.js @@ -1,51 +1,38 @@ -const store = require("electron-store"); -const {dialog} = require("electron"); -module.exports.createDatabase = () => { - const pkg = require("../../package.json") - const store = require("electron-store") +const pkg = require("../../package.json") +const store = require("electron-store") +module.exports.createDatabase = () => { const db = new store() if(db.get("app.version") !== pkg.version || db.get("app.version") === undefined) { db.set("app.version", pkg.version) - dialog.showMessageBox( { message: "Settings got moved. Now you can find them when you click on settings icon, or your profile icon and go to \"App Settings\" section.", title: "YouTube Music", buttons: ["OK"]}) } return db } module.exports.get = (name) => { - const store = require("electron-store") - const db = new store() return db.get("app.plugins." + name) === true } module.exports.getJSON = () => { - const store = require("electron-store") - const db = new store() return db.store } module.exports.set = (name, value) => { - const store = require("electron-store") - const db = new store() return db.set("app.plugins." + name, value) } module.exports.getLastSongInfo = () => { - const store = require("electron-store") - const db = new store() return db.get("app.songInfo") } -module.exports.setLastSongInfoDB = (value, time, list) => { - const store = require("electron-store") - - const info = { info: value, time: time, list: list } +module.exports.setLastSongInfoDB = (songInfo, time, list) => { + const info = { info: songInfo, time: time, list: list } const db = new store() return db.set("app.songInfo", info) diff --git a/scripts/web/CSS/AmbientModeCSS.js b/scripts/web/CSS/AmbientModeCSS.js new file mode 100644 index 0000000..0231100 --- /dev/null +++ b/scripts/web/CSS/AmbientModeCSS.js @@ -0,0 +1,5 @@ +module.exports.load = (window) => { + window.webContents.insertCSS(` + .ambient-mode-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; filter: blur(100px); z-index: -2; } + `) +} \ No newline at end of file diff --git a/scripts/web/CSS/ColorChangerCSS.js b/scripts/web/CSS/ColorChangerCSS.js index 5566aa9..80cfebc 100644 --- a/scripts/web/CSS/ColorChangerCSS.js +++ b/scripts/web/CSS/ColorChangerCSS.js @@ -1,24 +1,34 @@ module.exports.info = { name: "ColorChangerCSS" } + module.exports.load = (window) => { window.webContents.insertCSS(` - ytmusic-app-layout[player-page-open] #nav-bar-background.ytmusic-app-layout { background: var(--ytmusic-track-color2) !important } - ytmusic-player-page { background: var(--ytmusic-track-color2) !important } ytmusic-app-layout[player-page-open] ytmusic-app[is-bauhaus-sidenav-enabled] #guide-wrapper.ytmusic-app { background: var(--ytmusic-track-color2) !important } html { --ytmusic-track-color1: black; --ytmusic-track-color2: black; --ytmusic-playlist-color: black; } - ytmusic-app-layout[player-page-open] #nav-bar-background.ytmusic-app-layout { background: var(--ytmusic-track-color2) !important } tp-yt-paper-toast { background: var(--ytmusic-track-color2) !important } - ytmusic-app-layout[player-page-open] ytmusic-guide-renderer { background: var(--ytmusic-track-color2) !important } ytmusic-app-layout[player-page-open] #nav-bar-background.ytmusic-app-layout { left: 0 !important } - ytmusic-app-layout[player-visible] > [slot=player-bar], ytmusic-app-layout[player-visible] #player-bar-background.ytmusic-app-layout { background: var(--ytmusic-track-color1) !important; } - .html5-video-player:not(.ytp-transparent), .html5-video-player.unstarted-mode, .html5-video-player.ad-showing, .html5-video-player.ended-mode { background: var(--ytmusic-track-color2) !important } - ytmusic-player[player-ui-state="FULLSCREEN"] .html5-video-player, ytmusic-player[player-ui-state="MINIPLAYER"] .html5-video-player { background-color: black !important; } + .html5-video-player:not(.ytp-transparent), .html5-video-player.unstarted-mode, .html5-video-player.ad-showing, .html5-video-player.ended-mode { background: transparent !important } + ytmusic-player[player-ui-state="FULLSCREEN"] .html5-video-player, ytmusic-player[player-ui-state="MINIPLAYER"] .html5-video-player { background-color: transparent !important; } ytmusic-app-layout[player-visible] > [slot=player-bar], ytmusic-app-layout[player-visible] .ytmusic-menu-popup-renderer { --paper-listbox-background-color: var(--ytmusic-track-color2) !important } .duration.ytmusic-player-queue-item, .byline.ytmusic-player-queue-item { color: #ffffffb3 !important } .autoplay.ytmusic-tab-renderer .subtitle.ytmusic-tab-renderer { color: #ffffffb3 !important } .av-toggle.ytmusic-av-toggle { background: var(--ytmusic-track-color1) !important; } .song-button.ytmusic-av-toggle, .video-button.ytmusic-av-toggle { background: var(--ytmusic-track-color1) !important; } ytmusic-av-toggle[playback-mode=ATV_PREFERRED] .song-button.ytmusic-av-toggle, ytmusic-av-toggle[playback-mode=OMV_PREFERRED] .video-button.ytmusic-av-toggle { background-color: var(--ytmusic-av-toggle-active) !important; } + + ytmusic-app-layout[player-visible] #player-bar-background.ytmusic-app-layout { background: black !important; } + ytmusic-app-layout[player-page-open] #player-bar-background.ytmusic-app-layout { background: transparent !important; } + ytmusic-app-layout[player-visible] ytmusic-player-bar { background: black !important; } + ytmusic-app-layout[player-page-open] ytmusic-player-bar { background: transparent !important; } + + ytmusic-guide-renderer { background: transparent !important; } + + ytmusic-app-layout[player-page-open] #nav-bar-background.ytmusic-app-layout { background: transparent !important } + ytmusic-app-layout[is-bauhaus-sidenav-enabled] #mini-guide-background.ytmusic-app-layout { background: transparent !important } + + ytmusic-player-page { background: transparent !important } + + ytmusic-app-layout[player-page-open] { position: absolute; width: 100%; height: 100%; display: block; opacity: 1; background: linear-gradient(180deg,var(--ytmusic-track-color1) 0%, black 120%); overflow: hidden !important } `) } \ No newline at end of file diff --git a/scripts/web/CSS/ConsentCSS.js b/scripts/web/CSS/ConsentCSS.js index f66553a..c977578 100644 --- a/scripts/web/CSS/ConsentCSS.js +++ b/scripts/web/CSS/ConsentCSS.js @@ -1,3 +1,7 @@ +module.exports.info = { + name: "ConsentCSS" +} + module.exports.load = (window) => { window.webContents.insertCSS(` body#yDmH0d { background: #0e0e0e !important} diff --git a/scripts/web/CSS/HomepageCSS.js b/scripts/web/CSS/HomepageCSS.js index f9bfc01..2608d01 100644 --- a/scripts/web/CSS/HomepageCSS.js +++ b/scripts/web/CSS/HomepageCSS.js @@ -1,11 +1,11 @@ module.exports.info = { - name: "HomePageCSS", + name: "HomepageCSS", } module.exports.load = (window) => { window.webContents.insertCSS(`ytmusic-nav-bar[is-bauhaus-sidenav-enabled] .right-content.ytmusic-nav-bar { padding-right: 30px !important } ytmusic-cast-button { display: none !important } ytmusic-nav-bar[is-bauhaus-sidenav-enabled] .right-content.ytmusic-nav-bar { right: 0px !important } - ytmusic-app[is-bauhaus-sidenav-enabled] #guide-wrapper.ytmusic-app { background: var(--ytmusic-nav-bar) !important; border-right: 0px solid transparent !important } + ytmusic-app[is-bauhaus-sidenav-enabled] #guide-wrapper.ytmusic-app { background: transparent !important; border-right: 0px solid transparent !important } ytmusic-app-layout[is-bauhaus-sidenav-enabled] #nav-bar-background.ytmusic-app-layout { border-bottom: 0px solid transparent !important; transition: opacity 0s !important; } ytmusic-app-layout[is-bauhaus-sidenav-enabled] #nav-bar-divider.ytmusic-app-layout { border-top: 0px solid transparent !important } ytmusic-app-layout[is-bauhaus-sidenav-enabled] #mini-guide-background.ytmusic-app-layout {border-right: 0px solid transparent !important } @@ -15,7 +15,7 @@ module.exports.load = (window) => { .title.ytmusic-carousel-shelf-basic-header-renderer { font-size: 25px !important } #contents.ytmusic-section-list-renderer>ytmusic-carousel-shelf-renderer.ytmusic-section-list-renderer:not(:last-child), #contents.ytmusic-section-list-renderer>ytmusic-immersive-carousel-shelf-renderer.ytmusic-section-list-renderer:not(:last-child) { margin-bottom: 0px !important } ytmusic-mealbar-promo-renderer[dialog][dialog][dialog] { display: none !important } - div#guide-content { background: black !important } + div#guide-content { background: transparent !important } tp-yt-paper-listbox.ytmusic-menu-popup-renderer { border: 1px solid transparent !important; border-radius: 8px !important } .yt-simple-endpoint, .logo.ytmusic-logo { -webkit-user-drag: none !important } ytmusic-app-layout[player-page-open] ytmusic-search-box[is-bauhaus-sidenav-enabled][opened] .search-box.ytmusic-search-box, ytmusic-app-layout[player-page-open] ytmusic-search-box[is-bauhaus-sidenav-enabled] #suggestion-list.ytmusic-search-box, ytmusic-app-layout[player-page-open] ytmusic-search-suggestion { background: var(--ytmusic-track-color1) !important } @@ -32,5 +32,19 @@ module.exports.load = (window) => { .content.ytmusic-tabbed-search-results-renderer { padding: 8px 0 0 !important } ytmusic-search-box { box-shadow: none !important; } .menu.ytmusic-player-bar { --iron-icon-fill-color: #ffffff !important; } + ytd-multi-page-menu-renderer.ytmusic-popup-container { background: var(--ytmusic-track-color2) !important;--yt-spec-call-to-action: white !important;--yt-endpoint-hover-color: lightgrey !important; } + yt-icon.style-scope.ytd-compact-link-renderer { color: white !important } + ytmusic-app-layout[not-maximized] div#playlists {height: calc(100% - 75px);overflow-y: scroll;} + ytmusic-nav-bar[is-bauhaus-sidenav-enabled][is-search-page] .center-content.ytmusic-nav-bar { width: 80% !important } + .content.ytmusic-tabbed-search-results-renderer { margin: 0 0 !important } + .tab-container.ytmusic-tabs { margin: 0 0 !important } + #chips.ytmusic-chip-cloud-renderer { margin-left: 40px !important } + ytmusic-tabs { margin-left: 40px; } + ytmusic-chip-cloud-renderer.ytmusic-section-list-renderer { margin: 0 0 !important } + .strapline.ytmusic-carousel-shelf-basic-header-renderer, .strapline.ytmusic-shelf-renderer { color: #ffffffb3 !important } + .tab.ytmusic-tabs {text-transform: capitalize !important;} + ytmusic-section-list-renderer[page-type=MUSIC_PAGE_TYPE_LIBRARY_CONTENT_LANDING_PAGE] ytmusic-side-aligned-item-renderer.ytmusic-section-list-renderer, ytmusic-section-list-renderer[page-type=MUSIC_PAGE_TYPE_DOWNLOADS_CONTENT_LANDING_PAGE] ytmusic-side-aligned-item-renderer.ytmusic-section-list-renderer, ytmusic-section-list-renderer[page-type=MUSIC_PAGE_TYPE_PRIVATELY_OWNED_CONTENT_LANDING_PAGE] ytmusic-side-aligned-item-renderer.ytmusic-section-list-renderer { margin: 26px 0 36px !important; } + #container.ytmusic-multi-select-menu-renderer { border-radius: 16px !important; background: #0e0e0e !important} + #items.ytmusic-multi-select-menu-renderer {background: #0e0e0e !important} `) } \ No newline at end of file diff --git a/scripts/web/CSS/PlayerCSS.js b/scripts/web/CSS/PlayerCSS.js index 7582e3f..ea23bd4 100644 --- a/scripts/web/CSS/PlayerCSS.js +++ b/scripts/web/CSS/PlayerCSS.js @@ -12,14 +12,12 @@ module.exports.load = (window) => { .content.ytmusic-player-page { padding: 32px var(--ytmusic-player-page-horizontal-padding) 32px !important; } .description.ytmusic-description-shelf-renderer { font-size: 18px !important; font-weight: 500 !important } .video-disable-performance { width: 0px !important; height: 0px !important } - .autoplay.ytmusic-player-queue { display: none !important } .ytp-player-content.ytp-iv-player-content { display: none !important } tp-yt-paper-tab tp-yt-paper-tab .tp-yt-paper-tab[style-target=tab-content], .tp-yt-paper-tab[style-target=tab-content] { text-transform: none; font-size: 15px; } ytmusic-app-layout[player-fullscreened] > [slot=player-bar] { width: 100% !important; } .ytp-chrome-top-buttons { display: none !important } #buttons.ytmusic-queue-header-renderer { margin-left: 10px !important } button.yt-spec-button-shape-next.yt-spec-button-shape-next--filled.yt-spec-button-shape-next--call-to-action.yt-spec-button-shape-next--size-m { margin-top: 10px !important } - .song-media-controls.ytmusic-player { padding: 0px !important; position: absolute; top: 50% !important; left: 50% !important; transform: translate(-50%,-50%) !important } .top-row-buttons.ytmusic-player {margin-top: 8px !important; margin-right: 8px !important;} ytmusic-player-bar[player-fullscreened_] { --ytmusic-player-bar-height: 72px !important; --ytmusic-like-button-size: none !important; --ytmusic-menu-renderer-button-size: none !important; } .thumbnail-overlay.ytmusic-player-queue-item[play-button-state=loading], .thumbnail-overlay.ytmusic-player-queue-item[play-button-state=playing], .thumbnail-overlay.ytmusic-player-queue-item[play-button-state=paused] { opacity: 0 !important } @@ -36,10 +34,14 @@ module.exports.load = (window) => { .song-info-container {position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);} .song-image-container {width: 300px;height: 300px} .song-image-container img {width: auto;height: 300px;border:1px solid transparent;border-radius:8px;position:absolute;left: 50%;transform:translate(-50%)} - ytmusic-player {background-color: black !important} + ytmusic-player {background-color: transparent !important} .song-data-container h1 {text-align: center;padding: 10px 0px 0px;font-size: 26px;font-weight: 400;} .song-data-container h3 {text-align: center;padding: 0px;font-size: 20px;font-weight: 400;color: #ffffffd8;} ytmusic-player-page[player-fullscreened_] .av.ytmusic-player-page { visibility: hidden !important } ytmusic-app-layout[player-fullscreened] div#fullscreen-container {display: block;} + ytmusic-player-page[player-fullscreened] .side-panel.ytmusic-player-page {display: none;} + .autoplay.ytmusic-player-queue .title.ytmusic-player-queue { opacity: 1 !important; color: white } + ytmusic-app-layout[player-page-open] ytmusic-carousel-shelf-renderer { margin-left: 0px !important } + ytmusic-app-layout[player-page-open] iron-selector#chips { margin-left: 0px !important; } `) } \ No newline at end of file diff --git a/scripts/web/CSS/PlaylistsCSS.js b/scripts/web/CSS/PlaylistsCSS.js index 8972246..e187790 100644 --- a/scripts/web/CSS/PlaylistsCSS.js +++ b/scripts/web/CSS/PlaylistsCSS.js @@ -8,6 +8,20 @@ module.exports.load = (window) => { "#contents.ytmusic-playlist-shelf-renderer>*.ytmusic-playlist-shelf-renderer:not(:last-child) { border-bottom: 1px solid transparent !important }", "ytmusic-app-layout[player-page-open] .ytmusic-app-content {display: none;}", "ytmusic-app-layout[player-page-open] ytmusic-app-layout > [slot=player-bar] {width: 100vw !important;}", - "ytmusic-detail-header-renderer { background: linear-gradient(180deg, var(--ytmusic-playlist-color), transparent) !important } " + "ytmusic-detail-header-renderer { background: linear-gradient(180deg, var(--ytmusic-playlist-color), transparent) !important }", + "ytmusic-browse-response[is-bauhaus-sidenav-enabled] #header.ytmusic-browse-response ytmusic-header-renderer.ytmusic-browse-response, ytmusic-browse-response[is-bauhaus-sidenav-enabled] #header.ytmusic-browse-response ytmusic-detail-header-renderer.ytmusic-browse-response, ytmusic-browse-response[is-bauhaus-sidenav-enabled] #header.ytmusic-browse-response ytmusic-editable-playlist-detail-header-renderer.ytmusic-browse-response, ytmusic-browse-response[is-bauhaus-sidenav-enabled] #header.ytmusic-browse-response ytmusic-migration-header-renderer.ytmusic-browse-response {padding-left:0px !important;margin-left:var(--ytmusic-guide-width) !important}", + "ytmusic-playlist-form { background: var(--ytmusic-playlist-color-darker) !important; border-radius: 16px !important }", + ".content-container.ytmusic-detail-header-renderer { margin: var(--ytmusic-divider-height) 40px 0 !important}", + "#contents.ytmusic-section-list-renderer>*.ytmusic-section-list-renderer:not(.fullbleed) { margin-left: 40px !important}", + "ytmusic-carousel-shelf-renderer { margin-left: -100px; position: relative; }", + ".image.ytmusic-visual-header-renderer { left: 240px }", + "ytmusic-immersive-header-renderer[is-bauhaus-sidenav-enabled] .image.ytmusic-immersive-header-renderer { margin-left: 240px !important }", + "ytmusic-carousel-shelf-renderer.style-scope.ytmusic-add-to-playlist-renderer { margin-left: 0 !important }", + "ytmusic-carousel-shelf-renderer.ytmusic-add-to-playlist-renderer { padding: 0 20px !important }", + "ytmusic-add-to-playlist-renderer.style-scope.ytmusic-popup-container { margin: 0 !important }", + "yt-icon.ytmusic-playlist-add-to-option-renderer { color: white !important }", + ".section-heading.ytmusic-add-to-playlist-renderer { font-size: 16px !important }", + "ytmusic-add-to-playlist-renderer { background: #0e0e0e !important; border: 1px solid transparent !important; border-radius: 16px !important }", + "tp-yt-paper-dialog { background: #0e0e0e !important; border-radius: 16px}" ].join("\n")) } \ No newline at end of file diff --git a/scripts/web/CSS/PluginsMenuCSS.js b/scripts/web/CSS/PluginsMenuCSS.js index 8e0a94e..05bf63a 100644 --- a/scripts/web/CSS/PluginsMenuCSS.js +++ b/scripts/web/CSS/PluginsMenuCSS.js @@ -1,3 +1,7 @@ +module.exports.info = { + name: "PluginsMenuCSS" +} + module.exports.load = (window) => { window.webContents.insertCSS(` .hidden { display: none } @@ -5,13 +9,13 @@ module.exports.load = (window) => { .plugins-dialog {position: fixed;top: 50%;left: 50%;width: 50%;height: 50%;background:var(--ytmusic-track-color1);transform: translate(-50%,-50%);border:1px solid transparent;border-radius: 8px;} .plugins-title {height: 15%; border-bottom: 1px solid white; padding: 0px 20px;padding-bottom: 0;height: 10%;} .plugins-title h1 {font-size: 20px !important;color:white;font-family: 'Roboto';font-weight: 400;position:relative;margin:0;color:white;border-bottom:white;width:fit-content;margin-top:15px} - .close-menu {width: 24px;height: 24px;position: absolute;top:10px;right:20px} - .plugins-options {color: white;font-family: 'Roboto';position: absolute;top: 15%;bottom: 0;width: 20%;border-right: 1px solid white} + .close-menu {width: 24px;height: 24px;position: absolute;top:15px;right:20px} + .plugins-options {color: white;font-family: 'Roboto';position: absolute;top: calc(10% + 15px);bottom: 0;width: 20%;border-right: 1px solid white} .option {width: 100%;margin: auto;height: 48px;} .option:hover {background: #ffffffb3;color:var(--ytmusic-track-color1);cursor: pointer;} .option-selected { background:#ffffffa6;color:var(--ytmusic-track-color1);} .option h1 {font-size: 15px;font-weight: 400;margin: 0;position: relative;top: 50%;transform: translate(20px,-50%);} - .tab {position: absolute;top: 15%;bottom: 0;left: 20%;right: 0;} + .tabxd {position: absolute;top: 15%;bottom: 0;left: 20%;right: 0;} .tabc {padding: 0 20px !important;height: 100%;overflow-y: scroll;} .section h1 {color: white;border-bottom: 1px solid white;} .setting {color: white;position:relative;} diff --git a/scripts/web/CSS/TitlebarCSS.js b/scripts/web/CSS/TitlebarCSS.js index 91f462c..1a59c7b 100644 --- a/scripts/web/CSS/TitlebarCSS.js +++ b/scripts/web/CSS/TitlebarCSS.js @@ -34,7 +34,7 @@ module.exports.load = (window) => { ytmusic-section-list-renderer.style-scope.ytmusic-browse-response { margin-top: 32px; } div#sections { margin-top: 32px; } ytmusic-tabs#tabs { margin-top: 32px; } - .content.style-scope.ytmusic-tabbed-search-results-renderer { margin-top: 32px; } + .content.style-scope.ytmusic-tabbed-search-results-renderer { margin-top: 32px !important; } div#back-button img { width: 16px; } ytmusic-header-renderer.style-scope.ytmusic-browse-response {margin-top: 32px;} ytd-multi-page-menu-renderer div#container > div#sections {margin-top: 0px !important;} diff --git a/scripts/web/CSS/WhiteColorCSS.js b/scripts/web/CSS/WhiteColorCSS.js index e3e28a4..c812c8c 100644 --- a/scripts/web/CSS/WhiteColorCSS.js +++ b/scripts/web/CSS/WhiteColorCSS.js @@ -1,6 +1,7 @@ module.exports.info = { name: "WhiteColorCSS" } + module.exports.load = (window) => { window.webContents.insertCSS(` #primaryProgress.tp-yt-paper-progress { background: white !important } diff --git a/scripts/web/CSS/YouTubeSansCSS.js b/scripts/web/CSS/YouTubeSansCSS.js index e052789..33d31e5 100644 --- a/scripts/web/CSS/YouTubeSansCSS.js +++ b/scripts/web/CSS/YouTubeSansCSS.js @@ -44,7 +44,18 @@ module.exports.load = (window) => { .autoplay.ytmusic-tab-renderer .subtitle.ytmusic-tab-renderer {font-family: "YouTube Sans",sans-serif !important} .song-button.ytmusic-av-toggle, .video-button.ytmusic-av-toggle {font-family: "YouTube Sans",sans-serif !important} #info.yt-player-error-message-renderer {font-family: "YouTube Sans",sans-serif !important} - .song-data-container h1 {font-family: "YouTube Sans",sans-serif !important}} - .song-data-container h3 {font-family: "YouTube Sans",sans-serif !important}} + .song-data-container h1 {font-family: "YouTube Sans",sans-serif !important} + .song-data-container h3 {font-family: "YouTube Sans",sans-serif !important} + .floated-label-placeholder.tp-yt-paper-input-container {font-family: "YouTube Sans",sans-serif !important} + .autoplay.ytmusic-player-queue .title.ytmusic-player-queue {font-family: "YouTube Sans",sans-serif !important} + .strapline.ytmusic-shelf-renderer {font-family: "YouTube Sans",sans-serif !important} + ytmusic-carousel-shelf-basic-header-renderer[carousel-style=MUSIC_CAROUSEL_SHELF_BASIC_HEADER_STYLE_TITLE_TWO] .title.ytmusic-carousel-shelf-basic-header-renderer {font-family: "YouTube Sans",sans-serif !important} + .section-heading.ytmusic-add-to-playlist-renderer {font-family: "YouTube Sans",sans-serif !important} + #title.ytmusic-playlist-add-to-option-renderer {font-family: "YouTube Sans",sans-serif !important} + .privacy.ytmusic-playlist-add-to-option-renderer, .byline.ytmusic-playlist-add-to-option-renderer {font-family: "YouTube Sans",sans-serif !important} + .tab.ytmusic-tabs {font-family: "YouTube Sans",sans-serif !important;} + button.ytmusic-sort-filter-button-renderer {font-family: "YouTube Sans",sans-serif !important;} + .text.ytmusic-menu-title-renderer {font-family: "YouTube Sans",sans-serif !important;} + .text.ytmusic-multi-select-menu-item-renderer {font-family: "YouTube Sans",sans-serif !important;} `) } \ No newline at end of file diff --git a/scripts/web/JS/BackgroundJS.js b/scripts/web/JS/BackgroundJS.js new file mode 100644 index 0000000..5c92adb --- /dev/null +++ b/scripts/web/JS/BackgroundJS.js @@ -0,0 +1,18 @@ +module.exports.load = (window) => { + window.webContents.executeJavaScript(` + // This creates our MutationObserver() which will get disconnected after receiving our playlist section and will set that section's id to "playlists" + let PlaylistsObserver = new MutationObserver(() => { + // If our playlist section exists, continue with the code + if(document.querySelector("ytmusic-guide-renderer > #sections > ytmusic-guide-section-renderer:nth-child(2) > #items")) { + // Disconnect our observer + PlaylistsObserver.disconnect() + + // Set id of playlist container to "playlists" so we can edit it with div#playlists CSS + document.querySelector("ytmusic-guide-renderer > #sections > ytmusic-guide-section-renderer:nth-child(2) > #items").id = "playlists" + } + }) + + // This waits for an change occuring inside of guide renderer's sections so we can find then our guide-section-renderer + PlaylistsObserver.observe(document.querySelector("ytmusic-guide-renderer > #sections"), { attributes: true, childList: true, subtree: true }) + `) +} \ No newline at end of file diff --git a/scripts/web/JS/BetterFullscreenJS.js b/scripts/web/JS/BetterFullscreenJS.js new file mode 100644 index 0000000..23b229f --- /dev/null +++ b/scripts/web/JS/BetterFullscreenJS.js @@ -0,0 +1,3 @@ +module.exports.load = (window) => { + window.webContents.executeJavaScript(`document.querySelector("#layout").setAttribute("disable-better-fullscreen", "")`) +} \ No newline at end of file diff --git a/scripts/web/JS/ChannelJS.js b/scripts/web/JS/ChannelJS.js new file mode 100644 index 0000000..26c5c92 --- /dev/null +++ b/scripts/web/JS/ChannelJS.js @@ -0,0 +1,13 @@ +module.exports.info = { + include: "/channel" +} + +module.exports.load = (window) => { + window.webContents.insertCSS(`ytmusic-visual-header-renderer[is-bauhaus-sidenav-enabled] .content-container.ytmusic-visual-header-renderer { padding-left: 120px !important }`) + window.webContents.insertCSS(`.metadata.ytmusic-visual-header-renderer { display: block !important }`) +} + +module.exports.clear = (window) => { + window.webContents.insertCSS(`ytmusic-visual-header-renderer[is-bauhaus-sidenav-enabled] .content-container.ytmusic-visual-header-renderer { padding-left: 240px !important }`) + window.webContents.insertCSS(`.metadata.ytmusic-visual-header-renderer { display: flex !important }`) +} \ No newline at end of file diff --git a/scripts/web/JS/PlaylistJS.js b/scripts/web/JS/PlaylistJS.js index 1550104..9211dab 100644 --- a/scripts/web/JS/PlaylistJS.js +++ b/scripts/web/JS/PlaylistJS.js @@ -1,21 +1,36 @@ +const Vibrant = require('node-vibrant') + module.exports.info = { include: "/playlist" } + module.exports.load = (window) => { - window.webContents.executeJavaScript("document.querySelector(\"ytmusic-cropped-square-thumbnail-renderer > yt-img-shadow > img\").src").then(url => { - const Vibrant = require('node-vibrant') + // Get URL of opened playlist's cover image + window.webContents.executeJavaScript("if(document.querySelector(\"ytmusic-cropped-square-thumbnail-renderer > yt-img-shadow > img\")) { document.querySelector(\"ytmusic-cropped-square-thumbnail-renderer > yt-img-shadow > img\").src }").then(url => { + // When the playlist image is blank + if (url === undefined) { window.webContents.insertCSS(`html { --ytmusic-playlist-color: "#000000" !important }`) } + if (url.includes("base64")) { window.webContents.insertCSS(`html { --ytmusic-playlist-color: "#000000" !important }`) } - Vibrant.from(url).getPalette((err, palette) => { - try { - window.webContents.executeJavaScript(`document.querySelector('#nav-bar-background').style.background = '${palette.DarkVibrant.hex}'`) - window.webContents.insertCSS(`html { --ytmusic-playlist-color: ${palette.DarkVibrant.hex} !important }`) - } catch(e) { - if(e) return - } - }) + if (!url.includes("base64")) { + // Get colors using node-vibrant + Vibrant.from(url).getPalette((err, palette) => { + try { + // Set the navigation bar color to DarkVibrant.hex and set our variable --ytmusic-playlist-color to DarkVibrant.hex + window.webContents.executeJavaScript(`document.querySelector('#nav-bar-background').style.background = '${palette.DarkVibrant.hex}'`) + window.webContents.insertCSS(`html { --ytmusic-playlist-color: ${palette.DarkVibrant.hex} !important }`) + } catch (e) { + // When the palette was not successfully created and DarkVibrant.hex is undefined + if (e) { + // Clear the color of our navigation bar + window.webContents.insertCSS(`html { --ytmusic-playlist-color: "#000000" !important }`) + } + } + }) + } }) } module.exports.clear = (window) => { + // Clear the color of our navigation bar window.webContents.executeJavaScript("document.querySelector('#nav-bar-background').style.background = 'black'") } \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/ColorManager.js b/scripts/web/Managers/SongInfo/ColorManager.js new file mode 100644 index 0000000..e7c456e --- /dev/null +++ b/scripts/web/Managers/SongInfo/ColorManager.js @@ -0,0 +1,9 @@ +const changeColors = require("./ColorManager/changeColors") +const resetColors = require("./ColorManager/resetColors") +const setColors = require("./ColorManager/setColors") +const updateColors = require("./ColorManager/updateColors") + +module.exports.changeColors = (window, url) => { changeColors(window, url) } +module.exports.resetColors = (window) => { resetColors(window) } +module.exports.setColors = (window, videoMode, playerInfo) => { setColors(window, videoMode, playerInfo) } +module.exports.updateColors = (window) => { updateColors(window) } \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/ColorManager/changeColors.js b/scripts/web/Managers/SongInfo/ColorManager/changeColors.js new file mode 100644 index 0000000..50de8cd --- /dev/null +++ b/scripts/web/Managers/SongInfo/ColorManager/changeColors.js @@ -0,0 +1,11 @@ +const Vibrant = require('node-vibrant') + +module.exports = (window, url) => { + if(url.includes("base64")) { + return + } + + Vibrant.from(url).getPalette((err, palette) => { + window.webContents.insertCSS(`html { --ytmusic-track-color1: ${palette.DarkVibrant.hex} !important; --ytmusic-track-color2: ${palette.DarkVibrant.hex} !important }`) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/ColorManager/resetColors.js b/scripts/web/Managers/SongInfo/ColorManager/resetColors.js new file mode 100644 index 0000000..50a5a78 --- /dev/null +++ b/scripts/web/Managers/SongInfo/ColorManager/resetColors.js @@ -0,0 +1,4 @@ +module.exports = (window) => { + // Set colors to black + window.webContents.insertCSS(`html { --ytmusic-track-color1: black !important; --ytmusic-track-color2: black !important }`) +} \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/ColorManager/setColors.js b/scripts/web/Managers/SongInfo/ColorManager/setColors.js new file mode 100644 index 0000000..6261376 --- /dev/null +++ b/scripts/web/Managers/SongInfo/ColorManager/setColors.js @@ -0,0 +1,41 @@ +const {get} = require("../../../../database/PluginManager"); + +module.exports = (window, videoMode, playerInfo) => { + const {changeColors, resetColors} = require("../ColorManager"); + + // If videoMode is true + if (videoMode) { + // If color-changer is enabled for videos and enabled globally + if (get("color-changer") === true && get("color-changer-videos") === true) { + // Change colors + changeColors(window, playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[0].url.split("?")[0]) + } + + // If color-changer is not enabled for videos or not enabled globally + if (get("color-changer") !== true || get("color-changer-videos") !== true) { + // Reset colors + resetColors(window) + } + } + + // If videoMode is false + if (!videoMode) { + // If musicVideoType is "MUSIC_VIDEO_TYPE_PRIVATELY_OWNED_TRACK", color-changer is enabled for private songs and is enabled globally + if (playerInfo.playerResponse.videoDetails.musicVideoType === "MUSIC_VIDEO_TYPE_PRIVATELY_OWNED_TRACK" && get("color-changer-private-songs") === true && get("color-changer") === true) { + // Change colors + changeColors(window, playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[3].url) + } else { + // Reset colors + resetColors(window) + } + + // If color-changer is enabled globally and is enabled for songs + if (get("color-changer") === true && get("color-changer-songs") === true) { + // Change colors + changeColors(window, playerInfo.thumbnail.thumbnails[2].url) + } else { + // Reset colors + resetColors(window) + } + } +} \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/ColorManager/updateColors.js b/scripts/web/Managers/SongInfo/ColorManager/updateColors.js new file mode 100644 index 0000000..063fc56 --- /dev/null +++ b/scripts/web/Managers/SongInfo/ColorManager/updateColors.js @@ -0,0 +1,12 @@ +module.exports = (window) => { + const {setColors} = require("../ColorManager"); + + window.webContents.executeJavaScript("document.querySelector(\"#player\").__data").then(currentPlayerInfo => { + try { + if (currentPlayerInfo.playerResponse.videoDetails === null) return + setColors(window, currentPlayerInfo.videoMode, currentPlayerInfo) + } catch (error) { + return console.log(error) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/FullscreenManager.js b/scripts/web/Managers/SongInfo/FullscreenManager.js new file mode 100644 index 0000000..cfe13e5 --- /dev/null +++ b/scripts/web/Managers/SongInfo/FullscreenManager.js @@ -0,0 +1,3 @@ +const updateFullscreenMetadata = require("./FullscreenManager/updateFullscreenMetadata") + +module.exports.updateFullscreenMetadata = (window, playerInfo) => { updateFullscreenMetadata(window, playerInfo) } \ No newline at end of file diff --git a/scripts/web/Managers/SongInfo/FullscreenManager/updateFullscreenMetadata.js b/scripts/web/Managers/SongInfo/FullscreenManager/updateFullscreenMetadata.js new file mode 100644 index 0000000..dc3f189 --- /dev/null +++ b/scripts/web/Managers/SongInfo/FullscreenManager/updateFullscreenMetadata.js @@ -0,0 +1,13 @@ +module.exports = (window, playerInfo) => { + window.webContents.executeJavaScript(` + var trusted_policy = trustedTypes.createPolicy("myPolicy", { + createHTML: (string) => { + return string; + } + }) + + document.querySelector("#fullscreen_img").setAttribute("src", document.querySelector("#song-image > yt-img-shadow > img").src) + document.querySelector("#song_title_fullscreen").innerHTML = trusted_policy.createHTML("${playerInfo.playerResponse.videoDetails.title}") + document.querySelector("#song_author_fullscreen").innerHTML = trusted_policy.createHTML("${playerInfo.playerResponse.videoDetails.author}") + `) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/css/injectAllStyles.js b/scripts/web/Managers/Window/css/injectAllStyles.js new file mode 100644 index 0000000..c6f6e10 --- /dev/null +++ b/scripts/web/Managers/Window/css/injectAllStyles.js @@ -0,0 +1,29 @@ +module.exports = (window) => { + const {get} = require("../../../../database/PluginManager"); + + const AmbientModeCSS = require("../../../CSS/AmbientModeCSS") + const ColorChangerCSS = require("../../../CSS/ColorChangerCSS"); + const HomepageCSS = require("../../../CSS/HomepageCSS"); + const PlayerCSS = require("../../../CSS/PlayerCSS"); + const PlaylistsCSS = require("../../../CSS/PlaylistsCSS"); + const PluginsMenuCSS = require("../../../CSS/PluginsMenuCSS"); + const TitlebarCSS = require("../../../CSS/TitlebarCSS"); + const WhiteColorCSS = require("../../../CSS/WhiteColorCSS"); + const YouTubeSansCSS = require("../../../CSS/YouTubeSansCSS"); + const GamerModeCSS = require("../../../CSS/GamerModeCSS"); + + AmbientModeCSS.load(window) + ColorChangerCSS.load(window); + HomepageCSS.load(window); + PlayerCSS.load(window); + PlaylistsCSS.load(window); + PluginsMenuCSS.load(window); + TitlebarCSS.load(window); + WhiteColorCSS.load(window); + + if (get("disable-yt-sans") === false) { + YouTubeSansCSS.load(window); + } + + GamerModeCSS.load(window); +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/css/injectConsentStyles.js b/scripts/web/Managers/Window/css/injectConsentStyles.js new file mode 100644 index 0000000..f3cd7a0 --- /dev/null +++ b/scripts/web/Managers/Window/css/injectConsentStyles.js @@ -0,0 +1,5 @@ +module.exports = (window) => { + const ConsentCSS = require("../../../CSS/ConsentCSS"); + + ConsentCSS.load(window); +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/cssManager.js b/scripts/web/Managers/Window/cssManager.js new file mode 100644 index 0000000..43bab24 --- /dev/null +++ b/scripts/web/Managers/Window/cssManager.js @@ -0,0 +1,5 @@ +const injectAllStyles = require("./css/injectAllStyles") +const injectConsentStyles = require("./css/injectConsentStyles") + +module.exports.injectAllStyles = (window) => { injectAllStyles(window) } +module.exports.injectConsentStyles = (window) => { injectConsentStyles(window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/js/executeAllScripts.js b/scripts/web/Managers/Window/js/executeAllScripts.js new file mode 100644 index 0000000..cf566b6 --- /dev/null +++ b/scripts/web/Managers/Window/js/executeAllScripts.js @@ -0,0 +1,14 @@ +module.exports = (window) => { + const TitlebarJS = require("../../../JS/TitlebarJS"); + const BackgroundJS = require("../../../JS/BackgroundJS"); + const BetterFullscreenJS = require("../../../JS/BetterFullscreenJS") + + const {get} = require("../../../../database/PluginManager"); + + TitlebarJS.load(window); + BackgroundJS.load(window); + + if (get("disable-better-fullscreen") === true) { + BetterFullscreenJS.load(window) + } +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/jsManager.js b/scripts/web/Managers/Window/jsManager.js new file mode 100644 index 0000000..4c63385 --- /dev/null +++ b/scripts/web/Managers/Window/jsManager.js @@ -0,0 +1,3 @@ +const executeAllScripts = require("./js/executeAllScripts") + +module.exports.executeAllScripts = (window) => { executeAllScripts(window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/network/bypassNetwork.js b/scripts/web/Managers/Window/network/bypassNetwork.js new file mode 100644 index 0000000..28b3d09 --- /dev/null +++ b/scripts/web/Managers/Window/network/bypassNetwork.js @@ -0,0 +1,30 @@ +const {windows} = require("electron-is"); +module.exports = (window) => { + // User agents + const oldUserAgent = window.webContents.userAgent; + + // User agents prepared for different OSes + const userAgents = { + windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + } + + const sec_ch_ua = `"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"` + + // Happens when our session is about to send request + window.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => { + // If URL is for Google accounts + if (window.webContents.getURL().startsWith('https://accounts.google.com') && details.url.startsWith('https://accounts.google.com')) { + // Keep the old headers + details.requestHeaders['User-Agent'] = oldUserAgent; + } else { + // If platform is Windows, change the headers (Linux and Mac not supported yet) + if (windows()) { + details.requestHeaders['User-Agent'] = userAgents["windows"] + details.requestHeaders['Sec-Ch-Ua'] = sec_ch_ua + } + } + + // Send the callback + cb({requestHeaders: details.requestHeaders}); + }); +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/networkManager.js b/scripts/web/Managers/Window/networkManager.js new file mode 100644 index 0000000..0df9f9d --- /dev/null +++ b/scripts/web/Managers/Window/networkManager.js @@ -0,0 +1,3 @@ +const bypassNetwork = require("../Window/network/bypassNetwork") + +module.exports.bypassNetwork = (window) => { bypassNetwork(window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/pluginManager.js b/scripts/web/Managers/Window/pluginManager.js new file mode 100644 index 0000000..8369c3b --- /dev/null +++ b/scripts/web/Managers/Window/pluginManager.js @@ -0,0 +1,5 @@ +const loadPlugins = require("./plugins/loadPlugins") +const preloadPlugins = require("./plugins/preloadPlugins") + +module.exports.loadPlugins = (window) => { loadPlugins(window) } +module.exports.preloadPlugins = (window) => { preloadPlugins(window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/plugins/loadPlugins.js b/scripts/web/Managers/Window/plugins/loadPlugins.js new file mode 100644 index 0000000..eda5019 --- /dev/null +++ b/scripts/web/Managers/Window/plugins/loadPlugins.js @@ -0,0 +1,44 @@ +module.exports = (window) => { + const {get} = require("../../../../database/PluginManager"); + const color_changer = require("../../../../../plugins/color-changer/Plugin"); + const discord_rpc = require("../../../../../plugins/discord-rpc/Plugin"); + const downloader = require("../../../../../plugins/downloader/Plugin"); + const adblocker = require("../../../../../plugins/adblocker/Plugin"); + const bypass_premium_restrictions = require("../../../../../plugins/bypass-premium-restrictions/Plugin"); + + // Do not inject until we get the actual YouTube Music page. + if (window.webContents.getURL().includes("https://music.youtube.com/")) { + window.webContents.executeJavaScript("ytcfg.data_.IS_SUBSCRIBER").then(isPremium => { + if (isPremium) { + const store = require("electron-store") + const s = new store() + s.set("app.premium-user", true) + if (get("show-premium-tag") === true) { + window.webContents.on("page-title-updated", () => { + window.setTitle(window.getTitle().replace("YouTube Music", "YouTube Music Premium")) + }) + } + + if (get("color-changer") === true) color_changer.enable(window); + if (get("discord-rpc") === true) discord_rpc.enable(window); + downloader.enable(window); + return + } + if (!isPremium) { + const store = require("electron-store") + const s = new store() + s.set("app.premium-user", false) + window.setTitle("YouTube Music") + window.webContents.on("page-title-updated", () => { + window.setTitle("YouTube Music") + }) + + if (get("adblocker") === true) adblocker.enable(window); + if (get("disable-premium-upgrade") === true || get("disable-miniplayer") === true) bypass_premium_restrictions.enable(window); + if (get("color-changer") === true) color_changer.enable(window); + if (get("discord-rpc") === true) discord_rpc.enable(window); + downloader.enable(window); + } + }) + } +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/plugins/preloadPlugins.js b/scripts/web/Managers/Window/plugins/preloadPlugins.js new file mode 100644 index 0000000..f471944 --- /dev/null +++ b/scripts/web/Managers/Window/plugins/preloadPlugins.js @@ -0,0 +1,15 @@ +module.exports = (window) => { + const adblocker = require("../../../../../plugins/adblocker/Plugin"); + const bypass_premium_restrictions = require("../../../../../plugins/bypass-premium-restrictions/Plugin"); + const color_changer = require("../../../../../plugins/color-changer/Plugin"); + const discord_rpc = require("../../../../../plugins/discord-rpc/Plugin"); + const downloader = require("../../../../../plugins/downloader/Plugin"); + + const {get} = require("../../../../database/PluginManager"); + + if (get("adblocker") === true) adblocker.preload(window); + if (get("bypass-premium-restrictions") === true) bypass_premium_restrictions.preload(window); + if (get("color-changer") === true) color_changer.preload(window); + if (get("discord-rpc") === true) discord_rpc.preload(window); + downloader.preload(window); +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events.js b/scripts/web/Managers/Window/window/events.js new file mode 100644 index 0000000..887ae00 --- /dev/null +++ b/scripts/web/Managers/Window/window/events.js @@ -0,0 +1,3 @@ +const { loadEvents } = require("./events/eventManager") + +module.exports.loadEvents = (window) => { loadEvents(window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowBlur.js b/scripts/web/Managers/Window/window/events/WindowBlur.js new file mode 100644 index 0000000..31e7d0f --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowBlur.js @@ -0,0 +1,12 @@ +const {get, set} = require("../../../../../database/PluginManager"); + +module.exports.load = (window) => { + window.on("blur", () => { + if (get("gamer-mode") === true) { + console.log(`[Window] Video is hidden now to increase performance`) + window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.add("video-disable-performance") }`) + window.webContents.executeJavaScript(`document.querySelector("body").classList.add("gamer-mode")`) + set("color-changer", false) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowClose.js b/scripts/web/Managers/Window/window/events/WindowClose.js new file mode 100644 index 0000000..faa728c --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowClose.js @@ -0,0 +1,15 @@ +const {setLastSongInfo} = require("../../../../SongInfoManager"); +const electron = require("electron"); + +module.exports.load = (window) => { + window.on("close", () => { + window.webContents.executeJavaScript(` + document.querySelector("#movie_player").getCurrentTime().toString().split(".")[0] + `).then(time => { + window.webContents.executeJavaScript(`document.querySelector("#movie_player").getVideoData()`).then(data => { + setLastSongInfo(time, data.list || undefined) + electron.app.quit() + }) + }) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowEnterFullscreen.js b/scripts/web/Managers/Window/window/events/WindowEnterFullscreen.js new file mode 100644 index 0000000..100c258 --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowEnterFullscreen.js @@ -0,0 +1,5 @@ +module.exports.load = (window) => { + window.on("enter-full-screen", () => { + window.webContents.executeJavaScript("document.querySelector('#titlebar').classList.add('hidden')") + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowFocus.js b/scripts/web/Managers/Window/window/events/WindowFocus.js new file mode 100644 index 0000000..d696a96 --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowFocus.js @@ -0,0 +1,11 @@ +const {get, set} = require("../../../../../database/PluginManager"); + +module.exports.load = (window) => { + window.on("focus", () => { + if (get("gamer-mode") === true) { + window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.remove("video-disable-performance") }`) + window.webContents.executeJavaScript(`document.querySelector("body").classList.remove("gamer-mode")`) + set("color-changer", true) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowLeaveFullscreen.js b/scripts/web/Managers/Window/window/events/WindowLeaveFullscreen.js new file mode 100644 index 0000000..272b687 --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowLeaveFullscreen.js @@ -0,0 +1,5 @@ +module.exports.load = (window) => { + window.on("leave-full-screen", () => { + window.webContents.executeJavaScript("document.querySelector('#titlebar').classList.remove('hidden')") + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowNavigation.js b/scripts/web/Managers/Window/window/events/WindowNavigation.js new file mode 100644 index 0000000..47f7ace --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowNavigation.js @@ -0,0 +1,7 @@ +const {handleURLChange} = require("../../windowManager"); + +module.exports.load = (window) => { + window.webContents.on("did-start-navigation", (e, url) => { + handleURLChange(window, url) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowRestore.js b/scripts/web/Managers/Window/window/events/WindowRestore.js new file mode 100644 index 0000000..31e1567 --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowRestore.js @@ -0,0 +1,11 @@ +const {get, set} = require("../../../../../database/PluginManager"); + +module.exports.load = (window) => { + window.on("restore", () => { + window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.remove("video-disable-performance") }`) + window.webContents.executeJavaScript(`document.querySelector("body").classList.remove("gamer-mode")`) + if (get("gamer-mode") === true) { + set("color-changer", true) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowUnload.js b/scripts/web/Managers/Window/window/events/WindowUnload.js new file mode 100644 index 0000000..9da57b9 --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowUnload.js @@ -0,0 +1,5 @@ +module.exports.load = (window) => { + window.webContents.on("will-prevent-unload", (event) => { + event.preventDefault() + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/WindowUnmaximize.js b/scripts/web/Managers/Window/window/events/WindowUnmaximize.js new file mode 100644 index 0000000..4f8df2e --- /dev/null +++ b/scripts/web/Managers/Window/window/events/WindowUnmaximize.js @@ -0,0 +1,6 @@ +module.exports.load = (window) => { + window.on("unmaximize", () => { + window.webContents.executeJavaScript(`document.body.classList.remove('maximized')`); + window.webContents.executeJavaScript(`document.querySelector("ytmusic-app-layout").setAttribute("not-maximized", "")`) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/events/eventManager.js b/scripts/web/Managers/Window/window/events/eventManager.js new file mode 100644 index 0000000..d32c60c --- /dev/null +++ b/scripts/web/Managers/Window/window/events/eventManager.js @@ -0,0 +1,21 @@ +module.exports.loadEvents = (window) => { + const WindowBlur = require("./WindowBlur") + const WindowClose = require("./WindowClose") + const WindowEnterFullscreen = require("./WindowEnterFullscreen") + const WindowFocus = require("./WindowFocus") + const WindowLeaveFullscreen = require("./WindowLeaveFullscreen") + const WindowNavigation = require("./WindowNavigation") + const WindowRestore = require("./WindowRestore") + const WindowUnload = require("./WindowUnload") + const WindowUnmaximize = require("./WindowUnmaximize") + + WindowBlur.load(window) + WindowClose.load(window) + WindowEnterFullscreen.load(window) + WindowFocus.load(window) + WindowLeaveFullscreen.load(window) + WindowNavigation.load(window) + WindowRestore.load(window) + WindowUnload.load(window) + WindowUnmaximize.load(window) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents.js b/scripts/web/Managers/Window/window/ipcEvents.js new file mode 100644 index 0000000..64e81dd --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents.js @@ -0,0 +1,3 @@ +const { loadIpcEvents } = require("./ipcEvents/ipcEventManager") + +module.exports.loadIpcEvents = (ipcMain, window) => { loadIpcEvents(ipcMain, window) } \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/AmbientModeEvent.js b/scripts/web/Managers/Window/window/ipcEvents/AmbientModeEvent.js new file mode 100644 index 0000000..1f45761 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/AmbientModeEvent.js @@ -0,0 +1,9 @@ +const {get} = require("../../../../../database/PluginManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("ambient-mode", () => { + if(get("ambient-mode") === false) return + const drawCanvas = require("../../../../../../plugins/ambient-mode/functions/drawCanvas") + drawCanvas() + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/AudioVideoClickedEvent.js b/scripts/web/Managers/Window/window/ipcEvents/AudioVideoClickedEvent.js new file mode 100644 index 0000000..dd822a0 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/AudioVideoClickedEvent.js @@ -0,0 +1,18 @@ +module.exports.load = (ipcMain, window) => { + ipcMain.on("av-clicked", (e, [args]) => { + if (args === "audio") { + if (window.isFullScreen()) { + window.webContents.executeJavaScript(` + document.querySelector("#fullscreen-container").style.display = "block" + ;0`) + } + } + if (args === "video") { + if (window.isFullScreen()) { + window.webContents.executeJavaScript(` + document.querySelector("#fullscreen-container").style.display = "none" + ;0`) + } + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/ButtonClickedEvent.js b/scripts/web/Managers/Window/window/ipcEvents/ButtonClickedEvent.js new file mode 100644 index 0000000..457d802 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/ButtonClickedEvent.js @@ -0,0 +1,12 @@ +module.exports.load = (ipcMain) => { + ipcMain.on("button-clicked", (e, [args]) => { + handle(args) + }) + + function handle(args) { + const data = args + + const plugin = require("../../../../../../plugins/" + data.plugin + "/Plugin") + plugin.handle(data.for) + } +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/CloseEvent.js b/scripts/web/Managers/Window/window/ipcEvents/CloseEvent.js new file mode 100644 index 0000000..281b011 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/CloseEvent.js @@ -0,0 +1,20 @@ +const {get} = require("../../../../../database/PluginManager"); +const {setLastSongInfo} = require("../../../../SongInfoManager"); +const electron = require("electron") + +module.exports.load = (ipcMain, window) => { + ipcMain.on("close", () => { + if (get("close-background") === true) { + window.hide() + } else { + window.webContents.executeJavaScript(` + document.querySelector("#movie_player").getCurrentTime().toString().split(".")[0] + `).then(time => { + window.webContents.executeJavaScript(`document.querySelector("#movie_player").getVideoData()`).then(data => { + setLastSongInfo(time, data.list || undefined) + electron.app.quit() + }) + }) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/MaximizeEvent.js b/scripts/web/Managers/Window/window/ipcEvents/MaximizeEvent.js new file mode 100644 index 0000000..f150b91 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/MaximizeEvent.js @@ -0,0 +1,7 @@ +module.exports.load = (ipcMain, window) => { + ipcMain.on("maximize", () => { + window.maximize() + window.webContents.executeJavaScript(`document.body.classList.add('maximized')`); + window.webContents.executeJavaScript(`document.querySelector("ytmusic-app-layout").removeAttribute("not-maximized")`) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/MinimizeEvent.js b/scripts/web/Managers/Window/window/ipcEvents/MinimizeEvent.js new file mode 100644 index 0000000..8c7c889 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/MinimizeEvent.js @@ -0,0 +1,12 @@ +const {get, set} = require("../../../../../database/PluginManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("minimize", () => { + window.minimize() + window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.add("video-disable-performance") }`) + window.webContents.executeJavaScript(`document.querySelector("body").classList.add("gamer-mode")`) + if (get("gamer-mode") === true) { + set("color-changer", false) + } + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/NavigatePageBackEvent.js b/scripts/web/Managers/Window/window/ipcEvents/NavigatePageBackEvent.js new file mode 100644 index 0000000..15e1ea9 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/NavigatePageBackEvent.js @@ -0,0 +1,9 @@ +module.exports.load = (ipcMain, window) => { + ipcMain.on("navigate-page-back", () => { + window.webContents.executeJavaScript(` + if(navigation.canGoBack) { + navigation.back() + } + `) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/PauseEvent.js b/scripts/web/Managers/Window/window/ipcEvents/PauseEvent.js new file mode 100644 index 0000000..29b5b8a --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/PauseEvent.js @@ -0,0 +1,7 @@ +const {changePlayState} = require("../../../../SongInfoManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("pause", () => { + changePlayState(window, 'pause') + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/PlayEvent.js b/scripts/web/Managers/Window/window/ipcEvents/PlayEvent.js new file mode 100644 index 0000000..42afc8f --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/PlayEvent.js @@ -0,0 +1,7 @@ +const {changePlayState} = require("../../../../SongInfoManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("play", () => { + changePlayState(window, 'play') + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/RateLimitedEvent.js b/scripts/web/Managers/Window/window/ipcEvents/RateLimitedEvent.js new file mode 100644 index 0000000..b796608 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/RateLimitedEvent.js @@ -0,0 +1,13 @@ +const electron = require("electron"); +const path = require("path"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("rate-limited", () => { + electron.dialog.showMessageBox({ + title: "Oops...", + message: "You are rate limited. The app should work well in next 100 seconds. You should prevent yourself from relaunching the app too much.", + buttons: ["OK"], + icon: path.join(__dirname, "..", "..", "..", "..", "..", "icons", "tray.png") + }) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/RestoreEvent.js b/scripts/web/Managers/Window/window/ipcEvents/RestoreEvent.js new file mode 100644 index 0000000..09c11be --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/RestoreEvent.js @@ -0,0 +1,5 @@ +module.exports.load = (ipcMain, window) => { + ipcMain.on("restore", () => { + window.unmaximize() + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/SeekEvent.js b/scripts/web/Managers/Window/window/ipcEvents/SeekEvent.js new file mode 100644 index 0000000..d4dda22 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/SeekEvent.js @@ -0,0 +1,7 @@ +const {changePlayState} = require("../../../../SongInfoManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("seek", () => { + changePlayState(window, 'play') + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/SongInfoEvent.js b/scripts/web/Managers/Window/window/ipcEvents/SongInfoEvent.js new file mode 100644 index 0000000..17195a2 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/SongInfoEvent.js @@ -0,0 +1,7 @@ +const {checkSongInfo} = require("../../../../SongInfoManager"); + +module.exports.load = (ipcMain, window) => { + ipcMain.on("song-info", () => { + checkSongInfo(window) + }) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/ipcEvents/ipcEventManager.js b/scripts/web/Managers/Window/window/ipcEvents/ipcEventManager.js new file mode 100644 index 0000000..d0bb917 --- /dev/null +++ b/scripts/web/Managers/Window/window/ipcEvents/ipcEventManager.js @@ -0,0 +1,29 @@ +module.exports.loadIpcEvents = (ipcMain, window) => { + const AmbientModeEvent = require("./AmbientModeEvent") + const AudioVideoClickedEvent = require("./AudioVideoClickedEvent") + const ButtonClickedEvent = require("./ButtonClickedEvent") + const CloseEvent = require("./CloseEvent") + const MaximizeEvent = require("./MaximizeEvent") + const MinimizeEvent = require("./MinimizeEvent") + const NavigatePageBackEvent = require("./NavigatePageBackEvent") + const PauseEvent = require("./PauseEvent") + const PlayEvent = require("./PlayEvent") + const RateLimitedEvent = require("./RateLimitedEvent") + const RestoreEvent = require("./RestoreEvent") + const SeekEvent = require("./SeekEvent") + const SongInfoEvent = require("./SongInfoEvent") + + AmbientModeEvent.load(ipcMain, window) + AudioVideoClickedEvent.load(ipcMain, window) + ButtonClickedEvent.load(ipcMain, window) + CloseEvent.load(ipcMain, window) + MaximizeEvent.load(ipcMain, window) + MinimizeEvent.load(ipcMain, window) + NavigatePageBackEvent.load(ipcMain, window) + PauseEvent.load(ipcMain, window) + PlayEvent.load(ipcMain, window) + RateLimitedEvent.load(ipcMain, window) + RestoreEvent.load(ipcMain, window) + SeekEvent.load(ipcMain, window) + SongInfoEvent.load(ipcMain, window) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/tray.js b/scripts/web/Managers/Window/window/tray.js new file mode 100644 index 0000000..0aef6f6 --- /dev/null +++ b/scripts/web/Managers/Window/window/tray.js @@ -0,0 +1,37 @@ +let app_tray = null + +const electron = require("electron"); +const path = require("path"); +const {setLastSongInfo} = require("../../../SongInfoManager"); + +module.exports.addTray = (window) => { + if(app_tray !== null) return + + const tray = new electron.Tray(path.join(__dirname, "..", "..", "..", "..", "..", "icons", "tray.png")) + const menu = new electron.Menu.buildFromTemplate([ + { + label: "Quit", click: () => { + window.webContents.executeJavaScript(` + document.querySelector("#movie_player").getCurrentTime().toString().split(".")[0] + `).then(time => { + window.webContents.executeJavaScript(`document.querySelector("#movie_player").getVideoData()`).then(data => { + setLastSongInfo(time, data.list || undefined) + electron.app.quit() + }) + }) + } + } + ]) + + tray.on("click", () => { + window.show() + window.focus() + }) + + tray.setContextMenu(menu) + app_tray = tray +} + +module.exports.destroyTray = () => { + app_tray.destroy() +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/window/urlChange.js b/scripts/web/Managers/Window/window/urlChange.js new file mode 100644 index 0000000..beb7a95 --- /dev/null +++ b/scripts/web/Managers/Window/window/urlChange.js @@ -0,0 +1,8 @@ +module.exports = (window, url) => { + const PlaylistJS = require("../../../JS/PlaylistJS"); + const ChannelJS = require("../../../JS/ChannelJS"); + + if (url.includes(PlaylistJS.info.include)) return PlaylistJS.load(window) + if (!url.includes(PlaylistJS.info.include)) PlaylistJS.clear(window) + if (url.includes(ChannelJS.info.include)) ChannelJS.load(window) +} \ No newline at end of file diff --git a/scripts/web/Managers/Window/windowManager.js b/scripts/web/Managers/Window/windowManager.js new file mode 100644 index 0000000..15af6d6 --- /dev/null +++ b/scripts/web/Managers/Window/windowManager.js @@ -0,0 +1,6 @@ +const {addTray, destroyTray} = require("./window/tray"); +const handleURLChange = require("./window/urlChange") + +module.exports.addTray = (window) => { addTray(window) } +module.exports.destroyTray = () => { destroyTray() } +module.exports.handleURLChange = (window, url) => { handleURLChange(window, url) } \ No newline at end of file diff --git a/scripts/web/SongInfoManager.js b/scripts/web/SongInfoManager.js index c33c50d..d2e5af3 100644 --- a/scripts/web/SongInfoManager.js +++ b/scripts/web/SongInfoManager.js @@ -1,166 +1,73 @@ const {updatePresence} = require("../../plugins/discord-rpc/Plugin"); const {get} = require("../database/PluginManager"); const {setLastSongInfoDB} = require("../database/PluginManager"); -const getImageColors = require("get-image-colors"); -const chroma = require("chroma-js"); -const getPixels = require("get-pixels"); +// Define lastVideoId and songInfo which we will use to store data let lastVideoId let songInfo = {} -module.exports.checkSongInfo = (window, playback) => { - window.webContents.executeJavaScript("document.querySelector(\"#player\").__data").then(i => { - const playerInfo = i - try { - if (i.playerResponse.videoDetails.videoId === lastVideoId) return - this.setColors(window, playerInfo.videoMode, playerInfo) - this.updateFullscreenMetadata(window, playerInfo) - - lastVideoId = i.playerResponse.videoDetails.videoId - } catch (e) { - return - } - }) -} +module.exports.checkSongInfo = (window) => { + const {updateFullscreenMetadata} = require("./Managers/SongInfo/FullscreenManager"); + const {setColors} = require("./Managers/SongInfo/ColorManager"); -module.exports.updateColors = (window) => { - window.webContents.executeJavaScript("document.querySelector(\"#player\").__data").then(i => { + // Get the player's data + window.webContents.executeJavaScript("document.querySelector(\"#player\").__data").then(currentPlayerInfo => { try { - if (i.playerResponse.videoDetails === null) return - this.setColors(window, i.videoMode, i) - } catch (e) { - return console.log(e) - } - }) -} - -module.exports.updateFullscreenMetadata = (window, info) => { - window.webContents.executeJavaScript(` - var trusted_policy = trustedTypes.createPolicy("myPolicy", { - createHTML: (string) => { - return string; - } - }) - - document.querySelector("#fullscreen_img").setAttribute("src", document.querySelector("#song-image > yt-img-shadow > img").src) - document.querySelector("#song_title_fullscreen").innerHTML = trusted_policy.createHTML("${info.playerResponse.videoDetails.title}") - document.querySelector("#song_author_fullscreen").innerHTML = trusted_policy.createHTML("${info.playerResponse.videoDetails.author}") - `) -} - -module.exports.resetColors = (window) => { - window.webContents.insertCSS(`html { --ytmusic-track-color1: black !important; --ytmusic-track-color2: black !important }`) -} - -module.exports.updateImage = (window, playerInfo) => { - let coverURL - if (playerInfo.playerResponse.videoDetails.musicVideoType === "MUSIC_VIDEO_TYPE_ATV") { - coverURL = playerInfo.thumbnail.thumbnails[3].url.split("?")[0] - } else { - if (playerInfo.playerResponse.videoDetails.musicVideoType === "MUSIC_VIDEO_TYPE_PRIVATELY_OWNED_TRACK") { - coverURL = playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[3].url - } else { - const thumb = playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[playerInfo.playerResponse.videoDetails.thumbnail.thumbnails.length - 1] - if (thumb.url.includes("sddefault.jpg")) { - coverURL = "https://i.ytimg.com/vi/" + playerInfo.playerResponse.videoDetails.videoId + "/sddefault.jpg" + // If videoId has same value as lastVideoId, ignore it + if (currentPlayerInfo.playerResponse.videoDetails.videoId === lastVideoId) { return } - coverURL = "https://i.ytimg.com/vi/" + playerInfo.playerResponse.videoDetails.videoId + "/hq720.jpg" - } - } -} - -module.exports.setColors = (window, videoMode, playerInfo) => { - if (videoMode) { - if (get("color-changer") === true && get("color-changer-videos") === true) { - this.changeColors(window, playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[0].url.split("?")[0], false) - } else { - this.resetColors(window) - } - const videoDetails = playerInfo.playerResponse.videoDetails - songInfo = {details: videoDetails, videoType: playerInfo.playerResponse.videoDetails.musicVideoType} - - if (get("discord-rpc") === true) { - updatePresence() - } - } else { - const videoDetails = playerInfo.playerResponse.videoDetails - songInfo = {details: videoDetails, videoType: playerInfo.playerResponse.videoDetails.musicVideoType} - if (playerInfo.playerResponse.videoDetails.musicVideoType === "MUSIC_VIDEO_TYPE_PRIVATELY_OWNED_TRACK" && get("color-changer-private-songs") === true) { - if (get("color-changer") === true) { - this.changeColors(window, playerInfo.playerResponse.videoDetails.thumbnail.thumbnails[3].url, false) - } else { - this.resetColors(window) - } + // If videoId is different, update the colors and fullscreen metadata + setColors(window, currentPlayerInfo.videoMode, currentPlayerInfo) + updateFullscreenMetadata(window, currentPlayerInfo) - if (get("discord-rpc") === true) { - updatePresence() + // Finally set the new songInfo + this.setSongInfo(currentPlayerInfo) + } catch (error) { + // This happens only when playerData is undefined + if(error) { + lastVideoId = "" } - return } + }) +} - if (get("color-changer") === true && get("color-changer-songs") === true) { - this.changeColors(window, `https://i.ytimg.com/vi/${playerInfo.playerResponse.videoDetails.videoId}/hq720.jpg`, true) - } else { - this.resetColors(window) - } +module.exports.setSongInfo = (currentPlayerInfo) => { + songInfo = {details: currentPlayerInfo.playerResponse.videoDetails, videoType: currentPlayerInfo.playerResponse.videoDetails.musicVideoType} + lastVideoId = currentPlayerInfo.playerResponse.videoDetails.videoId - if (get("discord-rpc") === true) { - updatePresence() - } - } + this.updateDiscordPresence() } module.exports.getSongInfo = () => { + // Return songInfo return songInfo } -module.exports.setLastSongInfo = (time, list) => { - setLastSongInfoDB(songInfo, time, list) - console.log(`[SongInfo] Saved last SongInfo: ${songInfo.details.videoId}, ${time}s, ${list}`) +module.exports.updateDiscordPresence = () => { + if (get("discord-rpc") === true) { + updatePresence() + return + } } -module.exports.changePlayState = (window, state) => { - window.webContents.executeJavaScript("document.querySelector(\"#player\").getPlayer().getCurrentTime()").then(time => { - if (get("discord-rpc") === true) { - updatePresence(state, time) - } - }) +module.exports.setLastSongInfo = (elapsedTime, currentPlaylistId) => { + // When details include videoId + if(songInfo.details.videoId) { + // Set the SongInfo to DB + setLastSongInfoDB(songInfo, elapsedTime, currentPlaylistId) + } } -module.exports.changeAudioImage = (window) => { - window.webContents.executeJavaScript(` - if(document.querySelector("#player").getAttribute("video-mode") === '') { - document.querySelector("#song-image > yt-img-shadow > img").setAttribute("src", "https://i.ytimg.com/vi/" + document.querySelector("#player").__data.playerResponse.videoDetails.videoId + "/maxresdefault.jpg") +module.exports.changePlayState = (window, playbackState) => { + // Get current elapsed time from video + window.webContents.executeJavaScript("document.querySelector(\"#player\").getPlayer().getCurrentTime()").then(elapsedTime => { + // When Discord-RPC is enabled + if (get("discord-rpc") === true) { + // Update the presence + updatePresence(playbackState, elapsedTime) } - `) -} - -module.exports.changeColors = (window, url, song) => { - if (song) { - const getPixels = require("get-pixels") - getPixels(url, async (err, pixels) => { - if (err) return window.webContents.insertCSS(`html { --ytmusic-track-color1: black !important; }`) - - const array = [] - array.push(pixels.data[0]) - array.push(pixels.data[1]) - array.push(pixels.data[2]) - - const chroma = require("chroma-js") - const darkerColor = chroma(array[0], array[1], array[2]).darken(0.5).hex() - - window.webContents.insertCSS(`html { --ytmusic-track-color1: rgb(${array[0]}, ${array[1]}, ${array[2]}) !important; --ytmusic-track-color2: ${darkerColor} !important }`) - }) return - } - - const getImageColors = require("get-image-colors") - getImageColors(url).then(async colors => { - const chroma = require("chroma-js") - const c1 = chroma(colors[0]).darken(0.5).hex() - const c2 = chroma(colors[0]).darken(0.2).hex() - window.webContents.insertCSS(`html { --ytmusic-track-color1: ${c1} !important; --ytmusic-track-color2: ${c2} !important }`) }) -} +} \ No newline at end of file diff --git a/scripts/web/WebManager.js b/scripts/web/WebManager.js index cbf0f7e..3759ef3 100644 --- a/scripts/web/WebManager.js +++ b/scripts/web/WebManager.js @@ -1,434 +1,39 @@ -const {get, set} = require("../database/PluginManager"); -const electron = require("electron"); -const {changePlayState, checkSongInfo, setLastSongInfo} = require("./SongInfoManager"); -const path = require("path"); -const PlaylistJS = require("./JS/PlaylistJS"); -const {windows} = require("electron-is"); -let app_tray = null +const {injectConsentStyles, injectAllStyles} = require("./Managers/Window/cssManager"); +const {executeAllScripts} = require("./Managers/Window/jsManager"); +const {loadPlugins} = require("./Managers/Window/pluginManager"); +const {loadEvents} = require("./Managers/Window/window/events"); +const {loadIpcEvents} = require("./Managers/Window/window/ipcEvents"); +const {ipcMain} = require("electron"); module.exports.finishWebLoad = (window) => { // Do not inject until we get the actual YouTube Music page. if (!window.webContents.getURL().includes("https://music.youtube.com/")) { - const ConsentCSS = require("./CSS/ConsentCSS") - ConsentCSS.load(window); - console.log(`[ConsentCSS] Enabled`) + injectConsentStyles(window) } - // Do not inject until we get the actual YouTube Music page. + // Inject when we get the actual YouTube Music page. if (window.webContents.getURL().includes("https://music.youtube.com")) { - const ColorChangerCSS = require("./CSS/ColorChangerCSS") - const HomepageCSS = require("./CSS/HomepageCSS") - const PlayerCSS = require("./CSS/PlayerCSS") - const PlaylistsCSS = require("./CSS/PlaylistsCSS") - const PluginsMenuCSS = require("./CSS/PluginsMenuCSS") - const TitlebarCSS = require("./CSS/TitlebarCSS") - const WhiteColorCSS = require("./CSS/WhiteColorCSS") - const YouTubeSansCSS = require("./CSS/YouTubeSansCSS") - const GamerModeCSS = require("./CSS/GamerModeCSS") - const PluginsMenuJS = require("./JS/PluginsMenuJS") - const TitlebarJS = require("./JS/TitlebarJS") - - ColorChangerCSS.load(window); - console.log(`[ColorChangerCSS] Enabled`) - HomepageCSS.load(window); - console.log(`[HomepageCSS] Enabled`) - PlayerCSS.load(window); - console.log(`[PlayerCSS] Enabled`) - PlaylistsCSS.load(window); - console.log(`[PlaylistsCSS] Enabled`) - PluginsMenuCSS.load(window); - console.log(`[PluginsMenuCSS] Enabled`) - TitlebarCSS.load(window); - console.log(`[TitlebarCSS] Enabled`) - WhiteColorCSS.load(window); - console.log(`[WhiteColorCSS] Enabled`) - if (get("disable-yt-sans") === false) YouTubeSansCSS.load(window); - console.log(`[YouTubeSansCSS] Enabled`) - GamerModeCSS.load(window); - console.log(`[GamerModeCSS] Enabled`) - PluginsMenuJS.load(window); - console.log(`[PluginsMenuJS] Enabled`) - TitlebarJS.load(window); - console.log(`[TitlebarJS] Enabled`) + injectAllStyles(window) + executeAllScripts(window) - if (get("disable-better-fullscreen") === true) { - window.webContents.executeJavaScript(`document.querySelector("#layout").setAttribute("disable-better-fullscreen", "")`) - console.log(`[BetterFullScreen] Disabled`) - } - - this.loadPlugins(window) + loadPlugins(window) } - this.handleIPC(window) - this.handleWindow(window) + loadIpcEvents(ipcMain, window) + loadEvents(window) } - -module.exports.loadPlugins = (window) => { - const adblocker = require("../../plugins/adblocker/Plugin") - const bypass_premium_restrictions = require("../../plugins/bypass-premium-restrictions/Plugin") - const color_changer = require("../../plugins/color-changer/Plugin") - const discord_rpc = require("../../plugins/discord-rpc/Plugin") - const downloader = require("../../plugins/downloader/Plugin") - +module.exports.redoFinishWebLoad = (window) => { // Do not inject until we get the actual YouTube Music page. - if (window.webContents.getURL().includes("https://music.youtube.com/")) { - window.webContents.executeJavaScript("ytcfg.data_.IS_SUBSCRIBER").then(is => { - if (is) { - const store = require("electron-store") - const s = new store() - s.set("app.premium-user", true) - if (get("show-premium-tag") === true) { - window.webContents.on("page-title-updated", () => { - window.setTitle(window.getTitle().replace("YouTube Music", "YouTube Music Premium")) - }) - } - - if (get("color-changer") === true) color_changer.enable(window); - console.log(`[color-changer] Enabled`) - if (get("discord-rpc") === true) discord_rpc.enable(window); - console.log(`[discord-rpc] Enabled`) - downloader.enable(window); - console.log(`[downloader] Enabled`) - return - } - if (!is) { - const store = require("electron-store") - const s = new store() - s.set("app.premium-user", false) - window.setTitle("YouTube Music") - window.webContents.on("page-title-updated", () => { - window.setTitle("YouTube Music") - }) - - if (get("adblocker") === true) adblocker.enable(window); - console.log(`[adblocker] Enabled`) - if (get("disable-premium-upgrade") === true || get("disable-miniplayer") === true) bypass_premium_restrictions.enable(window); - console.log(`[bypass-premium-restrictions] Enabled`) - if (get("color-changer") === true) color_changer.enable(window); - console.log(`[color-changer] Enabled`) - if (get("discord-rpc") === true) discord_rpc.enable(window); - console.log(`[discord-rpc] Enabled`) - downloader.enable(window); - console.log(`[downloader] Enabled`) - } - }) - } -} - -module.exports.preloadPlugins = (window) => { - const adblocker = require("../../plugins/adblocker/Plugin") - const bypass_premium_restrictions = require("../../plugins/bypass-premium-restrictions/Plugin") - const color_changer = require("../../plugins/color-changer/Plugin") - const discord_rpc = require("../../plugins/discord-rpc/Plugin") - const downloader = require("../../plugins/downloader/Plugin") - - if (get("adblocker") === true) adblocker.preload(window); - console.log(`[adblocker] Preloaded`) - if (get("bypass-premium-restrictions") === true) bypass_premium_restrictions.preload(window); - console.log(`[bypass-premium-restrictions] Preloaded`) - if (get("color-changer") === true) color_changer.preload(window); - console.log(`[color-changer] Preloaded`) - if (get("discord-rpc") === true) discord_rpc.preload(window); - console.log(`[discord-rpc] Preloaded`) - downloader.preload(window); - console.log(`[downloader] Preloaded`) -} - -module.exports.handleURLChange = (window, url) => { - const PlaylistJS = require("./JS/PlaylistJS") - if (url.includes(PlaylistJS.info.include)) return PlaylistJS.load(window) - if (!url.includes(PlaylistJS.info.include)) return PlaylistJS.clear(window) -} - -module.exports.handleIPC = (window) => { - function handle(plugin, window) { - if (plugin === "disable-yt-sans") { - if (get("disable-yt-sans") === true) { - set("disable-yt-sans", false) - } else { - set("disable-yt-sans", true) - } - } - if (plugin === "disable-better-fullscreen") { - if (get("disable-better-fullscreen") === true) { - set("disable-better-fullscreen", false) - window.webContents.executeJavaScript(`document.querySelector("ytmusic-app-layout").removeAttribute("disable-better-fullscreen")`) - } else { - set("disable-better-fullscreen", true) - window.webContents.executeJavaScript(`document.querySelector("ytmusic-app-layout").setAttribute("disable-better-fullscreen", "")`) - } - } - if (plugin === "adblocker") { - const adblocker = require("../../plugins/adblocker/Plugin") - adblocker.handle() - } - if (plugin === "disable-miniplayer") { - const bypass_premium = require("../../plugins/bypass-premium-restrictions/Plugin") - bypass_premium.handle(plugin) - } - if (plugin === "disable-premium-upgrade") { - const bypass_premium = require("../../plugins/bypass-premium-restrictions/Plugin") - bypass_premium.handle() - } - if (plugin === "color-changer") { - const color_changer = require("../../plugins/color-changer/Plugin") - color_changer.handle() - } - if (plugin === "color-changer-songs") { - const color_changer = require("../../plugins/color-changer/Plugin") - color_changer.handle_songs() - } - if (plugin === "color-changer-videos") { - const color_changer = require("../../plugins/color-changer/Plugin") - color_changer.handle_videos() - } - if (plugin === "color-changer-private-songs") { - const color_changer = require("../../plugins/color-changer/Plugin") - color_changer.handle_private() - } - if (plugin === "discord-rpc" || plugin === "discord-show-playback" || plugin === "discord-show-cover" || plugin === "discord-show-songdata" || plugin === "discord-show-time") { - const discord = require("../../plugins/discord-rpc/Plugin") - discord.handle(plugin) - } - if (plugin === "download-mp3") { - const download = require("../../plugins/downloader/Plugin") - download.downloadMp3(window) - } - if (plugin === "download-mp4") { - const download = require("../../plugins/downloader/Plugin") - download.downloadMp4(window) - } - if (plugin === "gamer-mode") { - const gamer = require("../../plugins/gaming-mode/Plugin") - gamer.handle() - } - if (plugin === "show-premium-tag") { - const premium = require("../../plugins/premium-features/Plugin") - premium.handle() - } - if (plugin === "resume-playback-on-launch") { - const res = require("../../plugins/resume-playback-on-launch/Plugin") - res.handle() - } - if (plugin === "disable-tray") { - if (get("disable-tray") === true) { - set("disable-tray", false) - this.addTray(window) - } else { - set("disable-tray", true) - this.destroyTray() - } - } - if (plugin === "close-background") { - if (get("close-background") === true) { - set("close-background", false) - } else { - set("close-background", true) - } - } - } - - electron.ipcMain.on("play", () => { - changePlayState(window, 'play') - }) - - electron.ipcMain.on("seek", () => { - changePlayState(window, 'play') - }) - - electron.ipcMain.on("pause", () => { - changePlayState(window, 'pause') - }) - - electron.ipcMain.on("song-info", () => { - checkSongInfo(window) - }) - - electron.ipcMain.on("button-clicked", (e, [args]) => { - handle(args, window) - }) - - electron.ipcMain.on("rate-limited", () => { - electron.dialog.showMessageBox({ title: "Oops...", message: "You are rate limited. The app should work well in next 100 seconds. You should prevent yourself from relaunching the app too much.", buttons: ["OK"], icon: path.join(__dirname, "..", "..", "icons", "tray.png")}) - }) - - electron.ipcMain.on("av-clicked", (e, [args]) => { - if (args === "audio") { - if (window.isFullScreen()) { - window.webContents.executeJavaScript(` - document.querySelector("#fullscreen-container").style.display = "block" - ;0`) - } - } - if (args === "video") { - if (window.isFullScreen()) { - window.webContents.executeJavaScript(` - document.querySelector("#fullscreen-container").style.display = "none" - ;0`) - } - } - }) - - electron.ipcMain.on("close", () => { - if (get("close-background") === true) { - window.hide() - } else { - window.webContents.executeJavaScript(` - document.querySelector("#movie_player").getCurrentTime().toString().split(".")[0] - `).then(time => { - window.webContents.executeJavaScript(`document.querySelector("#movie_player").getVideoData()`).then(data => { - setLastSongInfo(time, data.list || undefined) - electron.app.quit() - }) - }) - } - }) - - electron.ipcMain.on("minimize", () => { - window.minimize() - }) - - electron.ipcMain.on("maximize", () => { - window.maximize() - }) - - electron.ipcMain.on("restore", () => { - window.unmaximize() - }) - - function handler() { - if (window.isMaximized()) { - window.webContents.executeJavaScript(`document.body.classList.add('maximized')`); - } else { - window.webContents.executeJavaScript(`document.body.classList.remove('maximized')`); - } + if (!window.webContents.getURL().includes("https://music.youtube.com/")) { + injectConsentStyles(window) } - window.on("maximize", () => { - handler() - }) - - window.on("unmaximize", () => { - handler() - }) -} - -module.exports.handleWindow = (window) => { - window.webContents.on("will-prevent-unload", (event) => { - event.preventDefault() - console.log(`[Window] Forced unloading`) - }) - - window.on("minimize", () => { - console.log(`[Window] Video is hidden now to increase performance`) - window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.add("video-disable-performance") }`) - window.webContents.executeJavaScript(`document.querySelector("body").classList.add("gamer-mode")`) - if (get("gamer-mode") === true) { - set("color-changer", false) - } - }) - - window.on("restore", () => { - console.log(`[Window] Video is shown again because app is not minimized anymore`) - window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.remove("video-disable-performance") }`) - window.webContents.executeJavaScript(`document.querySelector("body").classList.remove("gamer-mode")`) - if (get("gamer-mode") === true) { - set("color-changer", true) - } - }) - - window.on("blur", () => { - if (get("gamer-mode") === true) { - console.log(`[Window] Video is hidden now to increase performance`) - window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.add("video-disable-performance") }`) - window.webContents.executeJavaScript(`document.querySelector("body").classList.add("gamer-mode")`) - set("color-changer", false) - } - }) - - window.on("focus", () => { - if (get("gamer-mode") === true) { - console.log(`[Window] Video is shown again because app is not minimized anymore`) - window.webContents.executeJavaScript(`if(document.querySelector("video")) { document.querySelector("video").classList.remove("video-disable-performance") }`) - window.webContents.executeJavaScript(`document.querySelector("body").classList.remove("gamer-mode")`) - set("color-changer", true) - } - }) - - window.on("close", () => { - window.webContents.executeJavaScript(` - document.querySelector("#movie_player").getCurrentTime().toString().split(".")[0] - `).then(time => { - window.webContents.executeJavaScript(`document.querySelector("#movie_player").getVideoData()`).then(data => { - setLastSongInfo(time, data.list || undefined) - electron.app.quit() - }) - }) - }) - - window.on("enter-full-screen", () => { - window.setMenuBarVisibility(false) - }) - - window.on("leave-full-screen", () => { - window.setMenuBarVisibility(true) - }) - - window.webContents.on("devtools-opened", () => { - console.log(`[Window] devTools opened`) - }) - - window.webContents.on("devtools-closed", () => { - console.log(`[Window] devTools closed`) - }) - - window.webContents.on("did-start-navigation", (e, url) => { - this.handleURLChange(window, url) - }) -} - -module.exports.addTray = (window) => { - const tray = new electron.Tray(path.join(__dirname, "..", "..", "icons", "tray.png")) - const menu = new electron.Menu.buildFromTemplate([ - { - label: "Quit", click: () => { - electron.app.quit() - } - } - ]) - - tray.on("click", () => { - window.show() - window.focus() - }) - - tray.setContextMenu(menu) - app_tray = tray -} - -module.exports.destroyTray = () => { - app_tray.destroy() -} + // Inject when we get the actual YouTube Music page. + if (window.webContents.getURL().includes("https://music.youtube.com")) { + injectAllStyles(window) + executeAllScripts(window) -module.exports.bypassNetwork = (window) => { - const oldUserAgent = window.webContents.userAgent; - const userAgents = { - windows : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" + loadPlugins(window) } - - const sec_ch_ua = `"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"` - - window.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => { - if (window.webContents.getURL().startsWith('https://accounts.google.com') && details.url.startsWith('https://accounts.google.com')) { - details.requestHeaders['User-Agent'] = oldUserAgent; - } else { - if(windows()) { - details.requestHeaders['User-Agent'] = userAgents["windows"] - details.requestHeaders['Sec-Ch-Ua'] = sec_ch_ua - } - } - - cb({ requestHeaders: details.requestHeaders }); - }); } \ No newline at end of file