-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend.js
55 lines (47 loc) · 1.76 KB
/
send.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
alert("hello");
function getStyle(oElm, strCssRule){
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
}
else if(oElm.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
return p1.toUpperCase();
});
strValue = oElm.currentStyle[strCssRule];
}
return strValue;
}
function GetObjectinhtml() {
var html = '';
var all = document.getElementsByTagName("*");
for (var i=0, max=all.length; i < max; i++) {
// check html object
if(all[i].localName == "button" || (all[i].localName == "input" && all[i].type != "hidden") || all[i].localName == "textarea" || (all[i].localName == "a" && all[i].href != "")) {
var elemRect = all[i].getBoundingClientRect();
html += all[i].outerHTML+ "\n\nwidth : " + all[i].offsetWidth + " height : " + getStyle(all[i], "height") + " left : " + elemRect.left + " top : " + elemRect.top + "\n\n";
}
}
return html;
}
function sendNativeMessage(text) {
message = {"text": text};
port.postMessage(message);
alert("Sent message: <b>" + JSON.stringify(message) + "</b>");
}
function onNativeMessage(message) {
alert("Received message: <b>" + JSON.stringify(message) + "</b>");
}
function onDisconnected() {
alert("Failed to connect: " + chrome.runtime.lastError.message);
port = null;
}
function connect() {
var hostName = "neuralactiontest";
alert("Connecting to native messaging host <b>" + hostName + "</b>");
port = chrome.runtime.connectNative(hostName);
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
}
connect();
sendNativeMessage(GetObjectinhtml());