-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfront.html
97 lines (92 loc) · 3.44 KB
/
front.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Salesforce plugin</title>
<style type="text/css">
html {
font-family: "PT Serif", Georgia, serif;
font-size: 100%;
line-height: 1.6;
background: #fff;
color: #000;
}
body {
margin: 1em;
font-size: 1rem;
max-width:40rem;
margin:0 auto;
}
h1 {
margin:1.25em 0 0;
line-height:1.2;
font-size:2em;
}
h1 {
margin:1.25em 0 0;
line-height:1.2;
font-size:1.75em;
}
p {
margin:1em 0;
}
</style>
</head>
<body>
<h1>Salesforce plugin for Alfred</h1>
<p id="details">(1/3) Initialization...</p>
<script type="text/javascript">
// https://github.com/yanatan16/nanoajax
!function(t,e){function n(t){return t&&e.XDomainRequest&&!/MSIE 1/.test(navigator.userAgent)?new XDomainRequest:e.XMLHttpRequest?new XMLHttpRequest:void 0}function o(t,e,n){t[e]=t[e]||n}var r=["responseType","withCredentials","timeout","onprogress"];t.ajax=function(t,a){function s(t,e){return function(){c||(a(void 0===f.status?t:f.status,0===f.status?"Error":f.response||f.responseText||e,f),c=!0)}}var u=t.headers||{},i=t.body,d=t.method||(i?"POST":"GET"),c=!1,f=n(t.cors);f.open(d,t.url,!0);var l=f.onload=s(200);f.onreadystatechange=function(){4===f.readyState&&l()},f.onerror=s(null,"Error"),f.ontimeout=s(null,"Timeout"),f.onabort=s(null,"Abort"),i&&(o(u,"X-Requested-With","XMLHttpRequest"),e.FormData&&i instanceof e.FormData||o(u,"Content-Type","application/x-www-form-urlencoded"));for(var p,m=0,v=r.length;v>m;m++)p=r[m],void 0!==t[p]&&(f[p]=t[p]);for(var p in u)f.setRequestHeader(p,u[p]);return f.send(i),f},e.nanoajax=t}({},function(){return this}());
</script>
<script type="text/javascript">
function getHashParams() {
var params = {};
if (window.location.hash) {
var couple = (window.location.hash.substr(1)).split("&");
for (i = 0; i < couple.length; i++)
{
var split_couple = couple[i].split("=");
if (split_couple.length == 2) {
params[split_couple[0]] = decodeURIComponent(split_couple[1]);
}
}
}
return params;
}
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
var $p = document.getElementById("details");
setTimeout(function(){
var params = getHashParams();
console.log(params);
if (Object.keys(params).length > 0) {
window.location.hash = "";
$p.innerHTML = "(2/3) Connecting Salesforce account to Alfred...";
var url = "http://" + window.location.host + "/details/" + encodeURIComponent(JSON.stringify(params));
console.log(url);
nanoajax.ajax({url: url, timeout: 3000}, function (code, response) {
if (code == 200 && isJson(response)) {
//var r = JSON.parse(response);
$p.innerHTML = "(3/3) OK! Plugin setup."
}
else {
$p.innerHTML = "ERROR 002: Unable to connect Salesforce account to Alfred"
console.log(code);
console.log(response);
}
})
}
else {
$p.innerHTML = "ERROR 001: Unable to find Salesforce account details"
}
}, 1000);
</script>
</body>
</html>