// ==UserScript==
// @name          WordPress.com: Tags Button
// @namespace     http://zoolcar9.wordpress.com/
// @include       http://*.wordpress.com/wp-admin/page-new.php
// @include       http://*.blogsome.com/wp-admin/page-new.php
// @include       http://*.wordpress.com/wp-admin/post.php*
// @include       http://*.blogsome.com/wp-admin/post.php*
// @description	  Adds Tags button to add Technorati Tags and site search tags
// ==/UserScript==

// Based on Oddiophiles Technorati Tags Bookmarklet at
// http://andrewbeacock.blogspot.com/2005/10/oddiophiles-technorati-tags.html
// and Lorelle Van Fossen's Site Search Tags Bookmarklet at
// http://lorelle.wordpress.com/2005/10/14/a-tagging-bookmarklet-for-wordpress-and-wordpresscom-users/

(function() {
  var tagButt = document.createElement('input');
  tagButt.type = 'button';
  tagButt.id = 'ed_tags';
  tagButt.className = 'ed_button';
  tagButt.value = 'Tags';
  tagButt.title = 'Insert Tags';
  tagButt.addEventListener('click', function(e) {
    var a = '';
    var t = prompt('Enter Tags without commas:','');
    if(!t) return;
    var tr = t.split(' ');
    a += '\n\n<hr /><p><b>Technorati Tags:</b> ';
    for(var i = 0; i < tr.length; i++) {
      if(i > 0) a += ', ';
      a += '<a href=' + unescape('%22') + 'http://www.technorati.com/tags/' + tr[i] + unescape('%22') + ' rel='+unescape('%22') + 'tag' + unescape('%22') + '>' + tr[i] + '</a>';
    }
    a += '\n<b>Site Search Tags:</b> ';
    for(var j = 0; j < tr.length; j++) {
      if(j > 0) a += ', ';
      a += '<a href=' + unescape('%22') + '/?s=' + tr[j] + unescape('%22') + ' rel='+unescape('%22') + 'tag' + unescape('%22') + '>' + tr[j] + '</a>';
    }
    a += '</p>';
    document.getElementById('content').value += a;
  }, false);
  var toolbar = document.getElementById('ed_toolbar');
  toolbar.appendChild(tagButt);
})();

