Compare commits

..

No commits in common. "a086668bd3152f7a5d5b4a204bc2763b23b66761" and "eb290f7ba5ca7e2e8ffd738aedad596c70dff714" have entirely different histories.

3 changed files with 23 additions and 60 deletions

View File

@ -1,24 +1,4 @@
import type { Track, Artist } from "./modules/SpotifyAPI"; function onRuntimeMessage(message: any) {}
function onRuntimeMessage(message: Track) {
const artist = message.artist;
console.log(message.coverArt);
browser.notifications
.create({
title: message.title,
message: message.artist.name,
iconUrl: message.coverArt,
type: "basic",
})
.then(() => {
console.log("OK");
})
.catch((err) => {
console.error(err);
});
}
browser.runtime.onMessage.addListener(onRuntimeMessage); browser.runtime.onMessage.addListener(onRuntimeMessage);

View File

@ -4,7 +4,4 @@ const API = new SpotifyAPI();
// use the API // use the API
const data = API.getCurrentTrack(); API.getCurrentTrack();
browser.runtime.sendMessage(data);

View File

@ -6,14 +6,20 @@ export type Artist = {
}; };
export type Track = { export type Track = {
track: {
title: string; title: string;
URL: string; URL: string;
coverArt: string; coverArt: string;
artist: Artist; artist: Artist | Artist[];
};
playing: boolean;
}; };
export type PlayState = { export type Playstate = {
track: Track;
isPlaying: boolean; isPlaying: boolean;
}; };
@ -33,44 +39,24 @@ export default class SpotifyAPI {
return `${window.location.protocol}//${window.location.host}${relativeURL}`; return `${window.location.protocol}//${window.location.host}${relativeURL}`;
} }
getCurrentTrack(): Track { getCurrentTrack() {
const titleElement = this.scraper.getBarElement("title")!; const titleElement = this.scraper.getBarElement("title")!;
const trackURL = `${titleElement.getAttribute("href")}`; const trackURL = `${titleElement.getAttribute("href")}`;
const artistElement = this.scraper.getBarElement("artist")!; const artistElement = this.scraper.getBarElement("artist")!;
const artistName = artistElement.textContent!; const artistName = artistElement.textContent;
const artistURL = artistElement.getAttribute("href")!; const artistURL = artistElement.getAttribute("href");
const coverArtImage = this.scraper // console.log(trackElement.textContent);
.getBarElement("coverArtImage")!
.getAttribute("src")!;
return { console.log(
title: titleElement.textContent!, `Now playing: ${
URL: this.generateFullURL(trackURL), titleElement.textContent
} by ${artistName} (${this.generateFullURL(trackURL)})`
coverArt: coverArtImage, );
artist: {
name: artistName,
URL: this.generateFullURL(artistURL),
},
};
} }
getPlaystate() { getPlaystate() {}
const playbackControlButton = this.scraper.getBarElement(
"playbackControlButton"
)!;
/* The button's aria-label attribute contains the action that it will perform once clicked
not its current playstate */
return playbackControlButton.getAttribute("aria-label") === "Play"
? false
: true;
}
getPlayback() {}
// TODO: Implement events: onPlay, onPause (?), trackChanged, playstateChanged // TODO: Implement events: onPlay, onPause (?), trackChanged, playstateChanged