Hello,
I got this .js script to make any site's links clickable under code tags..
jQuery.fn.textNodes = function() {
var ret = [];
this.contents().each(function() {
var fn = arguments.callee;
if(this.nodeType == 3) {
ret.push(this);
} else if(this.nodeType==1 &&!(
this.tagName.toLowerCase()=='script' ||
this.tagName.toLowerCase()=='head' ||
this.tagName.toLowerCase()=='iframe' ||
this.tagName.toLowerCase()=='textarea' ||
this.tagName.toLowerCase()=='option' ||
this.tagName.toLowerCase()=='style' ||
this.tagName.toLowerCase()=='title' ||
this.tagName.toLowerCase()=='a')){
jQuery(this).contents().each(fn);
}
});
return ret;
}
jQuery.fn.hfautolink = function() {
re_link2 = new RegExp('(https?://(?:[A-Z0-9]\.)*(?:domain1.com)[-()A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|])', "ig");
re_link3 = new RegExp('https?://(?:[A-Z0-9]\.)*(?:domain1.com)[-()A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]', "i");
re_link4 = new RegExp('(https?://(?:[A-Z0-9]\.)*(?:domain2.com)[-()A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|])', "ig");
re_link5 = new RegExp('https?://(?:[A-Z0-9]\.)*(?:domain2.com)[-()A-Z0-9+&@#/%?=~_|!:,.;]*[A-Z0-9+&@#/%=~_|]', "i");
this.each(function(i){
jQuery.each($(this).textNodes(), function(i, node){
text = node.nodeValue;
if(re_link3.test(text)){
newNode=document.createElement('span');
text=jQuery('<div/>').text(text).html();
newNode.innerHTML=text.replace(re_link2, '<a href="$1" target="_blank">$1</a>');
node.parentNode.replaceChild(newNode, node);
}
else if(re_link5.test(text)){
newNode=document.createElement('span');
text=jQuery('<div/>').text(text).html();
newNode.innerHTML=text.replace(re_link4, '<a href="$1" target="_blank">$1</a>');
node.parentNode.replaceChild(newNode, node);
}
});
});
}
$(function() {
$("div").hfautolink();
});
( Domain1.com and Domain2.com can be anything of our choice )
and I have been told to add this in my site's source ( I added in Global Header Footer )
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="your created .js file location" type="text/javascript"></script>
Now tell me is this script will be okay and safe ? can it cause any problems ? it's working perfect.. but I want to know if there anything wrong in your view..
Also tell me how Do I make the color of links Black.. ( Only for the links made by this script )
Thank you
I would guess you got it from here (http://www.wjunction.com/showthread.php?t=42226). Is it safe? Not completely sure what you mean by safe? Does it work? Sounds like it does. Maybe ask at the site above about its safeness. To recolor it, try editing this line (and the others similar to it):
newNode.innerHTML=text.replace(re_link2, '<a href="$1" target="_blank">$1</a>');
to something like this:
newNode.innerHTML=text.replace(re_link2, '<a href="$1" class="colormeblack" target="_blank">$1</a>');
And in the style.css of the theme you are using, add something like this:
.colormeblack a {
color: #000;
}
Well they just made a script for any forum/blog software.. But You people are the SMF experts.. that's why I asked if this script can cause any problem with smf .. What do u personally think ? does it have ANY code that can harm the site ?
EDIT: I tried your code but it didn't worked :(
Looks to me like it's just rewriting links on the fly, so not really.
I tried your code to change the color but it didn't worked
Have a link to where you're putting this code? And what exactly did you change it to?
I Changed This
newNode.innerHTML=text.replace(re_link4, '<a href="$1" target="_blank">$1</a>');
to
newNode.innerHTML=text.replace(re_link4, '<a href="$1" target="_blank"><span style="COLOR: black">$1</span></a>');
it worked
Cool. Does that mean this topic is solved then? :)
yeah.. I am marking it solved.. Thanks mashby for your time
A Request - If anybody finds anything wrong and harmful in this script then please notify us by replying in this topic.. Thanks