高层jQuery解析

高层jQuery解析,jquery,greasemonkey,highrise,Jquery,Greasemonkey,Highrise,我想将h323:number样式的链接添加到高层联系人号码,以便用户可以单击链接拨打IP电话 我看到的html是: <table> <tbody> <tr> <th>Phone</th> <td>+44 (0)1123 1231312<span>Work</span></td> </tr> <tr> &

我想将h323:number样式的链接添加到高层联系人号码,以便用户可以单击链接拨打IP电话

我看到的html是:

<table>
  <tbody>
    <tr>
      <th>Phone</th>
      <td>+44 (0)1123 1231312<span>Work</span></td>
    </tr>
    <tr>
      <th></th>
    <td>+44 (0)777 2342342<span>Other</span></td>
    </tr>
  </tbody>
</table>
i、 e.正在剥离括号中的0

以下任何人都会得到极大的帮助

(1) 如何匹配包含+\d\d数字的td? (2) 当我从td获取数字时,如何使用选择器排除跨度
(3) 我应该使用什么正则表达式来清除href的数字?

这应该接近您所需要的

$('tbody td').each(function() {
    // match a sequence of digits, parentheses and spaces
    var matches = $(this).text().match(/[ \d()]+/);

    if (matches) {
        // remove the spaces and stuff between parentheses
        var href = 'h323:' + matches[0].replace(/\s|\(.*?\)/g, '');
        var link = $('<a/>').attr('href', href);

        $('span', this).append(link);
    }
});
$('tbody td')。每个(函数(){
//匹配一系列数字、括号和空格
var matches=$(this.text().match(/[\d()]+/);
如果(匹配){
//删除括号之间的空格和填充物
var href='h323:'+匹配[0]。替换(/\s | \(.*?\)/g,');
var link=$('').attr('href',href);
$('span',this).append(link);
}
});

不过有一点要注意,如果
span
的内容以一个数字开头,它将包含在匹配中;这是一种需要考虑的可能性吗?

这应该接近您所需要的

$('tbody td').each(function() {
    // match a sequence of digits, parentheses and spaces
    var matches = $(this).text().match(/[ \d()]+/);

    if (matches) {
        // remove the spaces and stuff between parentheses
        var href = 'h323:' + matches[0].replace(/\s|\(.*?\)/g, '');
        var link = $('<a/>').attr('href', href);

        $('span', this).append(link);
    }
});
$('tbody td')。每个(函数(){
//匹配一系列数字、括号和空格
var matches=$(this.text().match(/[\d()]+/);
如果(匹配){
//删除括号之间的空格和填充物
var href='h323:'+匹配[0]。替换(/\s | \(.*?\)/g,');
var link=$('').attr('href',href);
$('span',this).append(link);
}
});

不过有一点要注意,如果
span
的内容以一个数字开头,它将包含在匹配中;这是一种需要考虑的可能性吗?

这是最后一个GreaseMonkey脚本-可能对某些人有用

// ==UserScript==
// @name          HighRise Dialler
// @namespace     
// @description   Adds a CALL link to HighRise Contacts.
// @include       https://*.highrisehq.com/*
// @require       http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==

(function(){

GM_xmlhttpRequest({
   method: "GET",
   url: "http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js",
   onload: run
});

function run(details) {

   if (details.status != 200) {
       GM_log("no jQuery found!");
       return;
   }

   eval(details.responseText);
   var $ = jQuery;

   //do something useful here....

   $('table td').each(function() {
       var matches = $(this).text().match(/^\+*?[\d\(\) ]+/);

       if (matches) {
         var href = 'h323:' + matches[0].replace(/\+44|\+|\s|\(|\)/g, '');
         var link = $(' <a>CALL<a/>').attr('href', href);
         $(this).find('span').append(link);
       }
   });

}

})();
/==UserScript==
//@name高层拨号器
//@名称空间
//@description为高层联系人添加呼叫链接。
//@include https://*.highrisehq.com/*
//@需要http://code.jquery.com/jquery-latest.min.js
//==/UserScript==
(功能(){
GMxmlHttpRequest({
方法:“获取”,
url:“http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js",
加载:运行
});
函数运行(详细信息){
如果(details.status!=200){
GM_日志(“未找到jQuery!”);
返回;
}
eval(details.responseText);
var$=jQuery;
//在这里做些有用的事。。。。
$('table td')。每个(函数(){
var matches=$(this.text().match(/^\+*?[\d\(\)]+/);
如果(匹配){
var href='h323:'+匹配[0]。替换(/\+44\+\\\+\\s\(\\\)/g';
var link=$('CALL').attr('href',href);
$(this.find('span').append(link);
}
});
}
})();

这是最后一个GreaseMonkey脚本-可能对某些人有用

// ==UserScript==
// @name          HighRise Dialler
// @namespace     
// @description   Adds a CALL link to HighRise Contacts.
// @include       https://*.highrisehq.com/*
// @require       http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==

(function(){

GM_xmlhttpRequest({
   method: "GET",
   url: "http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js",
   onload: run
});

function run(details) {

   if (details.status != 200) {
       GM_log("no jQuery found!");
       return;
   }

   eval(details.responseText);
   var $ = jQuery;

   //do something useful here....

   $('table td').each(function() {
       var matches = $(this).text().match(/^\+*?[\d\(\) ]+/);

       if (matches) {
         var href = 'h323:' + matches[0].replace(/\+44|\+|\s|\(|\)/g, '');
         var link = $(' <a>CALL<a/>').attr('href', href);
         $(this).find('span').append(link);
       }
   });

}

})();
/==UserScript==
//@name高层拨号器
//@名称空间
//@description为高层联系人添加呼叫链接。
//@include https://*.highrisehq.com/*
//@需要http://code.jquery.com/jquery-latest.min.js
//==/UserScript==
(功能(){
GMxmlHttpRequest({
方法:“获取”,
url:“http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js",
加载:运行
});
函数运行(详细信息){
如果(details.status!=200){
GM_日志(“未找到jQuery!”);
返回;
}
eval(details.responseText);
var$=jQuery;
//在这里做些有用的事。。。。
$('table td')。每个(函数(){
var matches=$(this.text().match(/^\+*?[\d\(\)]+/);
如果(匹配){
var href='h323:'+匹配[0]。替换(/\+44\+\\\+\\s\(\\\)/g';
var link=$('CALL').attr('href',href);
$(this.find('span').append(link);
}
});
}
})();

当后面跟1-3位数字时,很遗憾……当后面跟1-3位数字时,很遗憾……谢谢。我已经添加了一个包含最后一个GreaseMonkey脚本的答案…谢谢。我添加了一个包含最后一个GreaseMonkey脚本的答案。。。