forked from cdata/polytiming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polytiming-content.js
35 lines (30 loc) · 1.03 KB
/
polytiming-content.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
(function() {
'use strict';
// Synchronously read a file packaged with the extension. The file must be
// listed in the "web_accessible_resources" section of manifest.json
function injectScript(localUrl) {
let extensionUrl = chrome.extension.getURL(localUrl);
let xhr = new XMLHttpRequest();
let response = null;
xhr.open('GET', extensionUrl, false);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
response = xhr.responseText;
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
let scriptSource = response + '\n\n//# sourceURL=' + localUrl;
let script = document.createElement('script');
let parent = document.body || document.head || document.documentElement;
script.appendChild(document.createTextNode(scriptSource));
parent.appendChild(script);
}
let polytimingSource = injectScript('/polytiming.js');
})();