forked from thinksalot/chrome-harilo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.html
83 lines (66 loc) · 2.67 KB
/
popup.html
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
<html>
<head>
<style>
body { width: 300px; }
</style>
<script>
chrome.tabs.getSelected(null, function(tab) {
document.forms[0].elements[1].value =tab.url;//get current url from chrome and put it in item[url]
});
function postForm()
{
document.getElementById('progress').innerHTML='<img src=\"img/progress.gif\"> Processing'; //display the progress animation
//document.getElementById('iframeContainer').innerHTML='<iframe id=\"shopFrame\" name=\"shopFrame\" src=\"frame.html\" width=\"150\" height=\"150\" style=\"border:0px\"></iframe>';
var token=getToken();
alert(token);
var http = new XMLHttpRequest();
//get form values
var itemQty=encodeURIComponent(document.forms[0].elements[0].value);
var itemUrl=encodeURIComponent(document.forms[0].elements[1].value);
//var token=encodeURIComponent(document.forms[0].elements[2].value);
var itemComment=encodeURIComponent(document.forms[0].elements[3].value);
var params = 'item[quantity]='+itemQty+'&item[url]='+itemUrl+'&authenticity_token='+token+'&item[comment][content]='+itemComment;
http.open("POST", "http://www.harilo.com/cart_items", true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200)
{
window.location ='done.html';
}
}
http.send(params);
}
function getToken()
{
//alert(document.getElementById("shopFrame").document.forms(0).elements(0).value);
var shopFrame = document.getElementById("shopFrame");
var shopDocument = shopFrame.contentDocument || shopFrame.contentWindow.document;
var token = shopDocument.forms(0).elements(0).value;
return token;
}
</script>
</head>
<body>
<b>Add this to harilo:</b><br/>
<form action="http://harilo.com/cart_items" method="post" name="hariloForm">
<label for="item_quantity">How Many</label>
<input id="item_quantity" name="item[quantity]" size="2" type="text" value="1" />
<input id="item_url" name="item[url]" size="30" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" />
<p>
<label for="item_comment_content">Note (optional) Tip: Enter any special instructions for your item here</label><br/>
<textarea cols="35" id="item_comment_content" name="item[comment][content]" rows="5"></textarea>
</p>
<a href="#" onClick='postForm()'><img src="img/button.png"/></a>
<p>
<div id="progress"></div>
</p>
</form>
</div>
<div id="iframeContainer">
<iframe id="shopFrame" name="shopFrame" src="frame.html" width="0" height="0" style="border:2px"></iframe>
</div>
</body>
</html>