Query-String Input Autofiller

There are some sites like Twitter which take a query-string type input and autofill an important text box on the page. If you’ve used Summize to reply to someone, you would have seen the ‘Reply’ link point to something like:

http://twitter.com/home?status=<text>

It’s a handy shortcut to predefining the value of text boxes, and can be coupled with features like Firefox’s bookmark keyword feature for some handy short-cuts. Unfortunately, not all sites do that. This userscript aims to solve that problem.

How it works

A more comprehensive explanation is given at the Userscripts.org repository, but in brief, it analyses the appended query-string to your URL and resolves it into a key and a value. It looks for a input box with the ID attribute specified by the key, and prepopulates it with the value. What’s left is to just submit the form.

The script also adds a hover tip on all text boxes which show the ID of that box, to make it easier for you to know what key to use to populate which box.

Query String Input Autofiller
All my userscripts

Update: The script now checks for the ID and name both, to find the text box to auto-fill. name is a fallback after an ID search. (thanks @singpolyma)


A Textual Experience

I’ve been an advocate of writing beautiful code, right from the time I began writing pieces of code myself. Functional code is the ultimate aim for all developers, one that defines how they tackle a problem. But beautiful code is an arbitrary and subjective concept. Codes with comments and in-line explanations are beautiful to me. They might be cluttered for you. Indented and terminated lines make code easier to read for my brain. They might be superfluous ornamentation to you.

We write code the way we see the problem. A quick-fix solution gathers the ugliest, most crammed-up code ever known to man. Large, modular projects automatically receive the most well documented and clear code. It’s just how the mind is tuned to work — with the destination influencing our methodology.

The natural feeling

Code is usually the furthest thing away from “natural”, and CSS sticks close to those roots better than most. Repetitive colour hex values and attribute:value pairs are just two of the many things that drive me insane whenever I sit down to write the style-sheet for my pages. The lack of a visual hierarchy is a close third, which makes debugging and changing things just that much harder. CSS just doesn’t feel natural enough, and you end up having to take care of your brackets, semi-colons and quote-marks more than the style itself. It’s ironical how a language for visual presentation is so ugly in itself.

These annoyances are probably not annoyances any more to designers who have been dabbling with CSS for many years, because they’ve become accustomed to the ugliness. But the point has to be made that just because we are used to the wrong way of doing things, doesn’t make the way any right-er.

I don’t propose a change in the in the syntax of the language. The implementation itself is rock solid. What we need is something to form a bridge between readable, visually clean code, and the standardised, already established syntax that we’ve all come to love or hate. The aim is not to create a new syntax in itself (why re-invent the wheel?), but leverage the current one to work with our way of working.

Textualise

Combining the above points, Textual aims to make styling just that much easier, but keeps the most familiar elements of CSS the same so that you don’t rattle into the unknown. It doesn’t include short-cuts or pre-definitions. It is not a framework either. If you think you’re alright with traditional CSS, I will not argue. But Textual is just a better way to do what you’ve already been doing. Your code[^1] will look and feel right, and the output will be just what you would expect. The CSS is well-formed and W3C valid, so that is one worry that isn’t a worry. The output is mini-fied, hence load times are fast.

The syntax is explained on the project page, but I think it’ll come to more naturally than you’ll believe.


Introducing Textual

As stated previously, I have written a text-to-CSS conversion engine for designers to use and abuse. Currently, it’s not available for download because it is still in alpha and very unreliable. You can give it a whirl over at the demo page, and if you like it, send me a mail and I will be glad to send you the current package. I just don’t want the source in too many hands at the moment.

Textual takes a plain-text as input, and spits out valid, well-formed and mini-fied CSS. The syntax and and usage is explained in a cheat-sheet format at the demo. As far as I know, there is no other engine of this sort out there, so I hope to be breaking new grounds. The engine is written completely in PHP, and I have plans to port this to Perl and maybe ASP (but not anytime soon).

Any and every feedback is most welcome, as are suggestions for syntax (I want to make it as intuitive as possible) and features, criticisms (don’t know why, but constructive only) and downright volunteers to help make it better (PHP dabblers only).

If you like it, go back one paragraph and do one of those. I will try to sell you on the concept in about a days time if you’re still skeptical.

(Yes. I changed the name from CSSEngine to Textual, for creative reasons)


The Quick Word Meaning Searching Thingamajig

Ever since definr came out, I’ve been using it religiously for any and every word meaning related doubt I’ve had. It’s really good and fast, and keeps my Google Search history clean :) But the problem I’ve always faced is going to the site and typing in my word. Too much work. So I cooked up this quick Greasemonkey script to handle that situation.

Sits nicely in the corner until called!

The script adds a tiny box to the bottom-left corner, which stays 3/4th hidden away, until you focus on it. Focus is through a click, or using the shortcut Shift + Alt + S. Wait for a second after you’ve finished typing, and it’ll start searching. Definr being as fast as it is, the results will show up almost immediately. Click anywhere else, and everything will get tucked away. It’s simple :)

Nothing more to say. You’ll have to use it to like it. Enjoy!

Userscript

Definr
All my scripts


A Shout Out to Search Suggest Users

It’s been quite a while since I released my Search Suggestions hack. Since then, I’ve seen the number of hashes being created for authorization increase steadily, which means people “are” using it. What I haven’t seen increase, is the number of search “terms” being added to my database.

This can mean one of two things:

  1. You have implemented the hack, but have botched up something in the implementation which is preventing search terms from being added to your account.

  2. You have “not” implemented my hack, and are just sitting pretty with a hash code in my database.

For the first case, if you need help implementing the hack properly, please let me know. I’ll be more than willing to have a look at your code and see where things are being messed up. We all want the suggestions to come up nice and pretty now, don’t we? :)

For the second case, well … if you don’t want to use it, fair enough. Just let me know your passcodes (which you used to get your hashes) so that I can remove them from the database, to prevent them from eating up space :)

