Greasy Fork is available in English.

Spotify Shuffle & Repeat Fix

If Shuffle and Repeat are enabled on Spotify, automatically enable them when the song or playlist is changed.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Spotify Shuffle & Repeat Fix
// @license      GNU GPLv3
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  If Shuffle and Repeat are enabled on Spotify, automatically enable them when the song or playlist is changed.
// @author       Erffy
// @match        https://open.spotify.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const enableButtons = () => {
        const shuffleButton = document.querySelector('[data-testid="control-button-shuffle"]');
        const repeatButton = document.querySelector('[data-testid="control-button-repeat"]');

        if (shuffleButton && shuffleButton.getAttribute('aria-checked') === 'false') {
            shuffleButton.click();
            console.log('[Spotify Auto] Shuffle enabled');
        }

        if (repeatButton && repeatButton.getAttribute('aria-checked') === 'false') {
            repeatButton.click();
            console.log('[Spotify Auto] Repeat enabled');
        }
    };

    const observeChanges = () => {
        const player = document.querySelector('.Root__now-playing-bar');
        const playlistArea = document.querySelector('[data-testid="tracklist-row"]');

        if (!player) {
            setTimeout(observeChanges, 1000);
            return;
        }

        let lastTrack = '';

        const checkTrackChange = () => {
            const trackNameElement = document.querySelector('[data-testid="now-playing-widget"] [data-testid="track-name"]');
            if (trackNameElement) {
                const currentTrack = trackNameElement.textContent.trim();
                if (currentTrack !== lastTrack) {
                    lastTrack = currentTrack;
                    enableButtons();
                }
            }
        };

        const observer = new MutationObserver(checkTrackChange);

        observer.observe(player, { childList: true, subtree: true });
        if (playlistArea) observer.observe(playlistArea, { childList: true, subtree: true });

        enableButtons();
    };

    observeChanges();
})();