【问题标题】:Pandora ajax not working with waitForKeyElementsPandora ajax 不适用于 waitForKeyElements
【发布时间】:2017-01-09 04:39:13
【问题描述】:

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);

【问题讨论】:

    标签: javascript ajax greasemonkey pandora


    【解决方案1】:

    #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.
    }
    

    【讨论】:

    • 谢谢布洛克,你太棒了。
    猜你喜欢
    • 2013-08-30
    • 2015-07-04
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多