I have got a bookmarklet for use with Opera which highlights all
occurrences of some text in the displayed page. I find it very
useful.
Sometimes I need to use two or three different colours for different
keywords I want highlighting on the same page. I have done this by
changing the original word 'yellow' for other javascript colour
words.
I know next to nothig about javascript. So I would ask if anyone
knows how I can tweak this javascript bookmarklet code (see below) in
two sepearte ways:
(1) So that I can select a color from a list. This may be as simple
as changing the caption to say "enter 1 for lime, 2 for yellow," etc.
or it might be cleverer.
(2) This is mutually exclusive with (1). In this case the
javascript would prompt me to enter a javascript colour keyword (like
"yellow" or colour code like "FF00FF").
Of course, in each case the javascript needs to ask me what i am
searching for!
The javascript is below. Is anyone able to advise on this?
TIA.
Jane
--------------
javascript:(fun ction(){var count=0, text, dv;text=prompt( "Search
phrase (yellow):", "");if(text==nu ll ||
text.length==0) return;dv=docum ent.defaultView ;function
searchWithinNod e(node, te, len){var pos, skip, spannode, middlebit,
endbit, middleclone;ski p=0;if( node.nodeType== 3
){pos=node.data .toUpperCase(). indexOf(te);if( pos>=0){spannod e=documen
t.createElement ("SPAN");spanno de.style.backgr oundColor="yell ow";middl
ebit=node.split Text(pos);endbi t=middlebit.spl itText(len);mid dleclone=
middlebit.clone Node(true);span node.appendChil d(middleclone); middlebit
..parentNode.re placeChild(span node,middlebit) ;++count;skip=1 ;}}else
if( node.nodeType== 1&& node.childNodes &&
node.tagName.to UpperCase()!="S CRIPT" &&
node.tagName.to UpperCase!="STY LE"){for (var child=0; child <
node.childNodes .length;
++child){child= child+searchWit hinNode(node.ch ildNodes[child], te,
len);}}return skip;}window.st atus="Searching for
'"+text+"'..."; searchWithinNod e(document.body , text.toUpperCas e(),
text.length);wi ndow.status="Fo und "+count+"
occurrence"+(co unt==1?"":"s")+ " of '"+text+"'.";}) ();
occurrences of some text in the displayed page. I find it very
useful.
Sometimes I need to use two or three different colours for different
keywords I want highlighting on the same page. I have done this by
changing the original word 'yellow' for other javascript colour
words.
I know next to nothig about javascript. So I would ask if anyone
knows how I can tweak this javascript bookmarklet code (see below) in
two sepearte ways:
(1) So that I can select a color from a list. This may be as simple
as changing the caption to say "enter 1 for lime, 2 for yellow," etc.
or it might be cleverer.
(2) This is mutually exclusive with (1). In this case the
javascript would prompt me to enter a javascript colour keyword (like
"yellow" or colour code like "FF00FF").
Of course, in each case the javascript needs to ask me what i am
searching for!
The javascript is below. Is anyone able to advise on this?
TIA.
Jane
--------------
javascript:(fun ction(){var count=0, text, dv;text=prompt( "Search
phrase (yellow):", "");if(text==nu ll ||
text.length==0) return;dv=docum ent.defaultView ;function
searchWithinNod e(node, te, len){var pos, skip, spannode, middlebit,
endbit, middleclone;ski p=0;if( node.nodeType== 3
){pos=node.data .toUpperCase(). indexOf(te);if( pos>=0){spannod e=documen
t.createElement ("SPAN");spanno de.style.backgr oundColor="yell ow";middl
ebit=node.split Text(pos);endbi t=middlebit.spl itText(len);mid dleclone=
middlebit.clone Node(true);span node.appendChil d(middleclone); middlebit
..parentNode.re placeChild(span node,middlebit) ;++count;skip=1 ;}}else
if( node.nodeType== 1&& node.childNodes &&
node.tagName.to UpperCase()!="S CRIPT" &&
node.tagName.to UpperCase!="STY LE"){for (var child=0; child <
node.childNodes .length;
++child){child= child+searchWit hinNode(node.ch ildNodes[child], te,
len);}}return skip;}window.st atus="Searching for
'"+text+"'..."; searchWithinNod e(document.body , text.toUpperCas e(),
text.length);wi ndow.status="Fo und "+count+"
occurrence"+(co unt==1?"":"s")+ " of '"+text+"'.";}) ();
Comment