Last active
August 29, 2015 14:02
-
-
Save saruba/ee62ac02006c9ff16932 to your computer and use it in GitHub Desktop.
Detect that a specific Chrome extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function detectChromeExtension(extensionId, accesibleResource, callback) { | |
if (typeof(chrome) !== 'undefined') { | |
var xmlHttp = new XMLHttpRequest(), | |
testUrl = 'chrome-extension://' + extensionId + '/' + accesibleResource; | |
xmlHttp.open('HEAD', testUrl, true); | |
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
xmlHttp.timeout = 1000; | |
xmlHttp.onreadystatechange = function () { | |
if (xmlHttp.readyState == 4 && typeof(callback) == 'function') { | |
if (xmlHttp.status == 200) { | |
callback.call(this, true); | |
} else { | |
callback.call(this, false); | |
} | |
} | |
}; | |
xmlHttp.ontimeout = function () { | |
if (typeof(callback) == 'function') | |
callback.call(this, false); | |
}; | |
xmlHttp.send(); | |
} else { | |
if (typeof(callback) == 'function') | |
callback.call(this, false); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detectChromeExtension('pimkadpiclhfobplcdjbnjgjmjfdklig', 'img/icon128.png', | |
function myCallbackFunction(extensionExists) { | |
if (!extensionExists) { | |
element.removeClass('hidden'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
font: http://www.willhawker.com/what-i-learnt-today/20-11-2012/27