Chow!


Who Said That?

This seems to have been broken for a while. Blogger changed the structure of the comment form page, hence it wasn’t getting the comment author’s name properly. I’ve fixed it now. A quick re–install will do :)


There isn’t really much history behind this one, except that it was an idea originally put into my head by Avatar, for the old Blogger. Since back then we had the form as part of the post page, and not a Blogger page, a comment quoting system was the ideal thing for a blog like Bloggeratto which needed Avatar answering tons of questions. Back then when I wrote the script, it was so badly broken that I feel ashamed now of it :P

With the new Blogger, that system broke since the form disappeared. Although, the idea is still a good one, and the necessity of having a comment quoting system became very glaringly obvious to me right after my Blogger Smilies post, where I had to answer tons of comments, and reply to a lot of suggestions. So, I wrote this script a long time back, and it’s been through a _very_ long testing phase. I’m going to finally release it for everyone to use :)

It’s a really simple script, which adds a ‘Reply’ link to all the comments on the comments page, which you can use to add the body of the comment to the form’s input, with all <BR> tags converted to line breaks for ease of use, and the text itself enclosed in a i[rel=”cquote”] element for easy styling. It also wraps the quote in nice curly comments for you :)

Also, when you click the quote link, a link is created back to that quote, and shown right above the input area. That’s for the unusually large number of comments that you might have to reply to all at once :)

Inputs are always welcome! Cheers! :)

What you waiting for?

Blogger Comment Quote / Reply
All my Userscripts


More bVibes Love: Greasemonkey Joins In

Ah! Two updates today :D

While looking around bVibes, I bumped into a post on Hackosphere about remote vibing (?) buttons from bVibes which you can add to your posts. Well, I took it a little out of context, but the effect is pretty much the same :)

With Vibe me later, you can click through to a story from a bVibes page, go through the story, and if you consider it worthwile, vibe it from the page you land on. You won’t have to go back to the story page on bVibes to vote for it. The script adds a (not so good looking, but meh!) small button to the bottom right of your page, which flashes initially to remind you it’s there.

You can use the button to vote whenever you want. Also, the button will only show up for pages linked from bVibes, and when you click through from bVibes. I might recode it to check bVibes for every page you visit … hence make a ‘smart’ vibe button :)

Enjoy!

Links

Vibe me later
All my userscripts


Making Punctuations Look Good!

Oops! Comments got disabled by mistake. Re-enabled them … let me know what you think! :)


Recently, I’ve been rather taken in with smart punctions, rather than the dumb normal ASCII ones. You know, the straight dumbOpposite of ‘smart’ is? ;) quote marks (” and ‘), or the normal ellipsis made up of full stops (…) ? HTML has predefined special entities to draw these rather nicely, but we don’t use them normally because most of us don’t know about them, and Blogger natively doesn’t convert the characters. Typing them out manually can be such a pain, and you need to remember so much more stuff.

So, I worked up a quick Greasemonkey userscript that adds a nice little link in your row of buttons (in the post editor), which you can use to quickly convert all your punctuations to what they should be. Since there is no way of creating a “plug–in” for Blogger, anything which needs to affect a post directly needs to be tackled at the post editor level.

The script is ‘smart’, as in it understands when to use a left curly quote and a right curly quote. It also changes hyphens to what you want them to be. A single or a double ‘–’ generates an en–dash (–), whereas a triple ‘–’ generates an em–dash (—). To know which one to use where, and other punctuation marks, look up the A List Apart article. I referred to it while making this.

Known Bugs and License

Since this went through an extended testing period, and some live testing (I guess you could call it that) on Userscripts, and there hasn’t been a complaint or a request, I’ll assume there to be no bugs :) Except for some weird behaviour when it comes to apostrophes and quotation marks :P And like everything else, this script is licensed under an NC–ND Creative Commons License.

The name for the script is taken from the excellent SmartyPants project, by the oh–so–creative John Gruber. So a big thanks goes out to him for coming up with the idea. I had sent him a mail regarding using of the name and the basic concept. I never got a reply (it’s been about 2 months now), so I took it as a yes and published this :)

Get the script!

Pseudo–SmartyPants for Blogger
All my Userscripts


Search Your Blog From Firefox

A hack to start this lovely week off! Well, not a hack really. You can call this a Native Blog Search for Firefox, without the AJAX :P Steve’s post about adding microformats in your blog gave me the idea (a little late though) about ways in which we can integrate our blogs with Firefox. The various new features in 2.0 make playing around with them a lot of fun.

Firefox 2.0 supports Open Search, and when detected, it automatically highlights the search box button, and from the drop down list, you can add the newly discovered search. You would have seen it on Wikipedia, or Live.com — and now here, on this page!

Add this one itsy bitsy line to your <head> area:

<link href='http://phpplay.ning.com/Open Search/openSearch.php?blogurl=blog_url&amp;name=blog_name&amp;icon=url_to_icon' rel='search' title='blog_name' type='application/opensearchdescription+xml'/>

Replace the required query string variables with the respective details. Note that the blog URL has to be just your blog URL, without the trailing slash. For eg: http://lastword.blogspot.com - nothing more.

After note

While this is a cool thing to have, and gives your readers a faster way to search your blog for anything they want, there is a stupid side effect of this. Searching through this won’t add to your Search Suggest pool. This makes the Search Suggest slightly useless, but hey! I am all for options :P I plan to fix this in the future though. Will give me something to do when I really don’t have anything else ;)

Search away!


You Wanted Suggest, You Got Suggest!

I’m going to start off this week with a teeny weeny bang. Let’s make this a little dramatic (it’s by no means a small thing):

