/
inject.js
22 lines (22 loc) · 921 Bytes
/
inject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* injectScript - Inject internal script to available access to the `window`
*
* @param {type} file_path Local path of the internal script.
* @param {type} tag The tag as string, where the script will be append (default: 'body').
* @see {@link http://stackoverflow.com/questions/20499994/access-window-variable-from-content-script}
*/
function injectScript(file_path, tag) {
var node = document.getElementsByTagName(tag)[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', file_path);
node.appendChild(script);
}
function injectStyleSheet(file_path, tag) {
var node = document.getElementsByTagName(tag)[0];
var script = document.createElement('link');
script.setAttribute('rel', 'stylesheet');
script.setAttribute('href', file_path);
node.appendChild(script);
}
injectStyleSheet(chrome.runtime.getURL('btbtt.css'), 'body');