Skip to content

Instantly share code, notes, and snippets.

@harishvc
Last active January 3, 2016 14:51
Show Gist options
  • Save harishvc/ed7d1affdb1d43277632 to your computer and use it in GitHub Desktop.
Save harishvc/ed7d1affdb1d43277632 to your computer and use it in GitHub Desktop.
mapit - content.js
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
//tab loaded
if (msg.action == 'start') {
if (DEBUG === true) { console.log("tab loaded");}
Start();
}
});
function Start(){
var today = document.getElementsByClassName('lv-location');
for (i=0;i<today.length;i++) {
var mapDiv = document.createElement("span");
mapDiv.setAttribute('class', "calendar-clicksaver-maplink");
var a = document.createElement('a');
var b = today[i].innerText;
b = b.replace(/^\s-\s/,'');
var eb = encodeURIComponent(b).replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/%20/g, ' ');;
var c = 'https://maps.google.com/maps?q=' + eb + "&source=calendar";
a.href = c;
a.innerHTML = b;
mapDiv.appendChild(a);
//Replace all existing content
today[i].innerText = " - ";
today[i].appendChild(mapDiv);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment