пожалуйста помогите, clearTimeout не работает [требует правки]

376
21 июня 2017, 02:50

Код: https://pastebin.com/raw/yQdHdEMW

// ==UserScript==
// @name         autoplayerludwigos
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description 
// @author       You
// @match        http://www.multiplayerpiano.com/*
// @grant        none
// ==/UserScript==
var adminsusers = [];
var t = 0;
var n;
var u;
var v;
var JSNMPB = [];
var JSNMPBcurrentsong;
    MPP.client.on("a", function (msg) {
    a = msg.a.split(' ');
    b = a[0];
    input = msg.a.substring(b.length).trim(); // <--- for if I make more commands :D
 var msgArr = msg.a.split(' ');
        if ((adminsusers.indexOf(msg.p._id) > - 1) || (msg.p._id==MPP.client.getOwnParticipant()._id)){ if (msgArr[0] == '/js' ) { try { MPP.chat.send("> "+ input);MPP.chat.send('< '+JSON.stringify(eval(msg.a.substr(msgArr[0].length).trim()))); } catch (error) { MPP.chat.send('ⓧ '+error); } } }
        if (b == "/play" || b =="/p") {
       if (!input) { MPP.chat.send("You don't choose song");} if (input == "0") { 
       if (t == 0) {                            
            n=-1;
            u=300;                                  
            v=299;         MPP.chat.send("Reading file. Name: Fur elise. [00:50]");
     JSNMPBcurrentsong = /*setInterval(function () {*/MPP.press("e4",1);
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);           
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs3",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {},                       t++ * 50); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs3",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c2",1);},     n * u);
setTimeout(function () {MPP.press("g2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("g3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("f4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("g1",1);},     n * u);
setTimeout(function () {MPP.press("g2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("f3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("e5",1);},     t++ * v); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs3",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("ds4",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("d4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("e1",1);},     n * u);
setTimeout(function () {MPP.press("e2",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("gs2",1);},    t++ * u); n++;
setTimeout(function () {MPP.press("e3",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("c4",1);},     t++ * u); n++;
setTimeout(function () {MPP.press("b3",1);},     t++ * u + 100); n++;
setTimeout(function () {MPP.press("a3",1);},     t++ * u + 300); n++;
setTimeout(function () {MPP.press("a1",1);},     n * u + 300);
setTimeout(function () {MPP.press("a2",1);},     n * u + 300);;//}, 1000);;
//setTimeout(function () {clearInterval(JSNMPBcurrentsong);}, 50000);               
t = 0;    
                       }}}
if (b == "/stop") {clearTimeout(JSNMPBcurrentsong);}
    });

Код для сайта multiplayerpiano.com

Проблема: При вводе в чат комманду /p 0, песня "fur elise" играет, но при вводе /stop, песня не останавливается.

Answer 1

Предположу, что надо все вложенные setTimeout тоже отменять.

READ ALSO
Спискок со своими стилями в TinyMCE WordPress

Спискок со своими стилями в TinyMCE WordPress

Как сделать в TinyMCE кнопку списка с выбором своих стилей для ul?

305
Два и более модальных окна?

Два и более модальных окна?

Хочу вставить на страницу два и более окна по гайдуНо не получается

327
Как дождаться завершения теста

Как дождаться завершения теста

Есть такой код все тесты запускаются асинхронно насколько я понимаю, как мне запустить playerFindRoom после проверки checkMessage

258