After I released the Native Blog Search, there was a lean period where I was playing around with extending it. It was a good thing, ofcourse, to have your results show up in your page without any hassles of page reloading! But, I also wanted to know what exactly people were looking for on my blog when they came. This served a simple single purpose. To see what people liked to read. It was then that my mind shifted to Google Suggest and how it worked. I didn’t do as much research behind it’s working as Deepak did, but I guessed out a pretty simple technique which would work under any circumstance. I needed a database to store my data, but I didn’t know how to code for a database back then. So I used simple file-handling techniques. It was rather messy, but it got the job done.

However, very recently, I learnt how to work with the Ning Content Store (thanks to Steve for putting up with me on this), and though the process got started by a completely different hack, the requests to release ‘this’ particular hack was at the back of my mind all the time. So I didn’t waste much time (ported it over 6 hours) getting things into place.

As with things like this, there is always the issue of security. I’ve come up with a rather secure ‘token’ system (according to me), but it still can be broken through quite easily. The next most secure thing to do is to get a Ning account if you want to use this as safely as possible, but I guessed you wouldn’t need ‘that’ much security for simple search terms :P So, with all that history and working, let’s get down to actually implementing this little devil of a hack :)

Getchyo’ token!

The first thing to do is to get your security token. It’ll be used for every transfer of data, and keeping things separate. Start by going to the page, and follow the instructions.

It’ll tell you if the password you’ve used is already under use. If it isn’t, you’ve got the hard part over :P Remember, there is no easy way to hide this token. It isn’t such a big deal, but if you’re rather possessive about your search queries, you might as well try and alter the way you add in your token in your page script. Add the following lines to your head area:

<script src='http://jscripts.ning.com/id/3229487?minify'></script>
<script src='http://aditya.vm.googlepages.com/scriptaculous.js?load=effects,controls'></script>
<script src='http://aditya.vm.googlepages.com/searchsuggests.js'></script>
<script>
token = 'insert_token_here';
blogname = 'insert_blog_name';
</script>

Replace the red ‘inserttokenhere’ text with the alphanumeric token string which you got in from the application. The second variable holds the URL name of your blog. For eg: ‘lastword’ for this blog. So, now that you have all the required scripts in place, you’ll have to modify your code for the search box. If you use my Native Blog Search, then you’ll have to change the ID in the main function to cath the value (for the search) from the ID of search-query if it is not set to that. Otherwise, find your the code for your search box, and replace it with this:

<form id="query" action="javascript:submitSearch()" class="search-form">
<input id="search-submit" value="Search" onclick="javascript:submitSearch()" type="submit"/><input id="search-query" autocomplete="off" accesskey="S" name="search-query" size="25" type="text"/>
<div id="nss_options" class="nss_options"></div>
</form>

<div id='nss_options' class='nss_options'></div>
<script>
new_script('http://phpplay.ning.com/getByTags.php?xn_auth=no&token='+token+'&callback=add_val');
check_post_data();
</script>

The DIV is the element which will get filled up with the results whenever you start typing. You can switch the tags’ positioning around to get the required look, but don’t change the significant attributes like the id or onclick. This is pretty much all you have to do. You can style your suggestions ofcourse. These are the definitions you can put in your <style> area:

.nss_options { } /* the container DIV */
.nss_options ul{ } /* the actual list of suggestions */
.nss_options ul li{ } /* each list element */
.nss_options ul li strong { } /* The matched highlight part */
.selected{ } /* The selected suggestion */

That’s it! If everything went well, you should be able to start searching :) Your results will only show up after your first search ofcourse, but you’ll see your list getting nice and populated in a few days if there are many people using the search box on your page.

After notes

I’m again going to bring up the lack of security of your search terms. I can see them, because I own the application. No-one else can see them, unless they use your token to catch your search terms. But they’ll be effectively populating ‘your’ search terms, so it makes no sense for them. But who knows what whim catches who :P

Secondly, the code I’ve provided right now has a buggy way of removing terms which don’t return any results. I plan to work up a better method soon. It’ll be updated in the main include however, so you don’t need to worry about updating your scripts.

Since this hack is hosted up at Ning, your search terms appearing is completely based on their uptime. They should not be going down anytime soon, and as per what has been discovered (if it’s true), their downtime shouldn’t affect output from the applications. But either way, they’ll be back up in less than 24 hours, so your suggestions will show up again soon! :)

Needless to say, this hack uses the oh-so-heavy Prototype.js library. I’ve minified it however, which should shave off about 10-12 kbs. It also uses Script.aculo.us, but since I’m loading only two files from it, it comes to very small file size. Totally, it should be around 60-65 Kbs added to your page size. Moo.fx doesn’t have an auto-completer built in, and people have developed ones for it which I don’t really like. I am eyeing the one developed and demo-ed at brandspankingnew, and plan to eventually move to it. But at the moment, this serves the purpose really well, and I’ve been testing it for over half a year now :) Quite reliable!

Credits

Ah! Credits … This is going to be the first one I’m going to write actual ‘credits’ out for :P Here’s the list:

  • Stephen - Always the helper. He literally taught me how to work with the content store, and about 70% of the PHP I know at the moment. So, this release would have been close to impossible without his help. Thanks mate!
  • All my viewers - I actually had lost all interest in releasing this hack, as I’ve stated in some blog’s comments. But thanks to interest still being shown in it by bleet like Deepak, and the initial burst of requests from people who liked it, I couldn’t ‘not’ have ported it! So thanks a bunch guys!
  • Avatar - as usual, without whom I’d never have really started hacking mainstream! :)

So yea, that’s the list (small as it is), and I hope you enjoy a trouble free search suggest experience. If you have any problems, the first thing to do would be to shoot an e-mail off to me with your token / password. If you’ve forgotten your token, send me your passphrase and I’ll send you your token! Anything else, should be addressed in the comments as usual, since I want everyone to benefit from each other’s doubts. I’ve also added a ‘digg’ button at the top (as seems the latest trend), but only for this post. I’m not submitting this myself, and want ‘you’ to submit it if you feel it’s worth it :)

