Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ socket.on("updateQueue", () => {
} else {
console.error("No active tabs found.");

}})}
);
socket.on("liked", () => {
chrome.tabs.query({ url: "https://music.youtube.com/*" }, (tabs) => {
if (tabs.length > 0) {
chrome.tabs.sendMessage(
tabs[0].id,
{ action: "liked" },
(response) => {
if (chrome.runtime.lastError) {
console.error(
"Error sending message:",
chrome.runtime.lastError.message
);
} else if (response) {
console.log("Next song response:", response);
socket.emit("queue", response);
} else {
console.warn("No response received from content script.");
}}
);
} else {
console.error("No active tabs found.");

}})}
);
socket.on("slider", (data) => {
Expand Down
11 changes: 11 additions & 0 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
"yt-formatted-string.byline.style-scope.ytmusic-player-bar.complex-string"
);
const playPauseButton = document.querySelector("#play-pause-button");

const likeButtons = document.querySelector("#like-button-renderer");

// Make sure the required elements are found
if (titleElement && imageElement && artistElement && playPauseButton) {
Expand All @@ -20,13 +22,15 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
const playPauseButtonLabel = playPauseButton.getAttribute("aria-label");
const playing = playPauseButtonLabel !== "Play"; // If the label is "Play", it means the song is paused.
const slider = document.querySelector("#progress-bar");
const like = likeButtons.getAttribute("like-status");
// Send the response with all song data
sendResponse({
title: title,
artist: artist,
image: image,
playing: playing,
slider: slider.getAttribute("aria-valuetext"),
like: like
});
} else {
// Send a response with a default error message if elements aren't found
Expand All @@ -51,6 +55,13 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
const playPauseButton = document.querySelector("#play-pause-button");
if (playPauseButton) playPauseButton.click();
}

if (message.action === "liked") {
const likeButton = document.querySelector(
"yt-button-shape#button-shape-like button"
);
if (likeButton) likeButton.click();
}

if (message.action === "prevSong") {
const prevButton = document.querySelector(
Expand Down
Loading