Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
the bookmarklet bookmarklet
function getJSON (url, callback) {
var xhr;
xhr = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (callback) {
callback(xhr.responseText);
}
}
};
xhr.open('GET', url, true);
xhr.send(JSON.stringify(json));
}
getJSON('https://api.github.com/users/fiatjaf/gists', function (gists) {
var bookmarklets = [];
for (var i = 0; i < gists.length; i++) {
var gist = gists[0];
if (gist.description.search('bookmarklet')) {
for (var file in gist.files) {
if (gist.files[file].language == 'JavaScript') {
bookmarklets.push(gist.files[file].raw_url);
}
}
}
else {
for (var file in gist.files) {
if (file.search('bookmarklet') && gist.files[file].language == 'JavaScript') {
bookmarklets.push(gist.files[file].raw_url);
}
}
}
}
var items = ''
for (var i = 0; i < bookmarklets; i++) {
items.push('<li><a data-src="' + bookmarklets[i] + '">' + bookmarklets[i].split('/').slice(-1)[0] + '</a></li>')
}
var list = '<div id="bookmarklets-list" style="position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-100px;width:300px;height:200px;"><ul>'
+ items
+ '</ul></div>';
document.write(list);
document.getElementById('#bookmarklets-list').addEventHandler(function (e) {
e.preventDefault()
if (e.target.tag == 'LI') {
console.log(e.target.dataset.src)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.