Also, this hack (like all others on this blog) is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.


Google Reader List Custom Widget

Edit: Big ‘oops’! If it didn’t work for you before, try the new code :) Also, updated the order of codes. The widget changes markup to be XHTML (phssh) standard, which doesn’t work well for any code going in them :( See the updated implementation.


Golden Summer style

I was looking at the Google Reader widget which shows your reading list from a particular label. It’s quite a useful little widget, which doesn’t need any work from you, is automatically updated, and gives a good idea of what’s keeping you interested! But there is one tiny problem, and it’s one I have with a lot of Google services. It simply looks terrible!

Doing it my way!

To overcome that little glitch, I went ahead and wrote my own little script to create your custom Google Reader reading list widget, one that can be styled, and modified to show more content that what the current Reader widget shows. I really didn’t have anything worthwhile to do last Sunday afternoon, so I thought of writing this :P I will explain every aspect of the parts (and it’s commented) which you can change, so that you can have a proper widget which does what ‘you’ want it to do! :)

Add the following to your <head> area:

<script src='http://jscripts.ning.com/id/3484647' type='text/javascript'/>
<script>//<![CDATA[
userID = 'user_no_here';//your GReader ID number you can get from the original reader widget
readerLabel = 'web-2.0';//the label
count = 5;//how many posts?
showSummary = 1;//1 for yes, 0 for no
showCredits = 1;//show the 'by so-so' line, 1 for yes
window.addEventListener('load',function(){new_script('http://www.google.com/reader/public/javascript/user/'+userID+'/label/'+encodeURIComponent(readerLabel)+'?n='+count+'&callback=makeWidget');},true);
//]]></script>

The following is the style template for the different elements in the widget. I’ve commented as to what is what. Change them to suit your blog’s template:

# { /* The container of the whole widget content */
 border:1px dotted #;
 padding: 10px;
 width: 200px;
}

div.block { /* Individual items are held in one block each */
 border-bottom:1px dotted whitesmoke;
 padding-bottom:5px;
 margin-bottom:5px;
}

a.title { /* Title of the item */
 font-size: 8pt;
 font-family: Verdana;
 text-decoration: none;
 color: #;
 }

a.title:hover {
 color: Orange;
 border-bottom:1px solid #;
}

div.summary { /* Summary of the item (in case you want one) */
 color: Khaki;
 font-size:7.5pt;
 font-family: Arial;
}

div.byline { /* Credits/By line of the item */
 margin-top:5px;
 color: #;
 font-size: 7pt;
 text-align:right;
 font-family: Tahoma;
}

Make a new HTML widget in whichever section you want to add the reading list, and copy paste the following lines as the content:

<div id='ReadingList'>
</div>

That’s it! You’re done! :) I still haven’t been able to wrap my head around the One Click Widget thingy. It seems a little painful to set up if you ask me actually, so I am not bothering. I hope my instructions are clear enough :) You can actually try and overwrite the styles of the original Google widget too if you don’t want to go through setting up my version, but you won’t get the customisability of showing names and summaries.

The original Google Reading List follows this heirarchyA ‘.’ means class, and ‘#’ means id. The symbols are what you’ll use to style them in your <style>.:

  • div#readerpublishermodule0.reader-publisher-module
  • h3 (for the title)
  • ul
  • li (each li holds one item)
  • a.i (title of the item)
  • div.s (byline text, contains another link)

If you’d like to see more content/or something I missed out in the custom reading list, leave a comment and I shall look into it! Go ahead, take your pick! :)


Add Captions to Images

Edit: Updated to check for a class="capt" instead of rel. This is to stay in regard with well markup-ness. Thanks to Steve for the tip!


This is one of those things which is so common, you wonder why it isn’t there natively in HTML and CSS. An image without a caption is almost code without comments, not very informative.

So I’ve written a quick piece of code to help you do that. I have it implemented here, and I’d like to see you (my beloved reader) use it! :) Just follow the instructions below, and read carefully, because it adds a few functionalities to a normal image tag.

Just a line

This being another one of my ‘easy addition’ scripts, you just need to add in a simple line:

<script src='http://jscripts.ning.com/id/3459063?minify' type='text/javascript'></script>

To style image and captions, use this default template, and modify it to your liking:

.image_container {/* contains image and caption */
    background-color: #;
    border: 1px solid gray;
    font-family: Verdana, sans-serif;
    padding: 5px;
    margin:5px;
    float:left;
}

.image_container img{/* the image */
     border:1px solid gray;
}

.image_container span {/* the caption */
     color: white;
     display: block;
     font-size:7pt;
     font-weight:bold;
     margin: 5px 0px 0px;
}

That is all it takes to get the captions created :)

Usage

Caption Preview

The usage is pretty simple. Write your image tags like you would normally, and add an attribute class='capt', so that the script can recognise that it needs to captionize that tag. The text for the caption itself will go in an alt attribute.

So, a sample tag which could get captionized would be:

<img src='http://www.google.com/logos/valentine07.gif' class='capt' alt='I love Google!'/>

If you don’t add the alt attribute, it’ll still captionize it, but without a caption (it’ll surround it with a Silver background and add borders).

Another cool thing (one I threw in for fun) that you can do is add an optional align attribute. It can take two values, ‘left’ or ‘right’, which will decide which way your image goes. It basically floats it to the direction specified. Makes for some quick styling. If you leave it empty, it’ll use your container’s default float property if you have one. Here’s a demo page putting everything together.

This script will not affect your images in previous posts, because they won’t have the captionizing attribute, so it’ll leave them alone. Will save you the worry of your previous post’s images going awry!

That’s basically it. Make your images look better! :)


DLTP Labels Widget Updated

