Skip to content

Instantly share code, notes, and snippets.

@tuxtina
Created January 31, 2015 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxtina/99826f955d47c5525a02 to your computer and use it in GitHub Desktop.
Save tuxtina/99826f955d47c5525a02 to your computer and use it in GitHub Desktop.
Delicious JavaScript Tag API Replacement (List + Simple Tag Cloud)
<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>&nbsp; ';
}
document.getElementById("deliciousPlaceholder").innerHTML = out;
}
</script>
<script type="text/javascript" src="http://feeds.delicious.com/v2/json/tags/delicious?callback=printDeliciousCloud"></script>
</body>
</html>
<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