Skip to content

Commit

Permalink
add currentMediaItemy
Browse files Browse the repository at this point in the history
  • Loading branch information
twnlink committed Dec 8, 2023
1 parent e8dff52 commit 1789554
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import { appendStyle, createPersistentObject, parseManifest } from "./utils.js";

export const [themesStore, themesStoreReady] = createPersistentObject("NEPTUNE_THEMES", true);

let updateThemeStyle = () => {};

document.addEventListener("DOMContentLoaded", () => {
updateThemeStyle = appendStyle("");

reloadThemes();
});
let updateThemeStyle = appendStyle("");

function reloadThemes() {
updateThemeStyle(themesStore.filter(t => t.enabled).map((t) => `@import url("${t.url}")`).join(";"));
Expand Down
10 changes: 5 additions & 5 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { createStore as createIdbStore, set as idbSet, get as idbGet } from "idb
import { store } from "voby";

export function appendStyle(style) {
const styleTag = document.createElement("style");
styleTag.innerHTML = style;
const sheet = new CSSStyleSheet();
sheet.replaceSync(style);

document.head.appendChild(styleTag);
document.adoptedStyleSheets.push(sheet);

return (newStyle) => {
if (newStyle == undefined) return document.head.removeChild(styleTag);
if (newStyle == undefined) return document.adoptedStyleSheets = document.adoptedStyleSheets.slice(document.adoptedStyleSheets.indexOf(sheet), 1)

styleTag.innerHTML = newStyle;
sheet.replaceSync(newStyle)
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/handleExfiltrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ let webpackObject;
let patchedPrepareAction = false;
let exfiltratedStore;

// Main store exfiltration
export let store;

// Built action handlers
export const actions = {};
windowObject.actions = actions;
Expand Down Expand Up @@ -80,7 +83,9 @@ Object.defineProperty(window, "webpackChunk_tidal_web", {
const unpatch = patcher.after(key, originalResponse, (_, resp) => {
if (!typeof resp == "object" && windowObject.store) return;

windowObject.store = resp;
store = resp;
// Hate.
windowObject.store = store;
unpatch();
});
}
Expand Down
21 changes: 21 additions & 0 deletions src/windowObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ import registerTab from "./api/registerTab.js";
import registerRoute from "./api/registerRoute.js";
import hookContextMenu from "./api/hookContextMenu.js";
import showModal from "./api/showModal.js";
// TODO: AWFUL VOMIT VOMIT KILL MURDER DIE KILL KILL DIE MURDER VOMIT
import { store } from "./handleExfiltrations.js";

let currentMediaItem = {};

try {
const vibrantColorStyle = utils.appendStyle("");

intercept("playbackControls/MEDIA_PRODUCT_TRANSITION", ([{ mediaProduct }]) => {
Object.assign(
currentMediaItem,
store.getState().content.mediaItems.get(mediaProduct.productId),
);
const vibrantColor = currentMediaItem?.item?.album?.vibrantColor;

if (!vibrantColor) return;

vibrantColorStyle(`:root{--track-vibrant-color:${vibrantColor}}`);
});
} catch {}

export default {
patcher,
Expand All @@ -24,4 +44,5 @@ export default {
plugins,
themes,
components,
currentMediaItem,
};

0 comments on commit 1789554

Please sign in to comment.