rendered paste body// Asterisk Click to Call
// Author: Tom Vile
// Inspired by: UPS Tracking Linkify (http://plutor.org/files/upslinkify.user.js) by Logan Ingalls
// Use in conjuction with c2c.php located at http://www.asteriskextras.com
// Match these patterns:
// 800-555-1212
// (800) 555-1212
// 800-555-TELL
// ==UserScript==
// @name Asterisk Click to Call
// @namespace http://www.asteriskextras.com/
// @description Looks for phone numbers in the page and hyperlinks them. When clicking on the link, the call is passed to clicktocall.php that is available at asteriskextras.com
// @include *
// ==/UserScript==
(function () {
const trackRegex = /\b\d\d\d(-|\)\s|\s)\d\d\d-(\d\d\d\d|\w\w\w\w)\b/ig;
function trackUrl(t) {
return "http://192.168.1.1/c2c/c2c.php?number=1"+ String(t).replace(/[\)\s-]/g,'').replace(/[abc]/ig,'2').replace(/[def]/ig,'3').replace(/[ghi]/ig,'4').replace(/[jkl]/ig,'5').replace(/[mno]/ig,'6').replace(/[pqrs]/ig,'7').replace(/[tuv]/ig,'8').replace(/[wxyz]/ig,'9');
}
// tags we will scan looking for un-hyperlinked urls
var allowedParents = [
"abbr", "acronym", "address", "applet", "b", "bdo", "big", "blockquote", "body",
"caption", "center", "cite", "code", "dd", "del", "div", "dfn", "dt", "em",
"fieldset", "font", "form", "h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe",
"ins", "kdb", "li", "object", "pre", "p", "q", "samp", "small", "span", "strike",
"s", "strong", "sub", "sup", "td", "th", "tt", "u", "var"
];
var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ")" +
//" and contains(translate(., 'HTTP', 'http'), 'http')" +
"]";
var candidates = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) {
if (trackRegex.test(cand.nodeValue)) {
var span = document.createElement("span");
var source = cand.nodeValue;
cand.parentNode.replaceChild(span, cand);
trackRegex.lastIndex = 0;
for (var match = null, lastLastIndex = 0; (match = trackRegex.exec(source)); ) {
span.appendChild(document.createTextNode(source.substring(lastLastIndex, match.index)));
var a = document.createElement("a");
a.setAttribute("href", trackUrl(match[0]));
a.appendChild(document.createTextNode(match[0]));
span.appendChild(a);
lastLastIndex = trackRegex.lastIndex;
}
span.appendChild(document.createTextNode(source.substring(lastLastIndex)));
span.normalize();
}
}
})();