-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgistmarklet.js
54 lines (48 loc) · 1.97 KB
/
gistmarklet.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var load_gistmarklet = function() {
$('#landing').hide();
$('#loading').show();
var id = location.hash.slice(1);
$('#header input').val(id);
$.getJSON('https://api.github.com/gists/' + id + '?&callback=?',
function(data) {
for (var filename in data.data.files) break;
script = data.data.files[filename].content;
if (script.slice(0, 11) != 'javascript:')
script = 'javascript:' + script;
$('#gistmarklet a').eq(0)
.attr('href', script)
.text(data.data.description)
.bookmarkletHelperArrow({pos: 350});
$('#gistmarklet a').eq(1)
.attr('href', 'https://gist.github.com/' + id);
document.title = 'GistMarklets: ' + data.data.description;
$('#loading').hide();
$('#gistmarklet').show();
if (navigator.userAgent.indexOf('Chrome') > 0)
$('#note').text('You may need to press ctrl+b to show your bookmarks bar');
else if (navigator.userAgent.indexOf('Firefox') > 0)
$('#note').text('You may need to show your bookmarks bar. Firefox menu > preferences > Bookmarks Toolbar');
else if (navigator.userAgent.indexOf('MSIE') > 0)
$('#note').text('IE not fully supported yet');
else
$('#note').text('');
});
}
var hashchange_func =
$(document).ready(function() {
$(window).bind('hashchange', function() {
if (location.hash == '') {
$('#header input').val('');
$('#landing').show();
$('#loading').hide();
$('#gistmarklet').hide();
document.title = 'GistMarklets';
$('#demo a').bookmarkletHelperArrow({pos: 350});
} else {
load_gistmarklet();
}
}).trigger('hashchange');
$('#header .button').click(function() {
location.hash = '#' + $(this).siblings('input').val();
});
});