favelet #f60

favelet #f60

Drag this favelet (bookmarklet) #f60 to your IE or Firefox bookmarks. Selecting the bookmarked link when you are visiting any web page will call the F60 script.
The script will add links to the phone numbers in the page, enabling you to click-to-call the number with Orange.

The favelet is customized with the following parameters (modify values of variables in the favelet url):

F60 script commented

/* Script for Favelet #f60 
Author: Jean-Luc Garneau
License: GNU GPL v2 or later
make phone numbers in the page clickable, to be called with Orange
Orange API click2call (http://www.orangepartner.com/site/fr/access_orange_apis/.....?)

Match international number patterns (starting with + or OO)
Match for one country (the default country) domestic number patterns 
(starting with 0 or according to the case a regional code in brackets)
numbers may be separated by one of the following characters : . - / ( ) 
 followed/preceded or not by a blank space

Calling script 
javascript:var user=%22my_username%22;var password=%22my_password%22;
var default_country=%22FR%22; var store=%22http://pagesperso-orange.fr/jeanluc7411/js/%22;
void((function(){var element=document.createElement('script');
element.setAttribute('src',store+'F60.js');
document.body.appendChild(element);})())

F60.js : this file
#f60 : the link calling the F60 script

User parameters :
-Default country : possible values FR (France), UK,US, GER (Germany), HK (Hong-Kong)
-user parameters (username? password ?) for the C2C Orange API : waiting for the API definition;
-Storage place for the F60 script (default "http://pagesperso-orange.fr/jeanluc7411/js/")
*/

//data per country
var prefixes={FR:33,UK:44,US:1,HK:852,GER:49};
var dom_num_shape={
FR:/([ ]?0)([1-9][ ]?[-.()/]?[ ]?(\d[ ]?[-.()/]?[ ]?){8})\b/g,
US:/([ ]?[0(])([1-9][ ]?[-.()/]?[ ]?(\d[ ]?[-.()/]?[ ]?){9})\b/g,
UK:/([ (]?0)([1-9][ ]?[-.()/]?[ ]?(\d[ ]?[-.()/]?[ ]?){9})\b/g,
GER:/([ (]?0)([1-9][ ]?[-.()/]?[ ]?(\d[ ]?[-.()/]?[ ]?){7,10})\b/g,
HK:/([ (]?0)([1-9][ ]?[-.()/]?[ ]?(\d[ ]?[-.()/]?[ ]?){6})\b/g
};
var prefix=prefixes[default_country];
var reg_dom=dom_num_shape[default_country];
var reg_int=/([( ]?(?:00|\+)[ )]?[ ]?)((?:[-.()/]?[ ]?\d){9,13})\b/g;
//Click to call mock-up : 
//final function will be included here when the  API will be made available
function click2call(user,password,tel_number){
x="phone call to "+tel_number+" from "+user+"/"+password;
alert(x);
}
//replacement function for international numbers
//(the Regex is composed of "pre" followed by "core" ; 
replace_int=function(match,pre,core){
core=core.replace(/\(0\)/g,"");
x="+"+core.replace(/[-. ()/]/g,"");
x='<a  href=\'javascript:click2call(user,password,"'+x+'");\'';
x+=' style=\'color:#f60;background-color:#000 \'>'+x+'';
return x;
}
//replacement function for domestic  numbers 
replace_dom=function(match,pre,core){
core=core.replace(/[-. ()/]/g,"");
x="+"+prefix+core;
x='<a  href=\'javascript:click2call(user,password,"'+x+'");\'';
x+=' style=\'color:#fff;background-color:#f50 \'>'+match+'';
return x;
}
//recursive function to find  text nodes (not already linked)
// matching an international  tel number pattern in order to  make numbers clickable;
function traite_tel_int_number(n){
if(n.nodeType==3){
var p=n.parentNode;
var t=p.nodeName;
  if((p.nodeType==1)&&(t!="A")&&reg_int.test(n.data)){
  p.innerHTML=p.innerHTML.replace(reg_int,replace_int)
  };
}
else{
var kids=n.childNodes;
for(var i=0;i<kids.length;i++)traite_tel_int_number(kids[i]);
}
}
//recursive function to find  text nodes (not already linked) 
//matching a domestic tel number pattern, in order to  make numbers clickable
function traite_tel_dom_number(n){
if(n.nodeType==3){
var p=n.parentNode;
var t=p.nodeName;
  if((p.nodeType==1)&&(t!="A")&&reg_dom.test(n.data)){
  p.innerHTML=p.innerHTML.replace(reg_dom,replace_dom)
  };
}
else{
var kids=n.childNodes;
for(var i=0;i<kids.length;i++)traite_tel_dom_number(kids[i]);
}
}
//processing the page
traite_tel_int_number(document);
traite_tel_dom_number(document);
//end