Greasy Fork

Greasy Fork is available in English.

网易云音乐专辑封面旋转

使网易云音乐播放时的专辑封面旋转

// ==UserScript==
// @namespace          https://github.com/inchei
// @icon               http://s1.music.126.net/style/favicon.ico
// @author             inchei
// @version            0.1
// @license            GPL 3.0

// @name               网易云音乐专辑封面旋转
// @name:zh-cn         网易云音乐专辑封面旋转
// @name:en            163 music rotating cover

// @description       使网易云音乐播放时的专辑封面旋转
// @description:zh-cn 使网易云音乐播放时的专辑封面旋转
// @description:en    rotate the cover when playing

// @include            /https?://music.163.com/*
// @grant              none
// ==/UserScript==

(function() {
    'use strict';

    let ifPlaying;
    const key = document.querySelector('.ply.j-flag');

    let css = document.createElement('STYLE');
    css.setAttribute('type', 'text/css');
    css.innerHTML = `
    .u-cover-6.rotating {
        -webkit-animation:rotate 10s infinite linear;
    }
    @-webkit-keyframes rotate{
        0%{
            -webkit-transform:rotate(0deg);
        }
        100%{
            -webkit-transform:rotate(360deg);
        }
    }`;
    document.querySelector('head').appendChild(css);

    setInterval(() => {
        if(document.querySelector('.g-iframe')) {
            main();
            window.clearInterval();
        }
    }, 500);

    function main() {
        function innermain() {
            ifPlaying = document.querySelector('.ply.j-flag.pas');
            if (ifPlaying) {
                document.querySelector('.g-iframe').contentWindow.document.querySelector('.u-cover-6').classList.add('rotating');
             } else {
                document.querySelector('.g-iframe').contentWindow.document.querySelector('.u-cover-6').classList.remove('rotating');
            }
        }
        innermain();
        key.addEventListener('click', innermain());
    }
})();