Change plain url text to a clickable link on a webpage.
Download
It can execute the function on "Tab key + click" or on page load (if
"//" is removed before
window.addEventListener('DOMContentLoaded',function(){url_text_to_link();} ,false)
)
Note:
It's made for Old Opera 12. On Firefox it still works, but the "Tab key + click" may be changed to another combination, since "Tab key" is already used by Firefox.
▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
// ==UserScript==
// @name url_text_to_link
// @include *
// @author Drozdman
// ==/UserScript==
// execute on page load
//window.addEventListener('DOMContentLoaded',function(){url_text_to_link();} ,false)
// or
execute
on Tab key + click
// ******************************** Tab key + click *****************************************
var keydown = false;
var klik = false;
window.addEventListener('click',function(event
) {
event
.stopPropagation();
document.onkeydown = function(event){ // Tab key=9
event = event || window.event;
var key = event.charCode || event.keyCode;
if(key === 9 ){ // Tab key
if(!keydown) {
keydown = true;
Tab_click();
} else {return}
}
}
document.onkeyup = function() { keydown = false;klik= false};
})
function Tab_click(){
if (!klik){
klik=true; //alert("Tab key ") ;
url_text_to_link();
}else {return}
}
// ********** url_text_to_link ************************
url_text_to_link= function(){
var tags=document.querySelectorAll("div,p,span") ;
for(var i=0;i<tags.length;i++){
var url_text=tags[i].textContent.match(/https?\:\/\/[^\s<\)]+/gi);
if(url_text){
for(var j=0;j<url_text.length;j++){
var url=url_text[j];
tags[i].innerHTML=tags[i].innerHTML.replace(new RegExp(url.replace("?","\\?").replace(/&/g,"&"),'g'),"<a href="+url+">"+url+"</a>");
}
}
}
}
//*********** second version
url_text_to_link2= function(){
var tags=document.querySelectorAll("div,p,span") ;
for(var i=0;i<tags.length;i++){
var url_text=tags[i].innerHTML.match(/https?\:\/\/[^\s"]+/gi);
if(url_text){
tags[i].innerHTML=tags[i].innerHTML.replace(/(href="|src=")?(https?\:\/\/[^\s"<']+)(.*)/gi, replacer)
}
}
function replacer(match, $1,$2,$3,offset, string) {
if(!$1 && $2 ){return '<br\>\n<a href="'+$2+'">'+$2+'</a>'}
else { return $1+$2+$3 }
}
}
▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
This script executes on shiftKey
+ mouse over a text url.
▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
// ==UserScript==
// @name url_text_to_link
// @include *
// @author Drozdman
// ==/UserScript==
window.addEventListener('DOMContentLoaded',function(){url_text_to_link_shift()} ,false)
url_text_to_link_shift= function(){
document.addEventListener('keydown',shift_key,false)
document.addEventListener('keyup',function(){
document.removeEventListener('mouseover',on_mouse_over,false)
},false)
function shift_key(event){
if(event.shiftKey){
document.addEventListener('mouseover',on_mouse_over,false);
}
}
function on_mouse_over(event){
var e= event.target || event.srcElement;
var tag = e.tagName.toLowerCase();
var url_text=e.textContent.match(/https?\:\/\/[^\s<\)]+/gi);
if(tag.match('div|p|span') && url_text){
if(url_text){
for(var j=0;j<url_text.length;j++){
var url=url_text[j];
e.innerHTML=e.innerHTML.replace(new RegExp(url.replace("?","\\?").replace(/&/g,"&"),'g'),"<a href="+url+">"+url+"</a>");
}
}
}
};
}
▐▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
This comment has been removed by a blog administrator.
ReplyDelete