Created
January 31, 2015 11:22
-
-
Save tuxtina/99826f955d47c5525a02 to your computer and use it in GitHub Desktop.
Delicious JavaScript Tag API Replacement (List + Simple Tag Cloud)
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
<html> | |
<head> | |
<title>Delicious JavaScript Tag API Replacement (Tag Cloud)</title> | |
</head> | |
<body> | |
<div id="deliciousPlaceholder"></div> | |
<script type="text/javascript"> | |
"use strict"; | |
var username = "delicious"; | |
var minFont = 14; | |
var maxFont = 36; | |
var ignoreFiletypes = true; | |
var minCount = 1; | |
var tagURLPrefix = "http://delicious.com/" + username + "/"; | |
function printDeliciousCloud(tags) | |
{ | |
var out = ""; | |
var maxCount; | |
var factor; | |
var offset; | |
var visibleTags; | |
// find all tags matching our min count and exclude filetypes as needed | |
visibleTags = []; | |
maxCount = 0; | |
for (tag in tags) { | |
if (tags.hasOwnProperty(tag)) { | |
if (tags[tag] > maxCount) { | |
maxCount = tags[tag]; | |
} | |
if ( | |
tags[tag] >= minCount && | |
(!ignoreFiletypes || tag.indexOf(":") == -1) | |
) { | |
visibleTags[visibleTags.length] = tag; | |
} | |
} | |
} | |
// sort the tags alphabetically (case-insensitive) | |
visibleTags.sort(function (a, b) { | |
return a.toLowerCase().localeCompare(b.toLowerCase()); | |
}); | |
// the tag cloud looks nicer if we use a logarithmic function, so fit | |
// one to our configured font sizes and min count | |
factor = (minFont - maxFont) / (Math.log(minCount) - Math.log(maxCount)); | |
offset = maxFont - (factor * Math.log(maxCount)); | |
// print the tag cloud | |
for (var i = 0; i < visibleTags.length; i++) { | |
var size; | |
var style; | |
var tag; | |
tag = visibleTags[i]; | |
size = offset + (factor * Math.log(tags[tag])); | |
style = 'text-decoration:none; color:#73adff; font-size:' + size + 'px;'; | |
out += '<a href="' + tagURLPrefix + tag + '" style="' + style + '" title="' + tags[tag] + ' bookmarks">'; | |
out += tag; | |
out += '</a> '; | |
} | |
document.getElementById("deliciousPlaceholder").innerHTML = out; | |
} | |
</script> | |
<script type="text/javascript" src="http://feeds.delicious.com/v2/json/tags/delicious?callback=printDeliciousCloud"></script> | |
</body> | |
</html> |
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
<html> | |
<head> | |
<title>Delicious JavaScript Tag API Replacement (Basic List)</title> | |
</head> | |
<body> | |
<div id="deliciousPlaceholder"></div> | |
<script type="text/javascript"> | |
var username = "delicious"; | |
var ignoreFiletypes = true; | |
var minCount = 1; | |
var tagURLPrefix = "http://delicious.com/" + username + "/"; | |
function printDeliciousTags(tags) | |
{ | |
var out = ""; | |
var visibleTags; | |
// find all tags matching our min count and exclude filetypes as needed | |
visibleTags = []; | |
maxCount = 0; | |
for (tag in tags) { | |
if (tags.hasOwnProperty(tag)) { | |
if (tags[tag] > maxCount) { | |
maxCount = tags[tag]; | |
} | |
if ( | |
tags[tag] >= minCount && | |
(!ignoreFiletypes || tag.indexOf(":") == -1) | |
) { | |
visibleTags[visibleTags.length] = tag; | |
} | |
} | |
} | |
// sort the tags alphabetically (case-insensitive) | |
visibleTags.sort(function (a, b) { | |
return a.toLowerCase().localeCompare(b.toLowerCase()); | |
}); | |
// print the tags | |
out += '<ul>'; | |
for (var i = 0; i < visibleTags.length; i++) { | |
var tag; | |
tag = visibleTags[i]; | |
out += '<li><a href="' + tagURLPrefix + tag + '">'; | |
out += tag + ' (' + tags[tag] + ' bookmarks)'; | |
out += '</a></li>'; | |
} | |
out += '</ul>'; | |
document.getElementById("deliciousPlaceholder").innerHTML = out; | |
} | |
</script> | |
<script type="text/javascript" src="http://feeds.delicious.com/v2/json/tags/delicious?callback=printDeliciousTags"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment