Highlight specific words on any page...
|
|
is there a script that highlights specific words that I want on any site/page? |
|
|
please. |
|
|
please. |
|
|
|
|
|
Crappy way, dob.
var RE = /(script)/;
for (var tx = document.evaluate('//text()[normalize-space(.)!=""]', document, null, 6, null), t, i = 0; t = tx.snapshotItem(i); i++) {
var before = t.textContent, st, matched = false;
if (t.parentNode.tagName == 'STYLE' || t.parentNode.tagName == 'SCRIPT') continue;
while ((st = before.search(RE)) != -1) {
t.parentNode.insertBefore(document.createTextNode(before.substr(0, st)), t);
t.parentNode.insertBefore(document.createElement('b'), t).textContent = RegExp.$1;
matched = true;
before = before.substr(st + RegExp.$1.length);
}
if (matched) t.textContent = before;
}
|
|
|
That's why I'm still learning :) |
|
|
thanks mikado, worked...but is there a way I can add more words? and also color them instead just bold? also when I add a word like (My Home) it only highlights exactly as it's typed, like it doesn't highlight (my home) just (My Home)
thanks. |
|
|
please. |
|
|
Replace
with (t.parentNode.insertBefore(document.createElement('span'), t))
textContent = RegExp.$1,
style.cssText = 'color: #f00; size: 14pt;';
Add any styles you like to the cssText string. |
|
|
multi word/case insensivity worked.
but when I replace, the script doesnt work at all. |
|
|
please. |
|
|
I've mismatched quotes in that line, try again. |
|
|
k. |
|
|
nope, still not working. |
|
|
Working for me. |
|
|
not working for me.
|
|
|
var RE = /(e)/;
for (var tx = document.evaluate('//text()[normalize-space(.)!=""]', document, null, 6, null), t, i = 0; t = tx.snapshotItem(i); i++) {
var before = t.textContent, st, matched = false;
if (t.parentNode.tagName == 'STYLE' || t.parentNode.tagName == 'SCRIPT') continue;
while ((st = before.search(RE)) != -1) {
t.parentNode.insertBefore(document.createTextNode(before.substr(0, st)), t);
with (t.parentNode.insertBefore(document.createElement('span'), t))
textContent = RegExp.$1,
style.cssText = 'color: #f00; font-size: 14pt;';
matched = true;
before = before.substr(st + RegExp.$1.length);
}
if (matched) t.textContent = before;
}
|
|
|
is there another way to do the var? i added the words i want to highlight and its a pretty large list and it causes the script to stall |
|
|
How could I use this script to replace text smilies with images (data: uris)? I cant figure it out This is what I need to incorporate it in:
Someone told me that using innerHTML replace was much slower, but I dont know how to use your way. |
|
|
Note: this script deletes words inside textareas instead of highlighting them. (Tested with Firefox 3 and Safari 3.)
|
