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: 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);
});
}
function onRuntimeMessage(message: any) {}
browser.runtime.onMessage.addListener(onRuntimeMessage);

View File

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

View File

@ -6,14 +6,20 @@ export type Artist = {
};
export type Track = {
track: {
title: string;
URL: string;
coverArt: string;
artist: Artist;
artist: Artist | Artist[];
};
playing: boolean;
};
export type PlayState = {
export type Playstate = {
track: Track;
isPlaying: boolean;
};
@ -33,44 +39,24 @@ export default class SpotifyAPI {
return `${window.location.protocol}//${window.location.host}${relativeURL}`;
}
getCurrentTrack(): Track {
getCurrentTrack() {
const titleElement = this.scraper.getBarElement("title")!;
const trackURL = `${titleElement.getAttribute("href")}`;
const artistElement = this.scraper.getBarElement("artist")!;
const artistName = artistElement.textContent!;
const artistURL = artistElement.getAttribute("href")!;
const artistName = artistElement.textContent;
const artistURL = artistElement.getAttribute("href");
const coverArtImage = this.scraper
.getBarElement("coverArtImage")!
.getAttribute("src")!;
// console.log(trackElement.textContent);
return {
title: titleElement.textContent!,
URL: this.generateFullURL(trackURL),
coverArt: coverArtImage,
artist: {
name: artistName,
URL: this.generateFullURL(artistURL),
},
};
console.log(
`Now playing: ${
titleElement.textContent
} by ${artistName} (${this.generateFullURL(trackURL)})`
);
}
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() {}
getPlaystate() {}
// TODO: Implement events: onPlay, onPause (?), trackChanged, playstateChanged