To prevent alert spamming you could just build in a variable in place of the alert that is changed to 1 when a word is found, then after the search has been made, check the variable, if = 1, alert...
js code:
// ==UserScript==
// @name Alert
// @namespace http://sammyservers.com
// @description Alert
// @include *
// ==/UserScript==
(function() {
const WORD = {
"test": {"color": "red"},
};
//build in the global variable...
var j = 0;
function highlightText() {
var allTextNodes = document.evaluate('//text()', document, null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i = 0; i < allTextNodes.snapshotLength; i++) {
var ele = allTextNodes.snapshotItem(i);
for (var key in WORD) {
if (ele.nodeValue.toLowerCase().indexOf(key) != -1) {
var span = document.createElement("span");
ele.parentNode.replaceChild(span, ele);
span.appendChild(ele);
for (var css in WORD[key]) {
span.style[css] = WORD[key][css];
//changes the global variable to 1
j = 1;
}
}
}
}
}
highlightText();
if(j = 1){
alert("test");
}
})();
I'm, not too strong on the javascript front so the code might not be solid, but in theory it should work!
As for searching the word outside of the source I have no clue...