-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
72 lines (61 loc) · 1.69 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
63
64
65
66
67
68
69
70
71
72
// This point to the webserved that contains the files in SERVER
var wikifierURL = 'http://greystock.cs.illinois.edu:8080/curator/curate.php';
var htmlFull = document.body.innerHTML;
wikify(htmlFull);
function wikify(html) {
//Create the notification element
var tmp = document.createElement("div");
tmp.style.position="absolute";
tmp.style.fontSize="small";
tmp.style.paddingTop="5px";
tmp.style.paddingLeft="10px";
tmp.style.paddingRight="10px";
tmp.style.left="50%";
tmp.style.top="0%";
tmp.style.height="30px";
tmp.style.marginLeft="-75px";
tmp.style.background="#FFE200";
tmp.style.textAlign="center";
tmp.innerHTML="Wikifying...";
document.body.appendChild(tmp);
console.log('Stating wikification...');
var data = new FormData();
data.append('html', html);
console.log('Adding data');
var xhr = this.createCORSRequest('POST', wikifierURL);
function handleSuccess(response) {
// alert('Sucess!');
document.body.innerHTML = response;
chrome.runtime.connect().postMessage({"result": "success"});
}
var invokedErrorCallback = false;
function handleError() {
if (!invokedErrorCallback)
alert ('Could not contact wikifier!');
document.body.removeChild(tmp);
invokedErrorCallback = true;
chrome.runtime.connect().postMessage({"result": "failure"});
}
xhr.onload = function() {
if (xhr.responseText) {
var response = xhr.responseText;
handleSuccess(response);
return;
}
handleError();
};
xhr.onerror = function(error) {
handleError();
};
xhr.send(data);
}
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}