-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_script.js
66 lines (50 loc) · 1.99 KB
/
content_script.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
console.save = function (data, filename, mime='text/json') {
if (!data) {
console.error('Console.save: No data');
return;
}
if (!filename) filename = 'console.json';
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4);
}
var blob = new Blob([data], {type: mime}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = [mime, a.download, a.href].join(':');
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
};
const injectFile = (file, type = "script", attr="src")=> {
var s = document.createElement(type);
s[attr] = chrome.extension.getURL(file);
(document.head || document.documentElement).appendChild(s);
};
var port = chrome.runtime.connect();
window.addEventListener("message", function(event) {
// We only accept messages from ourselves
if (event.source !== window)
return;
if (event.data.type && (event.data.type === "CURRENT_STATE")) {
console.save(event.data.stateString, "current-state.json");
window.setTimeout(()=>{
console.save(event.data.initialState, "initial-state.json");
window.setTimeout(()=>{
navigator.clipboard.writeText(event.data.stateString).then(function () {
//window.alert('Async: Copying to clipboard was successful!');
}, function (err) {
console.error('Async: Could not copy text: ', err);
});
},2000);
},3000);
}
}, false);
chrome.runtime.onMessage.addListener(
function(message, callback) {
console.log(message, callback);
//injectFile('lodash.js');
//injectFile('jquery.js');
//injectScripts('inject_immediate.js');
//injectFile('actions.js');
});