Made it so you can configure everything

You can configure the following settings:
- Placeholder artwork URL
- Paused timeout (in seconds, minutes, or hours)
- Metadata fetch interval (in seconds, minutes, or hours)

I also added helping notes to the title of the inputs to make it clearer what each setting does.

Also meow meow meow meow meow meow meow meow meow meow meow meow meow meow
This commit is contained in:
2025-06-27 12:00:56 -07:00
parent 575bf35e7f
commit 1ac096ca52
4 changed files with 180 additions and 32 deletions

View File

@ -4,15 +4,23 @@ let artworkEndpoint = null;
let token = null;
let intervalId = null;
let lastSentArtworkKey = null;
let placeholderArtwork = null;
let pausedTimeout = 300000;
let metadataFetchInterval = 1000;
// log credits to console
if (!window._nowPlayingExtensionLogged) {
console.log('Apple Music Now Playing Extension made by Sophia Atkinson with help from PreMiD contributors');
window._nowPlayingExtensionLogged = true;
}
const defaultArtwork = "https://placehold.co/150/1E1F22/FFF?text=Nothing%20playing";
const pausedTimeout = 300000; // 5 minutes
const metadataFetchInterval = 1000; // 1 second
// Cache for artwork base64 by URL
const artworkBase64Cache = {
lastArtworkUrl: null,
lastArtworkBase64: null
lastArtworkBase64: null,
defaultArtworkBase64: null
};
async function imageUrlToBase64(url) {
@ -44,8 +52,8 @@ async function getNowPlayingData() {
const timestampInput = document.querySelector('amp-lcd.lcd.lcd__music')?.shadowRoot
?.querySelector('input#playback-progress[aria-valuenow][aria-valuemax]');
if (!artworkBase64Cache.defaultArtworkBase64) {
artworkBase64Cache.defaultArtworkBase64 = await imageUrlToBase64(defaultArtwork);
if (!artworkBase64Cache.defaultArtworkBase64 && placeholderArtwork) {
artworkBase64Cache.defaultArtworkBase64 = await imageUrlToBase64(placeholderArtwork);
}
const defaultArtworkBase64 = artworkBase64Cache.defaultArtworkBase64;
@ -97,7 +105,7 @@ async function getNowPlayingData() {
const currentTime = timestampInput ? Number(timestampInput.getAttribute('aria-valuenow')) : media.currentTime || 0;
const duration = timestampInput ? Number(timestampInput.getAttribute('aria-valuemax')) : media.duration || 0;
const nowUnix = Math.floor(Date.now() / metadataFetchInterval);
const nowUnix = Math.floor(Date.now() / 1000);
return {
details: title,
@ -180,19 +188,18 @@ function startNowPlayingLoop() {
intervalId = setInterval(() => safeCall(sendNowPlaying), metadataFetchInterval);
}
}
if (!window._nowPlayingExtensionLogged) {
console.log('Apple Music Now Playing Extension made by Sophia Atkinson with help from PreMiD contributors');
window._nowPlayingExtensionLogged = true;
}
if (chrome?.storage?.sync) {
chrome.storage.sync.get(['endpoint', 'artworkEndpoint', 'token'], result => {
chrome.storage.sync.get(['endpoint', 'artworkEndpoint', 'token', 'placeholderArtwork', 'pausedTimeout', 'metadataFetchInterval'], result => {
if (chrome.runtime.lastError) {
console.error("Failed to load settings:", chrome.runtime.lastError.message);
return;
}
({ endpoint, artworkEndpoint, token } = result);
endpoint = result.endpoint;
artworkEndpoint = result.artworkEndpoint;
token = result.token;
placeholderArtwork = result.placeholderArtwork || 'https://placehold.co/150/1E1F22/FFF?text=Nothing%20playing';
pausedTimeout = Number(result.pausedTimeout) || pausedTimeout;
metadataFetchInterval = Number(result.metadataFetchInterval) || metadataFetchInterval;
if (!endpoint || !token) {
console.error("No endpoint/token configured.");