-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
77 lines (70 loc) · 2.46 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
/**
* (c) 2013 Rob Wu <rob@robwu.nl>
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals navigator */
/* globals chrome, cws_match_pattern, mea_match_pattern, ows_match_pattern, amo_match_patterns, atn_match_patterns,
cws_pattern, mea_pattern, ows_pattern, amo_pattern, atn_pattern,
*/
'use strict';
// Work-around for crbug.com/1132684: static event_rules disappear after a
// restart, so we register rules dynamically instead, on install.
function registerEventRules() {
if (registerEventRules.hasRunOnce) {
return;
}
registerEventRules.hasRunOnce = true;
var pageUrlFilters = [{
hostEquals: "chrome.google.com",
pathPrefix: "/webstore/detail/"
}, {
hostEquals: "microsoftedge.microsoft.com",
pathPrefix: "/webstore/detail/"
}, {
hostEquals: "addons.opera.com",
pathContains: "extensions/details/"
}, {
hostEquals: "addons.mozilla.org",
pathContains: "addon/"
}, {
hostSuffix: "addons.mozilla.org",
pathContains: "review/"
}, {
hostEquals: "addons.allizom.org",
pathContains: "addon/"
}, {
hostSuffix: "addons.allizom.org",
pathContains: "review/"
}, {
hostEquals: "addons-dev.allizom.org",
pathContains: "addon/"
}, {
hostSuffix: "addons-dev.allizom.org",
pathContains: "review/"
}, {
hostEquals: "addons.thunderbird.net",
pathContains: "addon/"
}, {
hostSuffix: "addons-stage.thunderbird.net",
pathContains: "addon/"
}];
var rule = {
conditions: pageUrlFilters.map(function(pageUrlFilter) {
return new chrome.declarativeContent.PageStateMatcher({
pageUrl: pageUrlFilter,
});
}),
actions: [
new chrome.declarativeContent.ShowPageAction(),
],
};
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([rule]);
});
}
// Work-around for crbug.com/388231 is in incognito-events.js
chrome.runtime.onInstalled.addListener(registerEventRules);
// Work-around for crbug.com/264963: onInstalled is not fired when the
// extension was disabled during an update.
chrome.runtime.onStartup.addListener(registerEventRules);