Thanks to Cyberbuff for pointing this out. I’ve become a little forgetful :( The code was (by mistake) set to get the labels from my personal blog, because I was testing it there. Get the updated code from below, and see the instruction! Sorry!


That’s “Don’t leave the page” Labels widget ;) Here’s a quick update since people asked me for it and I thought the script could use it. If you want the original without frills, check it out. This update makes a few cosmetic changes, nothing more. So most of your people won’t need to change your code. This update adds:

  • A +/- (toggling) sign before the label name, to give it a more hierarchical appearance. You can modify the code yourself to change the symbol to anything, I’ve marked it out in the code, but you’ll have to download it to edit it (get it from here).

  • A loading animated image for all your huge list of posts which take a while to load. The script pre-loads the image, so there will be no delay in showing it. But if you don’t see it, don’t worry. It just means you have a stinkin’ fast connection ;)

Add this line in (replace the previous code if you implemented the original (Sumesh pointed out a potential confusion):

<script>//<![CDATA[
var labels_blog = '<BLOGNAME>';
//]]></script>
<script type='text/javascript' src='http://aditya.vm.googlepages.com/labels.js'/>

Replace <BLOGNAME> with the name of your blog. You’ll have to edit your widget code a little. Replace the line which generates the link:

<a href='#' onclick='javascript:showLabel(this.innerHTML)'><data:label.name/></a>

With this:

<span expr:id='data:label.name + "-tog"'>+ </span><a href='#' onclick='javascript:showLabel(this.innerHTML)'><data:label.name/></a>

You can change the symbol within the span tags to whatever you want :) Cool? Good!
Have a good day!


‘Don’t-Leave-the-Page’ Labels Widget

Onset of labels sure did kill off the greatest playground of hackers. No more hacking with Del.icio.us to get a list of posts tagged or ‘labelled’ under a particular category. So what do we do now? Find ways of making Blogger Labels asynchronous ofcourse. There are quite a few hacks out there that do this nicely, but I just had to do it my way :)

The hack

This little code creates an asynchronously loaded list of the posts classified under a particular label, sorted by last update time, and shows it right below it. You can see it in action in the sidebar on the right. Click on any one of the topics. It also removes the list if it’s open, and you can open up more than one category at one time. I was experimenting with a few functions I made and DOM functions, so this should work in all modern browsers without too much hassles (I don’t care about IE).

The elements are all lists, so you need to just create a CSS class for postList, and style it as you see fit. I haven’t included code to show a ‘Loading…’ type message because this is quite fast, so many people won’t get any lag time. I’ve managed to integrate it with the Blogger Labels widget, so you just need to make a little change to the widget code. Yes, you’ll have to expand the widgets (sorry!).

The code

Wrap the following in <script> tags and put it in your <head> area:

//<![CDATA[
function $(){
  for( var i = 0, node; i < arguments.length; i++ )
    if( node = document.getElementById( arguments[i] ) )
      return node;
}

var _id = '';
function showLabel(name){
    _id = name;
    if($(name+'-expanded')) {
    $(name+'-expanded').parentNode.removeChild($(name+'-expanded'));
    $(name).style.textDecoration = 'none';
        }
    else {
    $(name).style.textDecoration = 'underline';
    var script = document.createElement('script');
    script.src = 'http://<BLOGNAME>.blogspot.com/feeds/posts/summary/-/'+name+'?alt=json-in-script&callback=makeList';
    script.type = 'text/javascript';
    
    document.getElementsByTagName('head')[0].appendChild(script);
    }
}

function makeList(json){
var d = document.getElementById('Label1');
var i=0, j=json.feed.entry[i];
var list = document.createElement('ul');
list.id = _id+'-expanded';
list.setAttribute('class','postList');
var frag = document.createDocumentFragment();

  while(i<json.feed.entry.length){
    j=json.feed.entry[i];
     var t_link = document.createElement('a');
         t_link.href = j.link[0].href;
    if(j.title.$t.length>37)
        t_link.appendChild(document.createTextNode((j.title.$t).slice(0,37)+'...'));
    else 
        t_link.appendChild(document.createTextNode(j.title.$t));

      var title = document.createElement('span');
     title.setAttribute('class','postTitle');
         title.appendChild(t_link);

    var li = document.createElement('li');
    li.appendChild(title);      
    frag.appendChild(li);
    i++;
      }
    list.appendChild(frag);
    $(_id).parentNode.insertBefore(list, $(_id).nextSibling);    
}
//]]>

All you need to do is replace the <BLOGNAME> with the name of your blog. I’ll explain the various parts of it at the end, so that you can change it to suit your needs. The next bit of code is where it gets a little ugly. Expand the template, and then go looking for your Labels widget. Once you find it, replace the entire widget with this code:

<b:widget id='Label1' locked='false' title='Topics' type='Label'>
<b:includable id='main'>
  <b:if cond='data:title'>
    <h2><data:title/></h2>
  </b:if>
  <div class='widget-content'>
    <ul class='elegantList'>
    <b:loop values='data:labels' var='label'>
      <li expr:id='data:label.name'>
        <b:if cond='data:blog.url == data:label.url'>
          <data:label.name/>
        <b:else/>
          <a href='#' onclick='javascript:showLabel(this.innerHTML)'><data:label.name/></a>
        </b:if>
        (<data:label.count/>)
      </li>
    </b:loop>
    </ul>

    <b:include name='quickedit'/>
  </div>
</b:includable>
</b:widget>

Do this only if you’re widget hasn’t been tinkered away from the default Blogger widget, which should be the case in most of the situations. That’s it, you’re done! :) Reap the benefits!

Explanation and further tinkering

This uses the dynamic script tag method to get a list of posts from the label feed. It then proceeds to form a list out of the post titles, and then using my home-made method of inserting a node, puts the list after the node specified by the ‘id’ of the parent node of the clicked link.

