-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
46 lines (36 loc) · 1.64 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
document.addEventListener('DOMContentLoaded', function() {
var address = "http://138.68.148.244:8000/api/";
var selectedText = "";
chrome.tabs.executeScript( {
code: "window.getSelection().toString();"
}, function(selection) {
selectedText = selection[0];
document.getElementById('selectedText').innerHTML = selectedText;
var text = document.getElementById('selectedText').innerHTML;
if (text.length == 0) {
document.getElementById('submitFields').style.display = "none";
} else {
document.getElementById('startApp').style.display = "none";
document.getElementById('submitFields').style.display = "block";
window.scrollTo(0, document.body.scrollHeight);
}
});
var closeApp = document.getElementById('close-app');
closeApp.addEventListener('click',function(){
window.close();
});
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.getSelected(null, function(tab) {
var user_question = document.getElementById('question').value;
var user_email = document.getElementById('user_email').value;
var data = "user_question="+user_question+"&user_email="+user_email+"&questionable_fact="+selectedText+"&questionable_fact_url="+tab.url;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", address, true);
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhttp.send(data);
});
document.getElementById('submitFields').style.display = "none";
document.getElementById('end').style.display = "block";
}, false);
}, false);