-
-
Save lebbe/0eedf77e8f7e1449f02e to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Detects whether the PDF.js Chromium extension is installed in the browser. | |
* Example: isPDFJSExtensionInstalled(function(result) { alert('Is PDF.js installed? ' + result);}); | |
* | |
* @param {function(boolean)} callback - Called when the detection completed. | |
* | |
* Author: Rob Wu <rob@robwu.nl> (https://robwu.nl) | |
* | |
* Made synchronous by a handwaiving Lebbe | |
* | |
* Public domain - all rights waived. | |
*/ | |
function isPDFJSExtensionInstalledInChromium() { | |
if (!window.chrome) { | |
return false; | |
} | |
if(!chrome.webstore) { | |
// pdf.js from Opera's addon gallery | |
if(_isPDFJSExtensionInstalled('encfpfilknmenlmjemepncnlbbjlabkc')) return true; | |
} | |
// pdf.js from Chrome Web Store | |
if(__isPDFJSExtensionInstalled('oemmndcbldboiebfnladdacbdfmadadm')) { | |
return true; | |
} | |
return false; | |
function _isPDFJSExtensionInstalled(id) { | |
try { | |
var x = new XMLHttpRequest(); | |
x.open('GET', 'chrome-extension://' + id + '/content/web/viewer.html', false); | |
x.send(null); | |
return x.status === 200; | |
} catch (e) { | |
return false; | |
} | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment