| From the let's-make-it-crazy-obsfucated-department
With the current nodelet craze, and everyone wanting a way to take a pipelink to Google, I decided to make a way to do it. First I played around with the IE context menu, but couldn't find a way to pass the link back to it, and I wanted it to be cross-browser compatible. But using the following code you can highlight a link you want to go to that has a web address, push the button, and be transported there in a new window.
One problem. The code (as you can see below) is long. Too long for our notelet nodelet, especially for a level 3 noder like myself. *BUT* the nodelet allows you to import scripts (It also allows you to use IFRAMES - see my homenode another nifty thing). So see below for how to work this into your nodelet.
(This has been tested in Phoenix 0.5 and IE 5.5 and IE6. Let me know of any issues)
Technical Description
When you push the button after highlighting the text, the script goes through the page and looks for a link that has the same text. For example, if there was a link:
<a href="http://www.everything2.com?node=www.google.com">Soy Soy Soy!</a>
If you highlighted "Soy Soy!" and pushed the button, the script would look for a link that used - somewhere in the text of the link - that term. It would then open a new window and send you to the address that is after "node=" in the href.
*Note* - This script used to return back a listing of all links in the document that matched the text you highlighted. E2 has too many links and it crashed my browser at first. I am working on a fix for this.
Nodelet
Here is how I have it in my notelet nodelet. If you are concerned about code coming from someone else's server please feel free to copy it to wherever you feel it's safe.
<script language="javascript" src="http://www.cornetdesign.com/alertLink.js">
</script>
<form><input type="button" value="Go Out!" onClick="javascript:goOut()"></form>
The Code
Here is the actual code. It consists of two functions just to clean it up a bit
function goOut(){
var l;
if(document.getSelection){
l = window.getSelection();
ie=0;
}else{
l = document.selection.createRange().text;
ie=1;
}
if(l != ""){
var linksFound = 0;
var arrLinks = new Array();
var theLinks = document.links;
for(i=0;i<theLinks.length;i++){
if(ie){
if(theLinks[i].outerText.indexOf(l) >= 0){
//alert("Link!");
arrLinks[linksFound++] = parseURL(theLinks[i].href);
break;
}
}else{
if(theLinks[i].text.indexOf(l) >= 0){
//alert("Link!");
arrLinks[linksFound++] = parseURL(theLinks[i].href);
break;
}else{
strTest += theLinks[i].text+"|";
}
}
}
if(arrLinks.length > 0){
theWinProps = "width=400,height=300,scrollbars=1,resizable=1,menubar=1,status=1";
theWin = open("","",theWinProps);
theWinDoc = theWin.document;
if(arrLinks.length = 1){
theWinDoc.location = arrLinks[0];
}else{
theWinDoc.writeln("Multiple Links Found that matched that selection:<br>")
for(j=0;j<arrLinks.length;j++){
theWinDoc.writeln("<a href=\""+arrLinks[j]+"\">"+arrLinks[j]+"</a><br>");
}
}
}else{
alert("No links were found that matched that text");
alert("Text searched for: '"+l+"'");
alert(strTest);
}
}else{
alert("You must select a link to go to");
}
return false;
}
function parseURL(strURL){
//alert(strURL);
//This finds the node that is pointed to from node= in the querystring
var returnString = "http://www.everything2.com";
var qMarkLoc = strURL.indexOf("?")+1;
qString = strURL.slice(qMarkLoc);
arrParams = qString.split("&");
for(i=0;i<arrParams.length;i++){
if(arrParams[i].slice(0,5) == "node="){
returnString = arrParams[i].slice(5);
//alert(returnString);
break;
}else{
alert(arrParams[i].slice(0,5));
}
}
if(returnString.indexOf("http://") < 0){
returnString = "http://"+returnString;
}
//alert(returnString);
return returnString;
}
Enjoy, and feel free to contact me with any questions or suggestions. |