Permalink
Browse files

added support for delicious, rss/atom feeds

  • Loading branch information...
1 parent 0e52da5 commit e3747826663fee9c591d69e4b0243aeb5ca3d0d2 @airportyh committed Jun 6, 2010
Showing with 92 additions and 9 deletions.
  1. +12 −0 delicious.html
  2. +4 −0 delicious.js
  3. +12 −0 feeds.html
  4. +6 −0 feeds.js
  5. +1 −2 index.html
  6. +15 −0 jsonp.js
  7. +1 −1 marklet.js
  8. +41 −6 wordyclouds.js
View
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Delicious</title>
+ <script src="jsonp.js"></script>
+ <script src="wordyclouds.js"></script>
+ <script src="delicious.js"></script>
+ </head>
+ <body>
+ <h1>Delicious</h1>
+ </body>
+</html>
View
@@ -0,0 +1,4 @@
+function loadDeliciousTags(){
+ WordyClouds.loadFromDelicious('airportyh')
+}
+window.onload = loadDeliciousTags
View
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Feeds</title>
+ <script src="jsonp.js"></script>
+ <script src="wordyclouds.js"></script>
+ <script src="feeds.js"></script>
+ </head>
+ <body>
+ <h1>Feeds</h1>
+ </body>
+</html>
View
@@ -0,0 +1,6 @@
+function loadFeed(){
+ var url = 'http://tobyho.com/user/airportyh/rss.xml'
+ var numEntries = 10
+ WordyClouds.loadFromFeed(url, numEntries)
+}
+window.onload = loadFeed
View
@@ -2,10 +2,9 @@
<html>
<head>
<title>WordyCloud</title>
- <script src="ecma5array.js"></script>
<script src="wordyclouds.js"></script>
</head>
-<body onload="main()">
+<body onload="WordyClouds.runBookmarklet()">
I've followed engadget's live blog, seen the keynote video, listened to Tom and Molly talk about it, even read others' opinions on engadget, gdgt and twitter, etc etc. I guess you could say I am pretty excited.
The tech savy(engadget, gdgt, BOL, etc) are in general underwhelmed or disappointed. Below are some of the complaints I have heard:
View
@@ -0,0 +1,15 @@
+var JSONP = {}
+JSONP.get = function(url, callback){
+ var scriptTag = document.createElement('script')
+ var callbackName = '_' + new Date().getTime()
+ window[callbackName] = function(){
+ callback.apply(null, arguments)
+ delete window[callbackName]
+ }
+ if (url.indexOf('?') != -1)
+ url += '&callback=' + callbackName
+ else
+ url += '?callback=' + callbackName
+ scriptTag.src = url
+ document.head.appendChild(scriptTag)
+}
View
@@ -1 +1 @@
-main()
+WordyClouds.runBookmarklet()
View
@@ -111,6 +111,17 @@ function boxesOverlap(ax, ay, aw, ah, bx, by, bw, bh){
return true
}
+function stripHTML(oldString) {
+ var data = []
+ var inTag = false;
+ for(var i = 0; i < oldString.length; i++) {
+ var chr = oldString.charAt(i)
+ if (chr == '<') inTag = true;
+ if (chr == '>') inTag = false;
+ if(!inTag) data.push(chr)
+ }
+ return data.join('');
+}
/* ========== Layouts ============================ */
@@ -155,6 +166,7 @@ Layouts.randomAvoid = function RandomAvoidLayout(freq, canvas, colors, fontName)
//words = words.slice(0, 200)
words.forEach(function(word){
var textHeight = freq[word] * sizeScale
+ if (textHeight < 5) return
//console.log('word[' + word + '].height = ' + textHeight)
context.font = textHeight + 'px ' + fontName
var textWidth = context.measureText(word).width
@@ -208,18 +220,20 @@ Layouts.randomAvoid = function RandomAvoidLayout(freq, canvas, colors, fontName)
}else
context.fillText(word, x, y)
- if (vertical) context.rotate(0)
//console.log('box[' + word + ']: ' + box)
})
}
-/* =========== Main ============================== */
+/* =========== main entry point ========================= */
-function main(){
- var layout = Layouts.randomAvoid
- var text = getText(document.body, ['script'])
+WordyClouds = {}
+WordyClouds.loadFromText = function(text){
var commonWords = CommonWords.english
var freq = wordSummary(text, commonWords)
+ this.loadFromWordFreq(freq)
+}
+WordyClouds.loadFromWordFreq = function(freq){
+ var layout = Layouts.randomAvoid
var palate = ColorPalates.autumn
var fontName = getComputedStyle(document.body)['font-family']
var canvas = document.createElement('canvas')
@@ -232,4 +246,25 @@ function main(){
document.body.style.overflow = 'hidden'
layout(freq, canvas, palate, fontName)
}
-
+WordyClouds.loadFromDelicious = function(username){
+ JSONP.get('http://feeds.delicious.com/feeds/json/tags/' + username, function(data){
+ WordyClouds.loadFromWordFreq(data)
+ })
+}
+WordyClouds.loadFromFeed = function(url, numEntries){
+ numEntries = numEntries || 10
+ var rand = new Date().getTime()
+ JSONP.get('http://www.google.com/uds/Gfeeds?context=1&num=' + numEntries + '&hl=en&output=json&q=' + url + '&v=1.0&nocache=' + rand, function(v, data){
+ var entries = data.feed.entries
+ var text = ''
+ entries.forEach(function(entry){
+ text += entry.title + '\n'
+ text += stripHTML(entry.content) + '\n'
+ })
+ WordyClouds.loadFromText(text)
+ })
+}
+WordyClouds.runBookmarklet = function(){
+ var text = getText(document.body, ['script'])
+ this.loadFromText(text)
+}

0 comments on commit e374782

Please sign in to comment.