This commit is contained in:
nin0 2025-03-30 05:12:50 -04:00
commit 518e66c6c2
Signed by: nin0
SSH key fingerprint: SHA256:NOoDnFVvZNFvqfXCIhzr6oCTDImZAbTTuyAysZ8Ufk8
2 changed files with 109 additions and 0 deletions

68
index.ts Normal file
View file

@ -0,0 +1,68 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 nin0dev
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { Toasts } from "@webpack/common";
const SpotifySocket = findByPropsLazy("getActiveSocketAndDevice");
const SpotifyAPI = findByPropsLazy("vcSpotifyMarker");
function queueSong(id: string) {
const { socket } = SpotifySocket.getActiveSocketAndDevice();
if (!socket) return Toasts.show({
type: Toasts.Type.FAILURE,
message: "Make sure that Spotify is running before queuing a song",
id: Toasts.genId()
});
try {
SpotifyAPI.post(socket.accountId, socket.accessToken, {
url: "https://api.spotify.com/v1/me/player/queue",
query: {
uri: `spotify:track:${id}`
}
});
Toasts.show({
type: Toasts.Type.SUCCESS,
message: "Song queued",
id: Toasts.genId()
});
}
catch (e) {
console.error(e);
Toasts.show({
type: Toasts.Type.FAILURE,
message: "An error occurred, check console",
id: Toasts.genId()
});
}
}
export default definePlugin({
name: "SpotifyAddToQueue",
description: "Vencord Virus",
authors: [Devs.nin0dev],
iframeMessageListener: e => {
try {
const songIDMatch = (e.data as string).match(/vc-spotifyaddtoqueue__([a-zA-Z0-9]{0,200})/);
if (!songIDMatch) return;
const songID = songIDMatch[1];
queueSong(songID);
}
catch {
return;
}
},
start() {
window.addEventListener("message", this.iframeMessageListener);
},
stop() {
window.removeEventListener("message", this.iframeMessageListener);
}
});

41
native.ts Normal file
View file

@ -0,0 +1,41 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 nin0dev
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { RendererSettings } from "@main/settings";
import { app } from "electron";
app.on("browser-window-created", (_, win) => {
win.webContents.on("frame-created", (_, { frame }) => {
frame?.once("dom-ready", () => {
if (frame.url.startsWith("https://open.spotify.com/embed/")) {
const settings = RendererSettings.store.plugins?.SpotifyAddToQueue;
if (!settings?.enabled) return;
frame.executeJavaScript(`
const interval = setInterval(() => {
const actions = document.querySelector("[class^='PlayerControlsShort_playerControlsWrapper__']");
if(actions) {
const addToQueueButton = document.createElement("button");
Object.assign(addToQueueButton.style, {
position: "relative",
top: "16px",
left: "0px"
});
addToQueueButton.title = "Add to queue";
addToQueueButton.addEventListener("click", () => {
window.top.postMessage("vc-spotifyaddtoqueue__" + location.href.match(/https:\\/\\/open\\.spotify.com\\/embed\\/track\\/([a-zA-Z0-9]{0,200})\\?/ )[1], "*");
});
addToQueueButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="32px" fill="#e3e3e3"><path d="M642.94-160q-47.94 0-81.44-33.56t-33.5-81.5q0-47.94 32.67-81.44Q593.33-390 640-390q15.97 0 30.48 3Q685-384 698-377v-343h182v71H758v375q0 47.5-33.56 80.75T642.94-160ZM120-320v-60h306v60H120Zm0-170v-60h473v60H120Zm0-170v-60h473v60H120Z"/></svg>';
actions.insertBefore(addToQueueButton, actions.firstChild);
clearInterval(interval);
}
}, 100);
`);
}
});
});
});