It also slices the post title to keep in within 40 characters, so that it doesn’t wrap to the next line and take up unnecessary lines in your sidebar. You can change this by changing the ‘37’ in the if statement, and line following it. However, this number should satisfy most cases. To style the list, as I said before, define a CSS class for ul.postList and then proceed to style the lis under this.

Once again, this will not work on a preview page, so you’ll have to save it and then test it. I hope you get it working without too many hassles!


A Date to Behold!

I have updated the code with a much cleaner one, which can be changed easily if you want to alter the order or anything else. If you have one, you don’t need to update, but first time users might as well take the new one.

Also, if someone has trouble finding the correct date format, see the picture below. It’s the second last format in the list :)


This was something that I wanted to have when I saw it on Lifehacker. Their dates look, well, different, and I thought it’d be really cool to let your dates stand out than the normal one line dates that Blogger forces us to have. It is basically a function that takes in the Blogger date as an input, does some fancy splitting and slicing, and outputs the day, the month and year in it’s own seperate line, or if you like it, as a picture. There is a catch to the niceness.

Before you jump in

If you want to use pictures, like I have, you’ll have to put in some time and photoshop work. Since there is no scripted way of generating pictures (not without much hallabaloo at least), you will have to make the picture for all days, months, and a few years. That means, you will need a picture with the numbers 1-31, month names January to December, and a few years from 2006-2008 (or from whenever you started your blog). This can be quite a job, so I’ll suggest you go with the first method.In case you want the pictures, you’ll need to modify the document.write statement to output image tags, with the source set to in a format of url/"+array-element+".png. This will generate an image for every value held in the array. That will take a bit of template modding as well, with some knowledge of CSS to make the styles. Don’t say I didn’t warn ya! :P

The code

Let’s get hacking. Begin by changing the date format output of your dates from the blog settings. Change it to show dates as ‘23 January 2007’ (with the spaces, no commas). Then put in this bit of code in your <head> area:

<script>
    function date_replace(d){
        var da = d.split(' ');
        day = "<span class='theDate'>"+da[0]+"</span>";
        mon = "<span class='theMonth'>"+da[1].slice(0,3)+"</span>";
        year = "<span class='theYear'>"+da[2]+"</span>";
        document.write(day+mon+year);
    }
</script>

Now, you’ll need to find the place where the date tag is in your template. The date tag looks like <data:post.dateHeader/>. You’ll have to replace that line, and anything else within that <b:loop> tag, except the conditional statement (<b:if>) with this:

<div id='post-date'>
    <script>date_replace('<data:post.dateHeader/>');</script>
</div>

That’s all you have to do at the template hacking level. The next to do will be to define styles for your newly generated date. Your three parts of the date are held in three <span> elements as you can see from the function up there, with the class attribute set to ‘theDate’ (for the day), ‘theMonth’ and the ‘theYear’. You can style all of them the way you like it by defining classes in your CSS named as div#post-date span.theDate and so on. You should set a display: block; to begin with so that they all come up in a seperate line. Other CSS style attributes can be applied as per required. The parent element will be styled with a div#post-date to hold the background. It can be a picture or a simple colour, it’s up to you. Here’s a sample CSS definition which you can use in case you’re lazy:

div#post-date {
    display: block;
    float:left;        /* set this to right if you want it go to the right */
    padding: 1em;       /* to keep the text away from the edges */
    background-color: #;  /* you can change this to hold a picture, will make it look nicer */
    border: 3px double gray;   /* a border to make it look nice */
}

div#post-date span.theDate {
    display: block;       /* to put this in a different line */
    font-size: 3em;       /* to make the date stand out */
    background-color: transparent; /* to let the background show through */
    color: white;
}

div#post-date span.theMonth {
    display: block;
    font-size: 1em;       /* smaller compared to the date */
    background-color: transparent;
    color: white;
}

div#post-date span.theYear {
    display: block;
    font-size: 1em;       /* smaller compared to the date */
    background-color: transparent;
    color: white;
}

All that will go within your <b:skin> tags in case your wondering. If you know what you’re doing, go around and play with the attributes to get what you’ll actually looking for.

That’s pretty much it! It’ll be a little hard to use images with this for those who don’t know Javascript, so if you want, I could modify the function for you to output the images. You’ll need to give me the URL to your images though. Do ‘not’ use Blogger Image hosting to upload your pictures. The path is never constant, and this function requires that the path always be constant, with only the names of the images changing. The names themselves should be 1.png, 2.png and so on for the days, January.png and so on for the months and 2007.png for the years. All in the same format! You’ll need to make 31+12+1 (atleast) = 44 images. I did it twice :P Once for my old blog, and then again for this new one. I’m beginning to not like this look too, so a third round might be imminent!

But now you know how to get it done! So go ahead, make your dates look great!


Blogger Smilies!

Posts can become dull and boring when no emotion comes through words. After all, blogs are meant to be a ‘personal’ medium, which goes from people to people. What better way to portray emotions than use emoticons and smilies? Blogger itself doesn’t give us a way of doing such trivial things, which is why this is another little script which I ported over from the old Blogger to the new one. It uses simple Regular Expressions to replace the text version of the emoticons to their pictured cousins!

There is nothing much for you to do here actually. You just need to include this one line in your <head> section:

<script src='http://aditya.vm.googlepages.com/addSmiley.js' type='text/javascript'></script>

And you’re done! :) The script assumes the content of your post is housed in an element called ‘post-body’. If it’s different, then just add one more line under that line:

postBodyClass = '';

The script will be called once the page finishes loading, so that it doesn’t hamper with the page load times! The emoticons are housed at my Google Pages account, which should be able to handle the load pretty well. They’re tiny cute icons after all! So enjoy your emoticonified posts!


Major Update: Seeing as how people wanted adding in more classes (or classes that I wasn’t offering by default), I have reworked the script (quite a bit) to fit in probably all kinds of situations. But, in doing so, it is a little more complicated to implement if you want to customise it ‘beyond’ my default settings.

