2017-10-20 11:09:12 -04:00
|
|
|
/*jslint es6: true, browser: true*/
|
|
|
|
/*global window*/
|
|
|
|
// This script file runs in the context of the extension, and mainly
|
|
|
|
// exists to inject the proxy blocking code into content frames.
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const cookies2 = window.Cookies.noConflict();
|
|
|
|
const {standards, constants, cookieEncodingLib, proxyBlockLib} = window.WEB_API_MANAGER;
|
|
|
|
const standardsCookieName = constants.cookieName;
|
|
|
|
|
|
|
|
const doc = window.document;
|
|
|
|
const script = doc.createElement('script');
|
|
|
|
const rootElm = doc.head || doc.documentElement;
|
|
|
|
|
|
|
|
const cookieValue = cookies2.get(standardsCookieName);
|
2017-10-22 00:40:39 -05:00
|
|
|
|
|
|
|
if (!cookieValue) {
|
|
|
|
window.console.log(`Unable to find the Web API Manager settings for ${doc.location.href}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-21 11:49:56 -04:00
|
|
|
cookies2.remove(standardsCookieName, {path: window.document.location.pathname});
|
|
|
|
|
|
|
|
if (!cookieValue) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-22 00:40:39 -05:00
|
|
|
|
2017-10-20 11:09:12 -04:00
|
|
|
const [standardsToBlock, shouldLog] = cookieEncodingLib.fromCookieValue(cookieValue);
|
|
|
|
|
|
|
|
const [scriptToInject, scriptHash] = proxyBlockLib.generateScriptPayload(
|
|
|
|
standards,
|
|
|
|
standardsToBlock,
|
|
|
|
shouldLog
|
|
|
|
);
|
|
|
|
|
|
|
|
script.appendChild(doc.createTextNode(scriptToInject));
|
|
|
|
script.integrity = "sha256-" + scriptHash;
|
|
|
|
rootElm.appendChild(script);
|
|
|
|
}());
|