-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcssinject.js
More file actions
44 lines (25 loc) · 1.04 KB
/
cssinject.js
File metadata and controls
44 lines (25 loc) · 1.04 KB
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
36
37
38
39
40
41
42
43
44
(function () {
var pathForCSS = '/customcss.css';
var webview = document.getElementById('webview');
var setupCSSInject = function(result){
var cssString = result.replace(/\r\n/gm, " ");
var scriptString = "var cssString = '" + cssString + "';" +
"var styleEl = document.createElement('style');" +
"document.body.appendChild(styleEl);" +
"styleEl.innerHTML = cssString;";
injectInWebview(scriptString);
};
var injectInWebview = function(jscode){
var asyncOp = webview.invokeScriptAsync("eval", jscode);
asyncOp.oncomplete = function() {
console.log("Custom script " + pathForCSS + " injected");
};
asyncOp.onerror = function(err) {
console.error("Error during injection of custom script " + pathForCSS, err);
};
asyncOp.start();
};
webview.addEventListener('MSWebViewDOMContentLoaded', function(){
$.ajax({url: pathForCSS, success: function(result){setupCSSInject(result)}});
});
})()