-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackground.js
104 lines (89 loc) · 2.92 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//chrome.contextMenus.removeAll();
var searchit;
var widgt;
var settings = {
url: 'http://demo.ictcore.org/api',
username : 'user',
password : 'user',
contact_load : 'https://www.google.com/search?q={phone_number}',
phone_pattern : '([0-9-()+]{6,20})',
token : 'abc',
agent : false,
extension : 3,
searchphn:false
}
var old;
var newval;
var cal_pref;
chrome.storage.sync.get("settings", function(result) {
settings = result.settings;
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
if (changes.settings !== undefined) {
settings = changes.settings.newValue;
}
});
chrome.tabs.onUpdated.addListener( function getTab (tabId, changeInfo, tab) {
searchit = settings.searchphn;
if (changeInfo.status == 'complete' && tab.active && searchit == 1) {
console.log('Message is sent to content script');
chrome.tabs.sendMessage(tab.id, {text : 'report_back'}, getDOM);
}
});
var tabDom;
function getDOM(value) {
tabDom = value;
console.log(tabDom);
};
chrome.contextMenus.create({
title: "Search phone number in current Tab",
contexts: ["browser_action"],
onclick: function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {text: 'report_back'}, function(response) {
console.log(response.farewell);
});
});
}
});
var no;
chrome.browserAction.onClicked.addListener(function launchApplication() {
var newWindow = null;
if ((newWindow == null) || (newWindow.closed))
newWindow = window.open(
"popup.html",
"ICT Agent",
"width=340,height=630,scrollbars=no,toolbar=no,screenx=0,screeny=0,location=no,titlebar=0,directories=no,status=no,menubar=no"
);
newWindow.focus();
});
//Listening msgs from contentscript
chrome.extension.onRequest.addListener(function(request, sender)
{
no = request.message;
cal_pref = request.preference;
setTimeout(myFunction, 1000);
});
function myFunction() {
chrome.runtime.sendMessage({message: no, preference: cal_pref},function(response){
console.log(response);
});
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?"from a content script:" + sender.tab.url :"from the extension");
widgt = settings.agent;
console.log('I am Clicked');
if (request.greeting == "Clicked" )
if (widgt == true) {
var newWindow = null;
if ((newWindow == null) || (newWindow.closed))
newWindow = newWindow = window.open(
"popup.html",
"ICT Agent",
"width=340,height=630,scrollbars=no,toolbar=no,screenx=0,screeny=0,location=no,titlebar=0,directories=no,status=no,menubar=no"
);
newWindow.focus();
}
sendResponse({farewell: "goodbye"});
});