-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
134 lines (117 loc) · 2.95 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var options = ["or 1=1 --", "' or 1=1 --"];
var errorDiv;
var msgDiv;
var urlInput;
var buttonNode;
var storage = chrome.storage.local;
function getUrl() {
return urlInput.value;
}
function injectSQL(url_arg) {
//Create original tab
chrome.windows.getCurrent(function(currentWindow) {
chrome.tabs.query({
active : true,
windowId : currentWindow.id
}, function(activeTabs) {
//Create tab to comparison
chrome.tabs.create({
selected : false,
url : "comparison.html"
});
//Open tab initial tab
//if (url_arg != activeTabs[0].url) {
chrome.tabs.create({
selected : false,
url : url_arg
}, function(createdTab) {
chrome.tabs.executeScript(createdTab.id, {
file : "injectCode.js"
});
});
for ( i = 0; i < options.length; i++) {
chrome.tabs.create({
selected : false,
url : url_arg + options[i]
}, function(createdTab) {
chrome.tabs.executeScript(createdTab.id, {
file : "injectCode.js"
});
});
}
log("Successful injection. Using " + options.length + " queries.");
// chrome.extension.sendMessage({
// action : "",
// size : DOMtoString(document)
// })
});
});
}
function cleanMSGs() {
errorDiv.style.visibility = "hidden";
msgDiv.style.visibility = "hidden";
}
function parseUrl(uri) {
if (uri.protocol() != "http") {
uri.protocol("http");
}
if (uri.query() == "") {
printError("Querry not defined");
return false;
}
return true;
}
function printError(error) {
cleanMSGs();
errorDiv.innerHTML = error;
errorDiv.style.visibility = 'visible';
}
function log(msg) {
cleanMSGs();
console.log(msg);
msgDiv.innerHTML = msg;
msgDiv.style.visibility = 'visible';
}
function getCurrentUrl() {
chrome.windows.getCurrent(function(currentWindow) {
chrome.tabs.query({
active : true,
windowId : currentWindow.id
}, function(activeTabs) {
urlInput.value = activeTabs[0].url;
});
});
}
window.onload = function() {
errorDiv = document.getElementById("error");
buttonNode = document.getElementById("inject_button");
urlInput = document.getElementById("urlInput");
msgDiv = document.getElementById("msg");
cleanMSGs();
storage.get('options', function(items) {
options = items.options;
log("Loaded options: <br>" + options.join("<br>"));
});
document.getElementById("currentAnchor").addEventListener('click', function() {
chrome.windows.getCurrent(function(currentWindow) {
chrome.tabs.query({
active : true,
windowId : currentWindow.id
}, function(activeTabs) {
urlInput.value = activeTabs[0].url;
});
});
})
buttonNode.addEventListener('click', function() {
var uri = new URI(getUrl());
if (!parseUrl(uri)) {
return;
}
injectSQL(uri.toString());
}, false);
// chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
// console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension");
// alert(request.source);
// sendResponse({response: "ok"});
// });
};