-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbackground.js
More file actions
47 lines (42 loc) · 1.24 KB
/
background.js
File metadata and controls
47 lines (42 loc) · 1.24 KB
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
/* global chrome */
chrome.webNavigation.onHistoryStateUpdated.addListener(function (props) {
var url = props.url
var tabId = props.tabId
if (url) {
var p = url.split('/')
if (p[2] === 'github.com' && p.length >= 5) {
chrome.tabs.sendMessage(tabId, true)
}
}
})
// show a page telling the user to input their token
chrome.storage.sync.get('token', ({token}) => {
if (chrome.runtime.lastError) return
if (!token) {
chrome.storage.sync.get('seenOptions', ({seenOptions}) => {
if (chrome.runtime.lastError) return
if (!seenOptions) {
chrome.tabs.create({
url: '/options.html'
})
}
})
}
})
// disable csp headers on github
// (webextension requests shouldn't need this, but chrome is broken)
if (chrome.webRequest.onHeadersReceived) {
chrome.webRequest.onHeadersReceived.addListener(details => {
for (var i = 0; i < details.responseHeaders.length; i++) {
if ('content-security-policy' === details.responseHeaders[i].name.toLowerCase()) {
details.responseHeaders[i].value = ''
}
}
return {
responseHeaders: details.responseHeaders
}
}, {
urls: ['https://github.com/*/*'],
types: ['main_frame']
}, ['blocking', 'responseHeaders'])
}