Created
December 24, 2008 08:00
-
-
Save dustin/39613 to your computer and use it in GitHub Desktop.
HTML to generate an HTML list of related links for you.
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<!-- Copyright (c) 2008 Dustin Sallings <dustin+html@spy.net> --> | |
<html lang="en"> | |
<head> | |
<title>Relativity.</title> | |
<style type="text/css"> | |
img { border: 0; margin-right: 2px; } | |
textarea { overflow: scroll; } | |
input { width: 350px; } | |
</style> | |
<script type="text/javascript" | |
src="http://code.jquery.com/jquery-latest.js"></script> | |
<script type="text/javascript"> | |
var my_url = null; | |
function makeLink(url) { | |
var domain=url.split("/")[2]; | |
var sdom=domain.split("."); | |
sdom=sdom[sdom.length - 2]; | |
var img="http://www.google.com/s2/favicons?domain=" + domain; | |
return '<a rel="me" href="' + url + '">' + | |
'<img alt="' + sdom +'" src="' + img + '"/></a>\n'; | |
} | |
function drawStuff(graph) { | |
console.log(graph); | |
var icons=document.getElementById('icons'); | |
var text=[]; | |
for (var node in graph.nodes) { | |
var n = graph.nodes[node]; | |
if (n.nodes_referenced_by[my_url]) { | |
$(icons).append(makeLink(node)); | |
text.push(makeLink(node)); | |
} | |
} | |
var formthing=document.getElementById('content'); | |
formthing.value = text.join(""); | |
$('#icons').fadeIn("slow"); | |
$('#sample-input').fadeIn("slow"); | |
} | |
function getArgs() { | |
var args = {}; | |
var query = location.search.substring(1); | |
var pairs = query.split("&"); | |
for(var i = 0; i < pairs.length; i++) { | |
var pos = pairs[i].indexOf('='); | |
if (pos == -1) continue; | |
var argname = pairs[i].substring(0,pos); | |
var value = pairs[i].substring(pos+1); | |
args[argname] = unescape(value); | |
} | |
return args; | |
} | |
$('body').ready(function() { | |
var a = getArgs(); | |
if(a.u) { | |
my_url = a.u; | |
document.getElementById('u-input').value=my_url; | |
var s = document.createElement("script"); | |
s.src = 'http://socialgraph.apis.google.com/lookup?q=' + my_url + | |
'&fme=1&edi=1&edo=1&callback=drawStuff'; | |
s.type = 'text/javascript'; | |
$('body').append(s); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<form method="get" action="autolinks.html"> | |
<fieldset> | |
<legend>Your URL</legend> | |
<input type="text" name="u" id="u-input" | |
value="http://bleu.west.spy.net/~dustin/"></input> | |
</fieldset> | |
</form> | |
<div style="display: none" id="icons"> | |
</div> | |
<form id="sample-input" style="display: none" method="post" action=""> | |
<textarea rows="30" cols="150" id="content"></textarea> | |
</form> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment