-
-
Save tallykatt/e1f3d2dd5759ff2ae33ac5c235b2cfd3 to your computer and use it in GitHub Desktop.
the bookmarklet bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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