Everything is handled within arrays now. I have pre-programmed the function to add smilies in classes of ‘post-body’, ‘entry-content’ (as asked by Stephen) and ‘comment-body’. These three should suffice ‘most’ cases in Blogger. However, if you don’t fall under any of these, you can make a manual function call at the end of the posts widget in your template. Yes, you ‘will’ have to get your hands dirty for this. So, supposed your template code for your posts look like this:

<b:section id='Blogposts'>
  <b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'/>
</b:section>

Your function call for ‘addSmiley()’ will come after this. Now, within the ‘()’, list out all the entry containers you want to add your emoticons to. So, if you want to add smilies to say ‘post-author’ and ‘post-notes’ as well, your code now becomes:

<b:section id='Blogposts'>
<b:widget id='Blog1' locked='false' title='Blog Posts' type='Blog'/>
</b:section>

<script language="javascript">
addSmiley('post-author', 'post-notes');
</script>

And this comes ‘after’ the </b:section> line above. Followed? Good! I’ll restate that this is ‘only’ if your emoticonizing content does not already fall under the classes of ‘post-body’,’comment-body’ and ‘entry-content’.

Another update: Deepak, has come up with a userscript that makes adding emoticons and other basic rich editing features easier to add in your comments made in Blogger. Go catch it at Blogger Hacked

Update: Ramani has listed out the CSS required if you see borders around your emoticons or they appear to squashed up. Also, I had forgotten to list out which emoticons are supported. The general ones are as follows:

:) or :-)  
:( or :-(  
:P or :-P  
:D or :-D  
:$ or :-$  
;) or ;-)  

Hope this helps! :)


Keep Current Date/Time on Posts

Update (05/04): Thanks to Phydeaux3 for stepping in. Some people were complaining on Consuming Experience about the script breaking the post editor buttons. These have now been fixed.

Update: Thanks to Improbulus for reminding me about this. I have now fixed the script to auto check the box when you’re editing unpublished drafts. I don’t know how stable my method is though, so if it doesn’t work for you, or breaks under any condtition, please let me know!

This script breaks Blogger’s inbuilt Spell–check. I think it has something to do with the repeating check for the time. I’ll look more into it and try and come up with a fix. In the meantime, this will be a good opportunity to try out Firefox’s wonderful spell check.


Blogger Beta doesn’t fix this still, so I had to take things into my own hands! I missed the functionality of the original by Jasper, which broke in the new post editor. Hence, I have redone it to do the same thing, but now for Beta. Except a few known bugs, it works quite well! :)

For Beta!

It works the same way. A little toggle checkbox will show up right at the bottom of the post options box. It’ll be auto–checked for you if you’re starting a new post. However, I couldn’t figure out how to check for difference between editing a “published” post and an “unpublished” post, hence couldn’t create conditions to auto–check the checkbox. It’s a minor glitch which shouldn’t be a problem for most people. Just check it, and it’ll update your date and time!

As an added feature, it also keeps your post options open for you by default, as compared to the Blogger default of having to click the ‘Post Options’ link :)

I’m not very sure if the date formats differ depending on what you set as your time zone. The favonian format is MM/DD and rest of us follow a DD/MM format. If you see a discrepancy, please let me know, and I’ll make the necessary changes! As usual, any bugs or glitches can be reported here! I’ll get back to you as soon as I can!

User script

Keep Current Date/Time on posts
All my userscripts


Native Blog Search Improved!

Edit: I’ve updated the instructions and code since some people were complaining of it not working. I’d also like to mention that for some reason, external data calls aren’t supported from the preview page, so please save your template, and try it again from your home page. If it still doesn’t work, I’ll be glad to help!

Update: I’ve made a few more changes, to make it check if it needs to paginate the results. Plus, a ironed out a few bugs.


It’s been quite a long while since this hack was updated, even though it’s been my most successful one! I’m sorry about that, but I guess it’s better to follow the ‘If it ain’t broke, don’t fix it’ method. But I can sure as hell improve it! :P So now I present to you a slightly updated version of NSS. The original and first version can be found here! :)

This update was triggered mostly by Avatar’s list of ideas for coders to tackle. If you think you have what it takes to tackle the others, check out the post here. Now, on to the hack itself. The only change at the moment is that you can now access results as an AJAX pagination type approach. Your results are preceded by the number of posts being shown, and a link to get the previous or next 10 results. I’ll be soon adding a Google AJAX type search for other blogs, or Google services (as demonstrated on Hoctro’s blog). I’m not adding that in this update because it’ll need some major changes to the implementation, for which I need to come up with a simpler explanation than the one I have at the moment. That update to the hack itself is complete though ;)

The code

You might as well start by removing all the previous code, since all the functions have been updated. This will not confuse you later on! Start by adding this piece of code in your area of the template:

<script language='javascript'>
//<![CDATA[
var blog_name="BLOG'S NAME";
var _num=0, _para, p;

function $()
{
  for( var i = 0, node; i < arguments.length; i++ )
    if( node = document.getElementById( arguments[i] ) )
      return node;
}

/* ```````````` NATIVE SEARCH ``````````````` */
/* <license resource="http://creativecommons.org/licenses/by-nc-sa/2.5/"> */
/* Coded by Aditya Mukherjee (www.aditya-mukherjee.com) */

