In [3]:
from urllib.parse import unquote

GMap -> rdotmap


In [2]:
bookmarklet = \
"""
javascript:(function()%20%7Bvar%20d%3Ddocument,w%3Dwindow,l%3Dd.location.href%3Blats%3Dl.indexOf(%27!2d%27)%2B3%3Blate%3Dl.indexOf(%27!3d%27,lats)%3Blat%3Dl.substring(lats,late)%3Blngs%3Dl.indexOf(%27!3d%27)%2B3%3Blnge%3Dl.indexOf(%27!%27,lngs)%3Blnge%3D%3D-1%3Flnge%3Dl.length:lnge%3Dlnge%3Blng%3Dl.substring(lngs,lnge)%3Bw.open(%27http://demographics.coopercenter.org/DotMap/index.html%23lat%3D%27%20%2Blng%20%2B%20%27%26lon%3D%27%20%2B%20lat%20%2B%20%27%26z%3D12%27)%3B%7D)()
"""

In [5]:
print (unquote(bookmarklet))


javascript:(function() {var d=document,w=window,l=d.location.href;lats=l.indexOf('!2d')+3;late=l.indexOf('!3d',lats);lat=l.substring(lats,late);lngs=l.indexOf('!3d')+3;lnge=l.indexOf('!',lngs);lnge==-1?lnge=l.length:lnge=lnge;lng=l.substring(lngs,lnge);w.open('http://demographics.coopercenter.org/DotMap/index.html#lat=' +lng + '&lon=' + lat + '&z=12');})()


In [42]:
script = """
javascript:(
function() {
    var d = document,
        w = window,
        l = d.location.href;
        
    parts = l.split("/");

    for (i=0; i < parts.length; i++ ) {
        p = parts[i];
        if (p.startsWith("@")) {
            c = p.substring(1).split(",");
            c[2] = c[2].substring(0,c[2].length-1);
            w.open("http://demographics.coopercenter.org/DotMap/index.html#lat=" +
                        c[0] + "&lon=" + c[1] + "&z=" + c[2]);
          }
    }
        
})()
"""

In [43]:
print (" ".join(script.split()))


javascript:( function() { var d = document, w = window, l = d.location.href; parts = l.split("/"); for (i=0; i < parts.length; i++ ) { p = parts[i]; if (p.startsWith("@")) { c = p.substring(1).split(","); c[2] = c[2].substring(0,c[2].length-1); w.open("http://demographics.coopercenter.org/DotMap/index.html#lat=" + c[0] + "&lon=" + c[1] + "&z=" + c[2]); } } })()

rdotmap -> GMap


In [24]:
bookmarklet = \
"""
javascript:(function() %7Bwindow.open("http://maps.google.com%3Fq%3D" %2Bmap.getCenter().lat() %2B "," %2B map.getCenter().lng())%3B%7D)()
"""

In [25]:
print (unquote(bookmarklet))


javascript:(function() {window.open("http://maps.google.com?q=" +map.getCenter().lat() + "," + map.getCenter().lng());})()


In [26]:
# https://www.google.com/maps/@37.868604,-122.2585271,17z

In [29]:
script = """
javascript:(
function() {
    window.open("https://www.google.com/maps/@" +
                map.getCenter().lat() + "," + 
                map.getCenter().lng() + "," +
                map.getZoom() + "z");
})()
"""

In [30]:
print (" ".join(script.split()))


javascript:( function() { window.open("https://www.google.com/maps/@" + map.getCenter().lat() + "," + map.getCenter().lng() + "," + map.getZoom() + "z"); })()

generate rdotmap link


In [36]:
# http://demographics.coopercenter.org/DotMap/index.html#lat=33.6670191&lon=-117.7646826&z=10
script = """
javascript:(
function() {
    var l = "http://demographics.coopercenter.org/DotMap/index.html" + 
                "#lat=" + map.getCenter().lat() + 
                "&lon=" + map.getCenter().lng() + 
                "&z=" + map.getZoom();
    document.location = l;
})()
"""

In [37]:
print (" ".join(script.split()))


javascript:( function() { var l = "http://demographics.coopercenter.org/DotMap/index.html" + "#lat=" + map.getCenter().lat() + "&lon=" + map.getCenter().lng() + "&z=" + map.getZoom(); document.location = l; })()

In [ ]: