Google Map UK Postcodes Bookmarklet

Today I found a really neat use for my Get Elements By Content function which I wrote recently.  I wanted to create a bookmarklet that allowed me to visit a page, click on the link and turn any UK postcodes in the page to a link to a Google Map.  Well, it’s pretty simple -

var pc=gbc('[a-z]{1,2}\\d{1,2}[a-z]? \\d[a-z]{2}');
for(var i=0;i<pc.length;i++){
 pc[i].innerHTML=pc[i].innerHTML.replace(/([a-z]{1,2}\d{1,2}[a-z]? \d[a-z]{2})/ig,'<a href="http://maps.google.co.uk/maps?f=q&hl=en&q=$1,UK&ie=UTF8&z=16&om=1&iwloc=addr">$1</a>');
}

Obviously you need to ‘gbc’ function from my last post, but other than that, you just need to turn it into a bookmarklet and away you go. If you have any problems, let me know.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live

Javascript: GetElementsByContent

I had the inclination last week to knock up a quick Javascript function to effectively give you GetElementsByContent. So, you can call a function which returns an array of nodes which match a string (or RegExp) which you pass in, which can optionally be filtered by tag name.

Now, I make no claims that this is “a first”, as it probably isn’t, I wanted to write it, so I did.  If I’d have googled it, I’d have probably found something really quickly that did exactly what I wanted and would probably be far superior to what I have written.  I wanted to write it for fun really, but I think it’s actually quite useful, so here it is -

var gbc=function(contents,tag){
  var n=[];var s=tag||'*';
  var b=document.getElementsByTagName(s);
  var r=new RegExp(contents,'ig');
  for(var i=0;i<b.length;i++){
    for(var t=0;t<b[i].childNodes.length;t++){
      if(b[i].childNodes[t].nodeType==3&&r.test(b[i].childNodes[t].textContent)){
        n.push(b[i]);
        break;
      }
    }
  }
  return n;
}

Because I’m lazy I’ve called it ‘gbc’ (Get By Content), but obviously you can name it whatever you like.

You use it like -

var f = gbc('forums');

This would return all nodes in the current document which contain the text ‘forums’.

You could do -

var f = gbc('forums','a');

This would return all nodes matching the text ‘forums’ (within the text content, not attributes), but limit the search to just ‘a’ tags.

Because the first parameter (the text to search) is actually treated as a regex, you can actually pass it a string to treat as a regex. So -

var f = gbc('abc\\d+');

This would return all nodes which contain the text ‘abc’ followed by one or more numbers. Note the double slash, this is due to the way Javascript interprets the RegExp when using the ‘new’ style syntax, you need to escape any slashes.

That’s about it really, let me know if you use it or have any feedback.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live

Switched Theme

Unfortunately, I’ve had to move away from my old theme, which is quite sad as Dennis featured so prominently on the old one. I’ll probably have to go for the CSS upgrade and get him back in here that way.

I needed to switch in order to get away from fixed width, which was ruining any code I pasted. As I intend to start posting more code, the old them had to go.

Right, now I need to right some new posts..

Google sync on windows mobile 5 (wm5)

Google has (finally) launched a product (service) allowing you to sync your contacts and calendar from windows mobile device with gmail equivalents.

Google Sync for Windows Mobile

If however, like me, you’re running an old window mobile 5 device, you may find yourself stumped while following the instructions.  Specifically, it says -

8. Leave the Domain field empty.

Hmm, not so easy.. it’s a compulsary field!

The answer is to use m.google.com/sync for the domain :)

This google forum post pointed me to the answer.

Oh, one more thing, you may want to take a backup of your phone contacts/calendar first.  That’s easy grab PIM backup from DotFred, it works great.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live

Hosted wordpress social bookmarks bookmarklet

As I use Google Chrome as my default browser nowadays, I don’t currently have access to greasemonkey (userscripts are coming in 2.0 though :) ) and therefore I can’t use my hosted wordpress social bookmarks greasemonkey script. For this reason (and for others who don’t use firefox*), I’ve knocked up a bookmarklet version of the script.

Given that it’s really diffcult to format code correctly in here, I’ll just point you to it as a file.  Just grab the file and and copy the contents as the location of a bookmark (preferably one on you bookmarks bar so you have easy access to it).  Then, whenever you’re on the add or edit post pages in your wordpress admin, you can click the link to add in the nifty “Social Bookmarks” section as if you were using the greasemonkey version.

Neat.

*Apart from those using IE as it seems to truncate all bookmarks longer than a predetermined max… what a PITA.

add to del.icio.us :: Bookmark Post in Technorati :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine :: :: :: TailRank :: post to facebook :: Bookmark on Google :: Add to Netscape :: Share on Yahoo :: Add this to Live