-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.html
37 lines (32 loc) · 1.09 KB
/
global.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
<!DOCTYPE html>
<html>
<head>
<title>Polr Link Shortener</title>
<script type="text/javascript">
function performCommand(event) {
if (event.command != 'shortenlink') return false;
var url = safari.application.activeBrowserWindow.activeTab.url;
var requestURL = safari.extension.settings.endpoint;
requestURL += '/api/v2/action/shorten?';
requestURL += 'key=' + safari.extension.secureSettings.apikey;
requestURL += '&url=' + encodeURIComponent(url);
requestURL += '&is_secret=false';
var request = new XMLHttpRequest();
request.open("GET", requestURL, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
alert(request.responseText);
} else {
alert('Failed to shorten link.');
}
}
}
request.send();
}
safari.application.addEventListener('command', performCommand, true);
</script>
</head>
<body>
</body>
</html>