GeoTag Flickr via streetmap.co.uk

By steeev Last update May 20, 2008 — Installed 1,485 times.
/*
// ==UserScript==
// @author	      Stephen Fernandez http://steeev.freehostia.com  http://flickr.com/steeev
// @name          GeoTag Flickr via streetmap.co.uk
// @description	  Lets you geotag your flickr photos via streetmap.co.uk
// @namespace     http://steeev.f2o.org/flickr/
// @include       http://www.flickr.com/photos/*
// @include       http://flickr.com/photos/*
// @include       http://www.streetmap.co.uk/*
// @include       http://streetmap.co.uk/*

// @version 0.8

///////////////////////////////////

 This is a Greasemonkey user script.
 In order to use it, you need to be using the Firefox web browser, with the Greasemonkey extension installed

///////////////////////////////////


History
=======
03-July-2006 v0.6 merged the 2 smuk gm scripts into a single script, and also fixed the geotagger code so it no longer needs to rely on my server
16-Sept-2006 v0.7 updated script to use Flickr's GeoAPI calls
20-May-2008  v0.8 fixed script, so it works again with latest version of GM + FF
*/


// ==/UserScript==

if (location.href.match(/streetmap\.co\.uk/)) {
(function() {

unsafeWindow.checkcookieexist=function()
{
  acookie=unsafeWindow.readCookie('sfpid');
  //alert(acookie);
  //alert(typeof(acookie));
  if ((typeof(acookie) !='undefined') && (acookie != '') && (acookie != null))
    ;//document.addcomment.geobloggers.value=acookie;
  else
    ;//document.addcomment.geobloggers.value=geobloggerslink;
}

unsafeWindow.createCookie = function(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/; domain=streetmap.co.uk";
}

unsafeWindow.readCookie = function(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

unsafeWindow.geotagging = function() {

  insertstuff  ='se.gif\" border=\"0\" height=\"22\" width=\"24\"></a></td></tr><tr><td bgcolor=\"#EEEEEE\" colspan=3><div align=center style=border:solid:1px><a title="Add GeoTags to your Flickr Image" href="javascript:latlon(\'' + location.href + '\',' + '\'addgeotags\'' + ');">Add GeoTags</a>';
  insertstuff +=' | <a title="Check Flickr.com for geotagged images in the local area" href="javascript:latlon(\'' + location.href + '\',' + '\'checkgeotags\'' + ');">Check Area for GeoTagged Flickr Images</a>'; //this.href=\'latlon(\'' + location.href + '\',' + '\'checkgeotags\'' +');
  insertstuff +=' | <A title="Display Longitude and Latitude" href="javascript:latlon(\'' + location.href + '\',' + '\'showlatlon\'' + ');"">Show Lat + Lon</a>';
  insertstuff +='<br/><span id="splatlon" align=center></span><br/></div></td></tr>';
  document.evaluate('/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/P[1]/FONT[1]/TABLE[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.innerHTML=document.evaluate('/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/P[1]/FONT[1]/TABLE[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.innerHTML.replace('se.gif\" border=\"0\" height=\"22\" width=\"24\"></a></td></tr>',insertstuff);
  //document.body.innerHTML=insertstuff+document.body.innerHTML;

}


if (!location.href.match(/popup/))
 {
 window.addEventListener("load", function() { unsafeWindow.geotagging() }, false);

 if (location.href.split('?') && location.href.split('?')[1].match(/sfpid/))
  {
  sfpidbeg=location.href.indexOf('sfpid=')+6;
  sfpidend=location.href.indexOf('&',sfpidbeg);
  sfpid=location.href.substr(sfpidbeg,sfpidend-sfpidbeg);
  unsafeWindow.createCookie('sfpid',sfpid,1);
  //alert(sfpid);

  sfpnmbeg=location.href.indexOf('sfpnm=')+6;
  sfpnmend=location.href.length;
  sfpnm=location.href.substr(sfpnmbeg,sfpnmend-sfpnmbeg);
  unsafeWindow.createCookie('sfpnm',sfpnm,1);
  //alert(sfpnm);
  parent.top.location.href='http://streetmap.co.uk/newsearch.srf?mapp=newmap&searchp=newsearch&Submit1=search&type=PostCode&name=' + sfpnm;
  }
}

unsafeWindow.smukaddgeotags=function(lat,lon) {

  tags='geotagged%20geo:lat=' + lat.replace(' ','') + '%20geo:lon=' + lon.replace(' ','');
  auth_hash=unsafeWindow.readCookie('sfpid').split('%7C')[1];
  photo_id=unsafeWindow.readCookie('sfpid').split('%7C')[0];
  oldlocation=unsafeWindow.readCookie('sfpid').split('%7C')[2];
  //alert(auth_hash + ' X ' + photo_id);
 
  // old way to add geotags (adds actual tags)
  //url="http://www.flickr.com/services/rest/?method=flickr.photos.addTags&api_key=9d179414c5491bb965d03dab476a0ef8&photo_id=" + photo_id + "&tags=" + tags + "&auth_hash=" + auth_hash;

  // new way to add geotags
  lat=lat.replace(' ','','g').replace('%20','','g');
  lon=lon.replace(' ','','g').replace('%20','','g');
  url="http://www.flickr.com/services/rest/?method=flickr.photos.geo.setLocation&api_key=9d179414c5491bb965d03dab476a0ef8&photo_id=" + photo_id + "&lat=" + lat + "&lon=" + lon + "&auth_hash=" + auth_hash;


window.setTimeout(function() { 
  GM_xmlhttpRequest({
    method: 'GET',
    url: url,
    headers: {
             'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
             'Accept': 'application/atom+xml,application/xml,text/xml'
             },
    onload: function(response) 
           {
           //GM_log('Request returned ' + response.status + ' ' + response.statusText + '\n\n' + 'Feed data:\n' + response.responseText);
           //alert('Request returned ' + response.status + ' ' + response.statusText + '\n\n' + 'Feed data:\n' + response.responseText);
           //alert('GeoTags added.\n\nNow returning to Flickr...');
           location.href=unescape(oldlocation);
           }
  })
}, 0);
 
  
  
}

unsafeWindow.latlon = function(href, command) {
  xbeg=href.indexOf('x=')+2;
  xend=href.indexOf('&',xbeg);
  x=href.substr(xbeg,xend-xbeg);
  ybeg=href.indexOf('y=')+2;
  yend=href.indexOf('&',ybeg);
  y=href.substr(ybeg,yend-ybeg);
  //alert('x='+x + ' y=' + y);

window.setTimeout(function() { 
  GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://www.streetmap.co.uk/streetmap.dll?GridConvert?name=' + x + ',' + y + '&type=OSGrid',
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'application/atom+xml,application/xml,text/xml',
    },
    onload: function(responseDetails) {
	lat=responseDetails.responseText.split('<strong>Lat</strong> (WGS84)')[1].split('(')[1].split(')')[0];
	lon=responseDetails.responseText.split('<strong>Long</strong> (WGS84)')[1].split('(')[1].split(')')[0];
        //alert('Request for Atom feed returned ' + responseDetails.status + ' ' + responseDetails.statusText + '\n\n' + 'Feed data:\n' + lat + ' ' + lon);

	if (command=='addgeotags')
		unsafeWindow.smukaddgeotags(lat,lon);
	if (command=='checkgeotags')
		location.href='http://www.flickr.com/map/?&fLat=' + lat.replace(' ','') + '&fLon=' + lon.replace(' ','') + '&zl=1&map_type=hyb' ;//'http://maps.yuan.cc/?lat=' + lat.replace(' ','') + '&lon=' + lon.replace(' ','');
	if (command=='showlatlon')
		document.getElementById('splatlon').innerHTML='<b>geotagged geo:lat=' + lat.replace(' ','') + 'geo:lon=' + lon.replace(' ','') + '</b>';
    }
  });
}, 0);

} // end function latlon


})(); 

}// end if we are on streetmap.co.uk
else {

(function() {

unsafeWindow.getElementsByClassName = function (classname,tagname) {
 //N.B tagname is optional
 return unsafeWindow.Y.U.Dom.getElementsByClassName(classname,tagname);
}

unsafeWindow.blurbflag=0;

unsafeWindow.steeevsgeotagger = function()
  {
  document.forms.namedItem("sfgeotagger").elements.namedItem("sfpid").value = unsafeWindow.ps_photo_id + '|' + unsafeWindow.global_auth_hash + '|' + location.href.split('?')[0];
  //alert(document.forms.namedItem("sfgeotagger").elements.namedItem("sfpid").value);
  return true;
  }

unsafeWindow.displaylocationfield = function()
  {
  document.forms.namedItem("sfgeotagger").elements.namedItem("sfpnm").focus();
  //document.sfgeotagger.sfpnm.focus();
  if (unsafeWindow.blurbflag==0)
    {
    document.getElementById('sfphotolocation').style.display = "inline"; 
    document.getElementById('sfsubmit').style.display ="inline";
    document.getElementById('tagadderlink').innerHTML+="<p><font color='blue'>Enter the UK postcode, road name, or place name where the photo was taken, then click submit.</font></p>";
    unsafeWindow.blurbflag=1;
    }
  return false;
  }

//alert(location.href);
unsafeWindow.sfhaharr= location.href.split('/');
unsafeWindow.ps_photo_id=unsafeWindow.sfhaharr[5];

unsafeWindow.bagtagger=document.getElementById('tagadderlink');
if ((unsafeWindow.bagtagger!= null) && unsafeWindow.bagtagger.innerHTML) 
	{
	unsafeWindow.bagtagger.innerHTML+=" | <a title='Add GeoTags' style=\"text-decoration: none;\" href='' onclick='displaylocationfield();return false;' >Add UK GeoTags</a><p><form onsubmit='steeevsgeotagger()' name='sfgeotagger' method='get' target='iffyframe' action='http://streetmap.co.uk'><input name='sfpid' type='hidden' value=''/><input name='sfpnm' id='sfphotolocation' type=text style='display:none'>&nbsp;<input id='sfsubmit' type='submit' value='SUBMIT' class='Butt' style='display:none'></form></p>";
        unsafeWindow.getElementsByClassName('About','p')[0].innerHTML+="<iframe id='iffyframe' name='iffyframe' height=0 width=0></iframe>";
	}

})();

} // end if we are on flickr.com