本文介绍了Pandora Ajax无法与waitForKeyElements一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Pandora AJAX无法与waitForKeyElements一起使用.我花了几个小时试图看看我哪里出了问题,无法解决.
Pandora AJAX is not working with waitForKeyElements. I have spent a few hours trying to see where I went wrong and can't work it out.
它只能运行一次,但在播放下一首曲目时将不起作用.
It works once but doesn't work when the next track is played.
// ==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
正在为每个其他轨道重用(不是重新创建).
#trackInfoContainer
is being reused (not created afresh) for each additional track.
因此,仅等待节点的创建是不够的,还必须检查内容是否已更改.
这是使用waitForKeyElements的方法:
So, it's not enough to wait for the node's creation, you must also check that the contents have changed.
Here's how to do that with 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.
}
这篇关于Pandora Ajax无法与waitForKeyElements一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!