-
Notifications
You must be signed in to change notification settings - Fork 2
/
relxpathpopup.js
119 lines (92 loc) · 2.48 KB
/
relxpathpopup.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
/**
* @author syamsasi99@gmail.com
*/
'use strict';
var toggleFlag = 0;
var xpath1 = document.getElementById('xpath_1');
var xpath2 = document.getElementById('xpath_2');
var rel_xpath = document.getElementById('rel_xpath');
var final_res = document.getElementById('final_xpath_result');
var handleRequest = function(request, sender, cb) {
if (request.type === 'update_xpath_1') {
if (request.query !== null) {
xpath1.value = request.query;
}
if (request.results !== null) {
xpath2.value = request.results;
rel_xpath.value = '';
final_res.value = '';
}
}
if (request.type === 'update_xpath_2') {
if (request.query !== null) {
xpath2.value = request.query;
}
if (request.results !== null) {
rel_xpath.value = request.results;
}
}
if (request.type === 'relative_xpath') {
if (request.query !== null) {
rel_xpath.value = request.query;
}
if (request.results !== null) {
if(request.results==''){
request.results="Empty Element";
}
final_res.value = request.tag+" "+request.results;
}
}
if (request.type === 'reset') {
xpath1.placeholder="Right-click anywhere on the page to select element";
xpath1.value="";
xpath2.value="";
}
if (request.type === 'backToInitialState') {
xpath1.placeholder="Right-click anywhere on the page to select element";
xpath1.value="";
xpath2.value="";
rel_xpath.value="";
rel_xpath.placeholder="Right-Click on any two elements... OR Type in an expression here and hit ENTER key...";
final_res.value="";
}
};
var togglePopupHtml = function(e) {
chrome.runtime.sendMessage({
type : 'changePosition'
});
if (toggleFlag == 0) {
document.getElementById("toggle").src = "up.png";
toggleFlag = 1;
} else {
document.getElementById("toggle").src = "down.png";
toggleFlag = 0;
}
};
function evaluateXpath(e) {
e = e || event;
if (e.keyCode === 13 && !e.ctrlKey) {
var xpr = rel_xpath.value;
chrome.runtime.sendMessage({
type : 'evaluateCustomXPath',
xpath : xpr
});
}
}
window.addEventListener('message', function(event) {
var data = String(event.data);
var xpathList = data.split(",");
var res = '';
if(data === ''){
res='No Result Found!!'
}
else{
for (var i = 0; i < xpathList.length; i++) {
res = res + xpathList[i] + "\n";
}
}
final_res.value = res;
});
document.getElementById("toggle").addEventListener('click', togglePopupHtml);
rel_xpath.addEventListener('keyup', evaluateXpath);
chrome.runtime.onMessage.addListener(handleRequest);