forked from visnup/Minimal-Status-Bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.html
70 lines (64 loc) · 2.42 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
safari.application.addEventListener('message', function handleMessage(e) {
switch (e.name) {
case 'hover':
var s = getStatus(e.message);
e.target.page.dispatchMessage('displayStatus', s);
if (safari.extension.settings.longURL && !safari.application.privateBrowsing.enabled) {
// TODO debounce?
lengthenURL(e.message.href, function(result) {
var url = result['long-url'];
if (url) e.target.page.dispatchMessage('displayStatus', s + ' (' + url + ')');
});
}
}
}, false);
function getStatus(options) {
var href = options.href.trim()
, email = href.match(/^mailto:([^?]+)(\?subject=([^&]+))?/i);
if (email) {
return 'Send email to ' + email[1] + (email[3] ? ' with subject “' + decodeURIComponent(email[3]) + '”' : '');
} else if (options.metaKey) {
if (options.altKey) {
return 'Open “' + href + '” in a new window behind the current window';
} else {
return 'Open “' + href + '” in a new tab behind the current one';
}
} else if (options.altKey) {
return 'Download “' + href + '”';
} else if (options.ctrlKey) {
return 'Display a menu for “' + href + '”';
} else if (options.target) {
return 'Open “' + href + '” in a new tab';
} else {
return 'Go to “' + href + '”';
}
}
var shortURL;
getJSON('http://api.longurl.org/v2/services?format=json', function(r) {
shortURL = new RegExp('://(' + Object.keys(r).join('|') + ')', 'i');
});
function isShortURL(url) {
return shortURL && url.match(shortURL);
}
function lengthenURL(url, callback) {
if (isShortURL(url))
getJSON('http://api.longurl.org/v2/expand?format=json&url=' + encodeURIComponent(url), callback);
}
function getJSON(url, callback) {
var xhr = new XMLHttpRequest
xhr.open('GET', url);
xhr.onreadystatechange = function(e) {
if (xhr.readyState === 4 && xhr.status === 200)
callback(JSON.parse(xhr.responseText));
};
xhr.send();
}
</script>
</head>
<body></body>
</html>