-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
68 lines (54 loc) · 1.42 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
function fillAllInjectedFunction() {
chrome.storage.sync.get(['pageRules'], function(items) {
let filler = null
let tabUrl = window.location.href.split('?')[0]
let match = false
if (items.pageRules) {
Object.keys(items.pageRules).forEach(pageUrl => {
if (!match) {
if (pageUrl.startsWith('^')) {
if(tabUrl.startsWith(pageUrl.slice(1,))){
match = true
filler = new SmartFiller(items.pageRules[pageUrl])
}
} else {
if (pageUrl == tabUrl) {
match = true
filler = new SmartFiller(items.pageRules[pageUrl])
}
}
}
});
}
if (!filler) {
filler = new SmartFiller()
}
filler.fillAll()
});
}
function fill(tab) {
chrome.scripting.executeScript(
{
target: { tabId: tab.id },
function: fillAllInjectedFunction
}
)
}
chrome.action.onClicked.addListener(
function (tab) {
fill(tab)
}
);
chrome.contextMenus.create({
id: "addPageRule",
title: "Smart Fill - Add page rules",
contexts: ["all"]
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == "addPageRule") {
console.log(tab.url);
var optionsUrl = chrome.runtime.getURL('options.html');
optionsUrl = optionsUrl + '?pageUrl=' + tab.url
chrome.tabs.create({ 'url': optionsUrl });
}
});