function d_script(para, num, paged){
_para = para;
_num = num;

var url = (p=='paged') ? "http://xoxotools.ning.com/outlineconvert.php?output=json&classes=item&url=http%3A%2F%2Fblogsearch.blogger.com%2Fblogsearch_feeds%3Fq%3D"+_para+"%2Bblogurl%3A"+blog_name+".blogspot.com%26hl%3Den%26ui%3Dblg%26ie%3Dutf-8%26num%3D10%26output%3Drss%26start%3D"+_num+"&submit=Convert&callback=json" : "http://xoxotools.ning.com/outlineconvert.php?output=json&classes=item&url=http%3A%2F%2Fblogsearch.blogger.com%2Fblogsearch_feeds%3Fq%3D"+_para+"%2Bblogurl%3A"+blog_name+".blogspot.com%26hl%3Den%26ui%3Dblg%26ie%3Dutf-8%26num%3D100%26output%3Drss&submit=Convert&callback=json";

var script = document.createElement('script');
 script.type = 'text/javascript';   
 script.src = url;   
 script.id = "app-script";
 document.getElementsByTagName("head")[0].appendChild(script);
}

function json(rss){

 function paginate(){
    if(_num>=10) {
   $('stext').innerHTML="<div class='search-paginate-links'>Displaying "+(_num+1)+" to "+(_num+10)+". <a id='prev' href='javascript:d_script(\""+_para+"\","+(_num-10)+")'>Previous 10</a> | <a id='next' href='javascript:d_script(\""+_para+"\","+(_num+10)+")'>Next 10</a></div><br />";
   }
  else {
   $('stext').innerHTML="<div class='search-paginate-links'>Displaying "+(_num+1)+" to "+(_num+10)+". <a id='next' href='javascript:d_script(\""+_para+"\","+(_num+10)+")'>Next 10</a></div><br />";
   }
}
 
 function display_search(){  
  $('stext').innerHTML='';
  $('stext').style.display="block";
  $('stextcont').style.display="block";
 }
  
 var i=0;
 var results = [];
 if (!rss.item) {
  alert('No Entries\!');
  }
 else if(typeof(rss.item[1])=='undefined') { 
  results.push(rss.item); display_search(); 
  }
 else {
  results=rss.item; display_search();
  alert(results.length);
   if(results.length>=10){
    paginate();
                p = 'page';
   }
  }
 
 for(i=0;i<10;i++){
  app=document.createElement('a');
   app.href=results[i].link;
   app.innerHTML=results[i].title;
   app.title=results[i].title; 
  dv=document.createElement('div');
   dv.innerHTML=results[i].description;
  sp=document.createElement('br');
  
if(app.innerHTML!='undefined' && dv.innerHTML!='undefined'){
  $('stext').appendChild(app);
  $('stext').appendChild(dv);
  $('stext').appendChild(sp);
  }
else
  $('stext').appendChild(document.createTextNode('No results!'));
  }
}
//]]>
</script>

Just put in the name of your blog in the variable named ‘blog_name’ right at the top! For example, this blog would have it as ‘var blog_name=”lastword”;’. Update: The links positioning can now be styled by styling the class ‘search-paginate-links’ :) Make ‘em look good! Now, the form itself:

<form action='javascript:var q=document.getElementById("query").value;q=q.replace(/\s/ig,"%252520");d_script(q, 0);'>
     <input id='query' name='as_q' onfocus='clearDefault(this)' type='text' value='Your Query'/> <input class='preview' id='searchbtn' type='submit' value=' Search '/>
<div style='text-align:center'>Powered by <a href='http://lastword.blogspot.com'>Aditya</a></div>
</form>

To display the search, put this bit wherever you want the results to show up:

<div id='stextcont' style='position:relative;display:none'><a href='javascript:$("stext").style.display="none";$("stextcont").style.display="none";void(0);'><img id='close' src='http://images.google.com/images?q=tbn:ReDgICpawihOsM:http://lubeselector.bpmadeniyaglar.com/Images/bpClose_icon.gif' style='position:absolute;top:0px;right:0px'/></a>
<div id='stext'/>

That’s it, you’re done! :) Simple? Good! Go ahead and give it a whirl. Any comments and/or doubts should be asked and will be answered in the comments. Don’t mail me your doubts b’cuz I want everyone to benefit from them, not just you! :)


Blogger Post Notes!

There are people who are constantly running the need to post and post and post! My example comes from Avatar, who, everytime I speak to him, tells me how he has tons of drafts saved in Blogger, and more pointers and reminders in GMail and Word. His misery, and now my experience with the posting fever prompted this little idea into my head that Blogger has lacked since day one. So I dedicate this one to the hard working Avatar! :)

We cannot remember all the time what were thinking when we started writing a post. And if you leave posts half way through, to come back and finish them later on, you’d have faced the situation that you’ve forgotten half the points you had in mind that you wanted to make and/or elaborate upon. If you’ve added them in the content as points, it can get a little annoying to constantly scroll up and down to remove points as you elaborate upon it. Wouldn’t it be cool to have a PostIt for your editor?

The solution

So now I give you the Blogger Post Sticky/Annotations/Notes (grab it here) or whatever else you want to call it! It’s basically a small PostIt Notes type box which floats to the top right of your post editor, holding the points that you add to it. You can actually write out your whole post there, and it’ll save it. Yes, it saves it automatically, and associates the points to the post’s title. Which means that if you come back to edit the post after you’ve published it, your sticky will return with it, with all the points intact! :) Now ain’t that wonderful?

I’ve not really bug tested this to glory, so if you run into any problems while working with it, please leave a comment with the exact problem (explained as well as you can) with a way to reproduce the problem if possible. I also don’t know if this will work with the old Blogger, since I use an appendChild function to add it to the parent element of the posting form, which might have a different name in Beta. Also, take care to not change the title once you’ve finished adding the points. If you do, your points won’t show up next time. To get them back, revert back to the old title, and then reload the post editor. Then put in the new title, and change your points. It’ll save it again associated to the new title.

In any other case, you know what to do if you hit a spanner in the works! :) I will try and fix it as soon as my exams permit me to (yes, they are going on again! A pain I tell you!) Enjoy! :)

Copyright © 2006-08 Aditya Mukherjee | Valid XHTML 1.0 Transitional Valid CSS!