Pandora ajax 无法使用 waitForKeyElements

Pandora ajax not working with waitForKeyElements

Pandora AJAX 无法使用 waitForKeyElements。我花了几个小时试图找出我哪里出错了,但无法解决。

一次有效,下一曲播放时无效。

// ==UserScript==
// @name         Pandora I am listening to
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Pandora I am listening to
// @author       You
// @match        http*://www.pandora.com/*
// @include      https://www.pandora.com/station/play/*
// @require      https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==

function liveNow() {
    setTimeout(function() {
        console.log(`Now Playing ${$(".songTitle")[0].innerHTML}`);
    }, 6000);  // delay for loading of music

}

waitForKeyElements ("#trackInfoContainer .songTitle", liveNow);

#trackInfoContainer 正在为每个额外的曲目重复使用(而不是重新创建)。

因此,仅仅等待节点创建是不够的,您还必须检查内容是否已更改。
以下是使用 waitForKeyElements 执行此操作的方法:

waitForKeyElements ("#trackInfoContainer .songTitle", liveNow);

function liveNow (jNode) {
    var titleText  = jNode.text ().trim ();
    var lastText   = jNode.data ("lastText")  ||  "";

    if (titleText != lastText) {
        jNode.data ("lastText", titleText);
        console.log (`Now Playing ${titleText}`);
    }
    return true;  //-- Tell waitForKeyElements to keep checking this node.
}