forked from jneug/osx-script-stuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeticon.js
37 lines (36 loc) · 1.13 KB
/
geticon.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
/*
name: Get Icon
apps: Safari, Chrome
description: Shows an icon for the current page. Requires jQuery.
parameters:
compile: false
*/
function $sorted(selector, attrName) {
return $($(selector).toArray().sort(function(a, b) {
var aVal = parseInt(a.getAttribute(attrName));
var bVal = parseInt(b.getAttribute(attrName));
return aVal - bVal;
}));
}
var icons = $sorted('link[rel=apple-touch-icon]', 'sizes').last();
if (icons.length === 0) {
icons = $sorted('link[rel=apple-touch-icon-precomposed]', 'sizes').last();
}
if (icons.filter('[href]').length > 0) {
window.location = icons.attr('href');
} else {
$('img').each(function(i, e) {
$(e)
.css('border', '2px dashed lime')
.css('cursor', 'pointer')
.hover(function() {
$(this).css('border', '2px dashed magenta');
}, function(e) {
$(this).css('border', '2px dashed lime');
})
.click(function(e) {
e.preventDefault();
window.location = $(this).attr('src');
});
});
}