-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (24 loc) · 736 Bytes
/
background.js
File metadata and controls
27 lines (24 loc) · 736 Bytes
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
/* global chrome */
// Note that this does not work with HSTS. Those URLs will always stay
// not-updated, as that's not an explicit 301 from the bookmarked page.
(function () {
'use strict'
function process301 (responseDetails) {
if ([301, 308].includes(responseDetails.statusCode)) {
updateBookmarks(responseDetails.url, responseDetails.redirectUrl)
}
}
function updateBookmarks (oldURL, newURL) {
chrome.bookmarks.search({ url: oldURL }, function (bookmarkItems) {
for (let item of bookmarkItems) {
chrome.bookmarks.update(item.id, {
url: newURL
})
}
})
}
chrome.webRequest.onBeforeRedirect.addListener(
process301,
{ urls: ['<all_urls>'] }
)
})()