UNPKG

@moonlightos/moonlight-hard

Version:

A way for open source developers to get paid

32 lines (29 loc) 1.14 kB
const util = require('./src/util') function showAd(repository, sandbox, debug) { if (repository === '' || repository === undefined) repository = 'no_repository_set' if (!util.shouldShowAd()) { // Reward fractional impression util.fractionalImpression(repository, 'npm') if (debug) console.log('[DEBUG] Fractional impression, not showing ad.') return } console.log('\x1b[42m%s\x1b[0m', 'Please watch the ad to support ' + repository.split('/')[1] + '! Thank you!') // 1. Generate an identifier for the current install const identifier = util.generateIdentifier() // 2. Open browser const url = util.config.AD_PATH + repository + '/' + identifier util.openBrowser(url, sandbox, function (success, error) { if (!success) { console.log('\x1b[41m%s\x1b[0m', 'Please watch the ad to support the developers of ' + repository.split('/')[1] + '! It only takes 3 seconds! Thank you!') if (error && debug) { console.log('[DEBUG] An error occurred. Stacktrace:') console.log(error) } } else { util.setAdShown(identifier) } }) } module.exports = { showAd }