Skip to content

Commit

Permalink
Use extension to dial tel: links
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfarrant committed Jan 2, 2019
1 parent 6f791ca commit 9006af4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sc-chrome-plugin.pem
sc-chrome-plugin.zip

.DS_Store
8 changes: 8 additions & 0 deletions sc-chrome-plugin/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function linkNumbers() {
var extension = chrome.extension.getURL("call.html");
var pattern = /((?:0|\+44)(?:[0-9]|\(|-|\)|\s(?:[0-9]|\()){8,20})/g;
$('body').find(':not(textarea,input,a,pre,code)').replaceText( pattern, '<a title="Click to call this number" href="' + extension + '?number=$1" target="_blank">$1<\/a>' );

$.initialize('a[href^="tel:"], a[href^="callto:"]', function () {
console.log('found link ' + this.href);
var number = this.href.replace(/\D/g, '');

$(this).attr('href', extension + '?number=' + number);
$(this).attr('target', '_blank');
});
}

$(document).ready(function() {
Expand Down
30 changes: 30 additions & 0 deletions sc-chrome-plugin/jquery/jquery.initialize.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

/*!
* jQuery initialize - v1.0.0 - 12/14/2016
* https://github.com/adampietrasiak/jquery.initialize
*
* Copyright (c) 2015-2016 Adam Pietrasiak
* Released under the MIT license
* https://github.com/timpler/jquery.initialize/blob/master/LICENSE
*/
!function (i) {
"use strict";
var t = function t(i, _t) {
this.selector = i, this.callback = _t;
},
e = [];e.initialize = function (e, n) {
var c = [],
a = function a() {
-1 == c.indexOf(this) && (c.push(this), i(this).each(n));
};i(e).each(a), this.push(new t(e, a));
};var n = new MutationObserver(function () {
for (var t = 0; t < e.length; t++) {
i(e[t].selector).each(e[t].callback);
}
});n.observe(document.documentElement, { childList: !0, subtree: !0, attributes: !0 }), i.fn.initialize = function (i) {
e.initialize(this.selector, i);
}, i.initialize = function (i, t) {
e.initialize(i, t);
};
}(jQuery);
1 change: 0 additions & 1 deletion sc-chrome-plugin/jquery/jquery.min.map

This file was deleted.

29 changes: 23 additions & 6 deletions sc-chrome-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@
"browser_action": {
"default_icon": "images/icon16.png",
"default_popup": "main.html",
"js": ["js/main.js", "content.js","background.js","jquery/jquery.min.js","jquery/jquery-ui-1.10.0.custom.min.js","bootstrap/js/bootstrap.min.js","jquery/moment.js","jquery/jquery.atmosphere.js"]
"js": [
"js/main.js",
"content.js",
"background.js",
"jquery/jquery.min.js",
"jquery/jquery-ui-1.10.0.custom.min.js",
"bootstrap/js/bootstrap.min.js",
"jquery/moment.js",
"jquery/jquery.atmosphere.js"
]
},

"permissions": [
Expand All @@ -30,18 +39,26 @@
"web_accessible_resources": [
"images/icon48.png",
"call.html",
"jquery/jquery.min.js",
"jquery/jquery.min.map"
"jquery/jquery.min.js"
],

"background": {
"scripts": ["jquery/jquery.min.js","jquery/jquery.min.map","jquery/jquery.atmosphere.js","js/request.js","js/background.js"]
"scripts": [
"jquery/jquery.min.js",
"jquery/jquery.atmosphere.js",
"js/request.js",
"js/background.js"
]
},

"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["jquery/jquery.min.js","jquery/jquery.ba-replacetext.min.js","content.js"],
"js": [
"jquery/jquery.min.js",
"jquery/jquery.ba-replacetext.min.js",
"jquery/jquery.initialize.min.js",
"content.js"
],
"run_at": "document_end",
"all_frames": true
}
Expand Down

0 comments on commit 9006af4

Please sign in to comment.