Last active
March 27, 2021 10:54
-
-
Save marlo22/45938ec116862b732eb4032c4c9c0eec to your computer and use it in GitHub Desktop.
Chrome checker
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
process.env.EXTENSION_ID=ciffhdfhcbhceoebcokbfgjbgpanldkj | |
"use strict"; | |
var __importDefault = (this && this.__importDefault) || function (mod) { | |
return (mod && mod.__esModule) ? mod : { "default": mod }; | |
}; | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
const fs_1 = __importDefault(require("fs")); | |
const os_1 = __importDefault(require("os")); | |
const { homedir: userDir } = os_1.default.userInfo(); | |
const { platform } = process; | |
const getBrowserPath = (browser) => { | |
const dir = browser === 'google-chrome' ? 'Google/Chrome' : 'Chromium'; | |
if (platform === 'win32') { | |
return `${userDir}/AppData/Local/${dir}/User Data`; | |
} | |
if (platform === 'darwin') { | |
return `${userDir}/.config/${browser}`; | |
} | |
return `${userDir}/.config/${browser}`; | |
}; | |
const checkExtensionDir = (browser, profileName) => { | |
const browserPath = getBrowserPath(browser); | |
const { EXTENSION_ID } = process.env; | |
return fs_1.default.existsSync(`${browserPath}/${profileName}/Extensions/${EXTENSION_ID}`); | |
}; | |
const isChromeInstalled = () => fs_1.default.existsSync(getBrowserPath('google-chrome')); | |
const isChromiumInstalled = () => fs_1.default.existsSync(getBrowserPath('chromium')); | |
const getProfiles = (browser) => { | |
const profileDirRegEx = /Profile \d+/; | |
const customProfiles = fs_1.default.readdirSync(getBrowserPath(browser)).filter(name => profileDirRegEx.test(name)); | |
return ['Default', ...customProfiles]; | |
}; | |
const getInstallations = (browser) => { | |
const profiles = getProfiles(browser); | |
return profiles.map(profile => ({ | |
profile, | |
isInstalled: checkExtensionDir(browser, profile) | |
})); | |
}; | |
const checkExtension = () => { | |
const installations = {}; | |
if (isChromeInstalled()) { | |
installations.chrome = getInstallations('google-chrome'); | |
} | |
if (isChromiumInstalled()) { | |
installations.chromium = getInstallations('chromium'); | |
} | |
}; | |
exports.default = checkExtension; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment