From d139da3a3277f73d7f01e4283d8dc01630a5317c Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Mon, 20 Oct 2014 16:38:24 -0700 Subject: initial setup --- source/javascripts/pinboard.js | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 source/javascripts/pinboard.js (limited to 'source/javascripts/pinboard.js') diff --git a/source/javascripts/pinboard.js b/source/javascripts/pinboard.js new file mode 100644 index 00000000..a97df03d --- /dev/null +++ b/source/javascripts/pinboard.js @@ -0,0 +1,56 @@ +function pinboardNS_fetch_script(url) { + //document.writeln(''); + (function(){ + var pinboardLinkroll = document.createElement('script'); + pinboardLinkroll.type = 'text/javascript'; + pinboardLinkroll.async = true; + pinboardLinkroll.src = url; + document.getElementsByTagName('head')[0].appendChild(pinboardLinkroll); + })(); +} + +function pinboardNS_show_bmarks(r) { + var lr = new Pinboard_Linkroll(); + lr.set_items(r); + lr.show_bmarks(); +} + +function Pinboard_Linkroll() { + var items; + + this.set_items = function(i) { + this.items = i; + } + this.show_bmarks = function() { + var lines = []; + for (var i = 0; i < this.items.length; i++) { + var item = this.items[i]; + var str = this.format_item(item); + lines.push(str); + } + document.getElementById(linkroll).innerHTML = lines.join("\n"); + } + this.cook = function(v) { + return v.replace('<', '<').replace('>', '>>'); + } + + this.format_item = function(it) { + var str = "
  • "; + if (!it.d) { return; } + str += "

    " + this.cook(it.d) + ""; + if (it.n) { + str += "" + this.cook(it.n) + "\n"; + } + if (it.t.length > 0) { + for (var i = 0; i < it.t.length; i++) { + var tag = it.t[i]; + str += " " + this.cook(tag).replace(/^\s+|\s+$/g, '') + " "; + } + } + str += "

  • \n"; + return str; + } +} +Pinboard_Linkroll.prototype = new Pinboard_Linkroll(); +pinboardNS_fetch_script("https://feeds.pinboard.in/json/v1/u:"+pinboard_user+"/?cb=pinboardNS_show_bmarks\&count="+pinboard_count); + -- cgit v1.2.1