-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
53 lines (45 loc) · 1.38 KB
/
popup.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
var PopupController = function () {
this.button = document.getElementById('button');
this.buffer = null;
this.output = document.getElementById('output');
this.addListeners();
};
var dump = function(input) {
output = "";
for (key in input) {
value = input[key];
if(value instanceof Array) {
output += " " + key + ":" + "\n - " + value[0] + "\n";
} else if (key == "title") {
output += " - " + key + ":" + " \"" + value + "\"\n";
} else {
output += " " + key + ":" + " \"" + value + "\"\n";
}
}
return output;
}
PopupController.prototype = {
button: null,
addListeners: function () {
this.button.addEventListener('click', this.handleClick.bind(this));
},
handleClick: function () {
self = this;
chrome.tabs.executeScript(null, {file: "get_dom.js"}, function () {
if (chrome.extension.lastError) {
console.log(chrome.extension.lastError.message)
}
// We currently only support one tag
self.buffer.tags = [document.querySelectorAll('input[name="tags"]:checked')[0].value]
self.output.textContent = dump(self.buffer);
})
},
};
document.addEventListener('DOMContentLoaded', function () {
window.PC = new PopupController();
chrome.extension.onMessage.addListener(function(request, sender) {
if (request.action == "getDOM") {
PC.buffer = request.source
}
});
});