Spotify & Amplituner Power Auto

Script that turns power ON/OFF in my amplituner (with autohotkey http server) automatically with spotify play/pause. For this script browser has to allow mixed content (https spotify vs http autohotkey server)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name    Spotify & Amplituner Power Auto
// @version 1.0.4
// @description Script that turns power ON/OFF in my amplituner (with autohotkey http server) automatically with spotify play/pause. For this script browser has to allow mixed content (https spotify vs http autohotkey server)
// @match https://open.spotify.com/*
// @author verona (lukchojnicki)
// @namespace https://greasyfork.org/users/164173
// ==/UserScript==


var prevState = 1; // 1 = play, 0 = pause

setInterval(function () {
    if (!document.getElementsByClassName('connect-bar').length) { // playing on this device
		if (document.getElementsByClassName('spoticon-pause-16').length) { // now playing
			if (prevState === 0) {
				console.log('turn ON AMP power');
                ampPower(1);
			}
            prevState = 1;
		} else if (document.getElementsByClassName('spoticon-play-16').length) { // paused
            if (prevState === 1) {
                console.log('turn OFF AMP power');
                ampPower(0);
            }
            prevState = 0;
		}
	}
}, 1000);

function ampPower(status)
{
    var xhttp = new XMLHttpRequest();
    if (status) {
        xhttp.open('GET', 'http://localhost:8000/ampon', true);
    } else{
        xhttp.open('GET', 'http://localhost:8000/ampoff', true);
    }
    xhttp.send();
}