Display a message, using waitForKeyElements, every time a class is added to element

北城余情 提交于 2019-12-06 16:44:40

By default, waitForKeyElements() only fires once per individual node found. But, what you want is to fire when that class (ui-tabs-selected) moves from one node to another.

This means that you must track the old node, and see if it is the same as the new node. And if you use waitForKeyElements(), you must tell it to run more than once on individual found nodes. You can do that by having the callback function (addAlert() in this case) return true.

Putting it all together, your script would become:

// ==UserScript==
// @name          deskNotifications2
// @namespace     http://www.dutgriff.com/userscripts
// @description   Notifications for desk.com
// @include       https://nvows.desk.com/agent*
// @version       1.0
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require       https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant         GM_addStyle
// ==/UserScript==

waitForKeyElements (
    ".ui-tabs-selected", addAlert
);

function addAlert (jNode) {
    if (typeof this.lastNode == "undefined"  ||  this.lastNode != jNode[0]) {
        alert('The user was selected.');
    }
    this.lastNode = jNode[0];

    return true;    // Allow repeat firings for this node.
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!