I'm playing around with GreaseMonkey, trying to detect new comments on a page. My Javascript is pretty rusty. I've found this waitForKeyElements() script, which seems quite helpful. I see that it's using jQuery, and I've looked into JQuery wildcard selectors, but it's not working.
I even found this question and answer here and this one about jQuery selector id ends with, but still can't get it working.
The chat messages are identified by a <div>
with an id="chat-messages-12345randomNum"
.
Here's what I've tried:
// ==UserScript==
// @name Chat listener
// @include https://chatSite.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
console.log("hello world");
function findNewComments (jNode) {
console.log("found comment " + jNode);
}
waitForKeyElements ("div[id$='chat-messages']", findNewComments);
The 'hello world' is in the console, so I know at least the script is being loaded.
I've tried it both with and without the div in the selector, neither has worked.