Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check is Streak installed
var INSTALL_CHECK = 'chrome-extension://pnnfemgpilpdaojpnkjdgfgbnnjojfik/blank.png';
function isExtensionInstalled() {
//we have different logic for Chrome vs Safari
if(BrowserDetect.browser === 'Chrome'){
// the Chrome extension makes an image "web accessible", so we have the page try to load that image.
// if it loads successfully then the Streak extension is installed. If the image does not load successfully, then the image is not installed
var img = new Image();
img.onload = function() {
clearInterval(installTimerId);
streakIsInstalled();
};
img.onerror = function(){
};
try {
img.src = INSTALL_CHECK;
}
catch (error) {
}
}
else{
// for Safari, we have our Safari extension add an element to the page with id "streakExists" when going to a
// streak page. So we have our script look for that element. If we can find it then we're good
if( document.getElementById('streakExists')){
clearInterval(installTimerId);
streakIsInstalled();
}
}
}
// we poll because sometimes it takes time for the marker element to get added
function intervalCheckInstalled(max){
var current = 0;
var delay = 500;
installTimerId = setInterval(function(){
current += delay;
if(current > max){
clearInterval(installTimerId);
streakIsNotInstalled();
}
isExtensionInstalled();
}, delay);
isExtensionInstalled();
}
// our current homepage checks for 2 seconds
intervalCheckInstalled(2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.