-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
34 lines (27 loc) · 947 Bytes
/
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
// Copyright (c) 2017 Marc Juarez. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.
var CENSORED = 'https://www.pinterest.com/';
var CDN = 'https://a248.e.akamai.net/';
// Helper. Return the domain from a URL.
var getDomain = function(url) {
var link = document.createElement('a');
link.setAttribute('href', url);
return link.hostname;
}
// Set the host name of CDN requests to the censored domain.
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
details.requestHeaders.push({
name: 'Host',
value: getDomain(CENSORED)
});
return {requestHeaders: details.requestHeaders};
},
{urls: [CDN]},
["blocking", "requestHeaders"]);
// Intercept requests to the censored page and redirect them to CDN.
chrome.webRequest.onBeforeRequest.addListener(function (details) {
return { redirectUrl: CDN };
},
{urls: [CENSORED]},
['blocking']);