Spotifresh

Reload and autoplay Spotify when it stops (because I'm blocking ads)

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Spotifresh
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Reload and autoplay Spotify when it stops (because I'm blocking ads)
// @author       Your neighbor
// @include        https://open.spotify.com/playlist/*
// @include        https://open.spotify.com/album/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
const ONE_SECOND = 1000;
    
const playOnLoad = () => {
  const intervalLoop = () => {
    const playButton = document.getElementsByClassName("spoticon-play-16")[0];
    const playbackTimeEl = document.getElementsByClassName(
      "playback-bar__progress-time"
    )[0];
    const playbackTime = playbackTimeEl ? playbackTimeEl.textContent : null;
    const pausedAndNotAdvancing = playbackTime === "0:00" && playButton;
    setTimeout(() => {
      pausedAndNotAdvancing ? playButton.click() : intervalLoop();
    }, ONE_SECOND);
  };
  intervalLoop();
};
    
setTimeout(() => {
    playOnLoad();
}, 5 * ONE_SECOND);


const callAfterNSecondsOfTrue = (callback, seconds, condition) => {
  const intervalLoop = secondsLeft => {
    if (secondsLeft < seconds) {
      console.log("tick ", secondsLeft);
    }
    if (secondsLeft <= 0) {
      callback();
    }
    setTimeout(() => {
      condition() ? intervalLoop(secondsLeft - 1) : intervalLoop(seconds);
    }, ONE_SECOND);
  };
  intervalLoop(seconds);
};

function playingAndNotAdvancing() {
  const pauseButton = document.getElementsByClassName("spoticon-pause-16")[0];
  const playbackTimeEl = document.getElementsByClassName(
    "playback-bar__progress-time"
  )[0];
  const playbackTime = playbackTimeEl ? playbackTimeEl.textContent : null;
  return playbackTime === "0:00" && pauseButton;
}

const reload = () => {
  console.log("reloading...");
  location.reload();
};

callAfterNSecondsOfTrue(reload, 10, playingAndNotAdvancing);
})();