Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Daring Fireball with Comments for iPad Bookmarklet Version 2

By: a guest on Jan 16th, 2013  |  syntax: None  |  size: 9.33 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ever wanted to use Daring Fireball with Comments (http://daringfireballwithcomments.net) on your iPad?
  2.  
  3. VERSION 2 - because i make misstakes.
  4.  
  5. Create a bookmark and paste the following code into it. Then just visit daringfireball.net and hit the bookmark. You get comment indicators on the posts.
  6. Just tap one of them, when loaded just use the bookmark again to load the comments.
  7.  
  8. This code is shit, but it works.
  9.  
  10. It contains som stuff not made by be:
  11.  
  12. jQuery Cookie Plugin v1.3
  13. https://github.com/carhartl/jquery-cookie
  14. Copyright 2011, Klaus Hartl
  15. licensed under the MIT or GPL Version 2 licenses
  16. Used because I'm too lazy to do cookies with pure JS.
  17.  
  18. jQuery.ajax mid - CROSS DOMAIN AJAX
  19. James Padolsey (http://james.padolsey.com)
  20. Used to fetch data from a source that is not JSONP-compatible from a different domain.
  21.  
  22. The original Daring Fireball with Comments extension for Safari
  23. Bits of it, modified for jQuery.
  24.  
  25. It loads jQuery from google (because I'm to lazy to bother writing pure JS).
  26.  
  27. All JSON-data is pulled from daringfireballwithcomments.net through query.yahooapis.com because daringfireballwithcomments.net does not return JSONP.
  28.  
  29. Do with this what you like. I am not responsible for any shit that happens.
  30.  
  31. Enjoy.
  32.  
  33.  
  34. javascript:(function(){var v="1.4.1";if(window.jQuery===undefined||window.jQuery.fn.jquery<v){var done=false;var script=document.createElement("script");script.src="http://ajax.googleapis.com/ajax/libs/jquery/"+v+"/jquery.min.js";script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;initMyBookmarklet()}};document.getElementsByTagName("head")[0].appendChild(script)}else{initMyBookmarklet()}function initMyBookmarklet(){(window.myBookmarklet=function(){jQuery.ajax=(function(_ajax){var protocol=location.protocol,hostname=location.hostname,exRegex=RegExp(protocol+'//'+hostname),YQL='http'+(/^https/.test(protocol)?'s':'')+'://query.yahooapis.com/v1/public/yql?callback=?',query='select * from html where url="{URL}" and xpath="*"';function isExternal(url){return!exRegex.test(url)&&/:\/\//.test(url)}return function(o){var url=o.url;if(/get/i.test(o.type)&&!/json/i.test(o.dataType)&&isExternal(url)){o.url=YQL;o.dataType='json';o.data={q:query.replace('{URL}',url+(o.data?(/\?/.test(url)?'&':'?')+jQuery.param(o.data):'')),format:'xml'};if(!o.success&&o.complete){o.success=o.complete;delete o.complete}o.success=(function(_success){return function(data){if(_success){_success.call(this,{responseText:(data.results[0]||'').replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi,'')},'success')}}})(o.success)}return _ajax.apply(this,arguments)}})(jQuery.ajax);(function($,document,undefined){var pluses=/\+/g;function raw(s){return s}function decoded(s){return decodeURIComponent(s.replace(pluses,' '))}var config=$.cookie=function(key,value,options){if(value!==undefined){options=$.extend({},config.defaults,options);if(value===null){options.expires=-1}if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days)}value=config.json?JSON.stringify(value):String(value);return(document.cookie=[encodeURIComponent(key),'=',config.raw?value:encodeURIComponent(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''))}var decode=config.raw?raw:decoded;var cookies=document.cookie.split('; ');for(var i=0,l=cookies.length;i<l;i++){var parts=cookies[i].split('=');if(decode(parts.shift())===key){var cookie=decode(parts.join('='));return config.json?JSON.parse(cookie):cookie}}return null};config.defaults={};$.removeCookie=function(key,options){if($.cookie(key)!==null){$.cookie(key,null,options);return true}return false}})(jQuery,document);jQuery('<style type="text/css">#Banner{position:relative}#Banner a{position:relative;width:347px;height:80px;display:block}#Banner a img{z-index:100}#Banner a .withComments{position:absolute;top:0;left:0;background-image:url(logo_overlay.png);width:347px;height:80px}#Banner img:hover{background-color:transparent!important}#Banner a:hover{background-color:#555e66!important}.article.comments{margin-top:0!important}#Main .permalink{font-size:10px!important;color:#cdcdcd!important;padding:6px 7px 5px 7px!important;font-family:Verdana,"Bitstream Vera Sans",sans-serif!important}#Main .permalink img{border:0 solid transparent!important;margin-bottom:-4px!important}#Main .article .permalink{margin:0 0 0 -7px!important;padding:8px 7px 5px 7px!important}dl.commentsMinusShutup dt a:link,dl.commentsMinusShutup dt a:visited{border-bottom:0!important}dl.commentsMinusShutup dd{margin:auto auto 1em .2em!important}dl.commentsMinusShutup dd .comment{border-left:1px solid #777!important;padding-left:1em!important}dl.commentsMinusShutup dd .smallprint:link,dl.commentsMinusShutup dd .smallprint:visited{display:block!important;margin:-.7em 0 0 -.6em!important;text-decoration:none!important;border-bottom:none!important;font-size:10px!important;color:#ccc!important;padding:3px!important}dl.commentsMinusShutup dd .smallprint:hover{background:none!important;border-bottom:none!important}form input.name,form input.website{text-transform:none!important;letter-spacing:0!important;width:204px!important;margin:3px 0!important;left:0!important}textarea{background-color:#ddd!important;width:204px!important;height:200px!important;margin:3px 0!important}.dfwcindex .article .permalink{display:block}.withComments,.comments{display:block!important}</style>').appendTo("head");function addComment(dl,id,name,text,date){var anchor=document.createElement('a');anchor.name='comment'+id;dl.appendChild(anchor);var dt=document.createElement('dt');dt.innerHTML=name;dl.appendChild(dt);var dd=document.createElement('dd');var comdiv=document.createElement('div');comdiv.className='comment';comdiv.innerHTML=text;dd.appendChild(comdiv);var a=document.createElement('a');a.href=document.location.pathname+"#comment"+id;a.className='smallprint';a.innerHTML='★ <em>'+date+'</em>';dd.appendChild(a);dt.appendChild(dd)}function addCommentCounts(data){$('.permalink').each(function(i){$e=jQuery(this);console.log($e.attr('href'));var x=$e.attr('href').replace('http://daringfireball.net','');console.log(data[x]);if(data[x]==1)$e.html(''+data[x]+' comment');else if(data[x])$e.html(''+data[x]+' comments');else $e.html('Comments');$e.attr('href',$e.attr('href')+"#comments")})}var ver=2;if($('.ookiaks').length>0){jQuery.ajax({url:'http://daringfireballwithcomments.net/commentcounts',data:{version:ver},type:'get',success:function(json){addCommentCounts(jQuery.parseJSON(jQuery(json.responseText).text())[0])},error:function(){alert("Error")},})}else if(document.location.pathname.indexOf('/linked/')>-1||jQuery('#PreviousNext')){jQuery('body').addClass('dfwcarticle');var areadiv=document.createElement('div');areadiv.className='article comments';var anchor=document.createElement('a');anchor.name='comments';areadiv.appendChild(anchor);var h1=document.createElement('h1');h1.innerHTML='Comments';areadiv.appendChild(h1);dl=document.createElement('dl');dl.id='DFWC';dl.className='commentsMinusShutup';areadiv.appendChild(dl);var form=document.createElement('form');form.action='http://daringfireballwithcomments.net/comment?version='+ver;form.method='post';form.innerHTML='<fieldset style="text-align:center;"><legend>Leave a Comment</legend><table style="margin: 0 auto 1em auto;"><tr><td align="right"><label for="name">Name (optional):</label></td>  <td valign="top"><input type="text" name="name" class="name" value="" /></td></tr><tr><td align="right"><label for="website">Website (optional):</label></td>  <td valign="top"><input type="text" name="website" class="website" value="" /></td></tr><tr valign="top"><td align="right"><label for="comment" style="display: block; margin-top: .4em;">Comment:</label></td>  <td><textarea name="comment"></textarea></td></tr></table><p><input type="submit" name="submit_comment" value="Leave a Comment" style="width: 10em;" /></p></fieldset>';if(jQuery.cookie('name'))jQuery(form).find('.name').val(jQuery.cookie('name'));if(jQuery.cookie('website'))jQuery(form).find('.website').val(jQuery.cookie('website'));jQuery(form).submit(function(){jQuery.cookie('name',jQuery(form).find('.name').val(),{path:'/',duration:60});jQuery.cookie('website',jQuery(form).find('.website').val(),{path:'/',duration:60});return true});var permainput=document.createElement('input');permainput.type='hidden';permainput.name='permalink';permainput.value=document.location.pathname;form.appendChild(permainput);areadiv.appendChild(form);if(jQuery('#PreviousNext'))h1.style.marginTop='100px';jQuery('#Main #Footer').before(areadiv);jQuery.ajax({url:'http://daringfireballwithcomments.net/comments'+document.location.pathname+'',data:{version:ver},type:'get',success:function(data){json=data.responseText;json=json.replace(/\r\n/g,'');json=json.replace(/\s+/g," ");json=json.replace(/<\/p>\s<p>/g,'<p>');json=json.replace(/&lt;\\\/p&gt;/g,'</p>');json=json.replace('<html> <head> <meta content="HTML Tidy for Java (vers. 26 Sep 2004), see www.w3.org" name="generator"/> <title/> </head> <body> <p>','');json=json.replace('</p> </body> </html>','');var comments=(jQuery.parseJSON(json));for(var i=0;i<comments.length;i++){addComment(dl,comments[i].id,comments[i].name,comments[i].text,comments[i].date)}},error:function(){alert("Error")},})}})()}})();