Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/apps/block_scout_web/assets/js/lib/ad.js

98 lines
2.9 KiB

3 years ago
import $ from 'jquery'
import customAds from './custom_ad'
3 years ago
function countImpressions (impressionUrl) {
3 years ago
if (impressionUrl) {
$.get(impressionUrl)
}
3 years ago
}
function showAd () {
const domainName = window.location.hostname
if (domainName.endsWith('blockscout.com')) {
3 years ago
$('.js-ad-dependant-mb-2').addClass('mb-2')
$('.js-ad-dependant-mb-3').addClass('mb-3')
return true
} else {
$('.js-ad-dependant-mb-2').removeClass('mb-2')
$('.js-ad-dependant-mb-3').removeClass('mb-3')
return false
}
}
function adjustPaddingForTextAd (showAd, data) {
if (showAd && data) {
$('.js-ad-dependant-pt').addClass('pt-4')
$('.js-ad-dependant-pt').removeClass('pt-5')
} else {
3 years ago
$('.js-ad-dependant-pt').addClass('pt-5')
$('.js-ad-dependant-pt').removeClass('pt-4')
}
}
function getTextAdData () {
3 years ago
return new Promise((resolve) => {
const displayAd = showAd()
if (displayAd) {
3 years ago
$.get('https://request-global.czilladx.com/serve/native.php?z=19260bf627546ab7242', function (data) {
3 years ago
if (!data) {
if (customAds && customAds.length > 0) {
3 years ago
try {
const ind = getRandomInt(0, customAds.length)
const inHouse = true
adjustPaddingForTextAd(displayAd, true)
resolve({ data: customAds[ind], inHouse: inHouse })
3 years ago
} catch (_e) {
adjustPaddingForTextAd(displayAd, false)
resolve({ data: null, inHouse: null })
3 years ago
}
} else {
adjustPaddingForTextAd(displayAd, false)
resolve({ data: null, inHouse: null })
3 years ago
}
} else {
const inHouse = false
adjustPaddingForTextAd(displayAd, true)
resolve({ data: data, inHouse: inHouse })
3 years ago
}
3 years ago
})
} else {
adjustPaddingForTextAd(displayAd, false)
resolve({ data: null, inHouse: null })
3 years ago
}
})
}
function fetchTextAdData () {
3 years ago
if (showAd()) {
getTextAdData()
.then(({ data, inHouse }) => {
3 years ago
if (data) {
const prefix = inHouse ? 'Featured' : 'Sponsored'
3 years ago
const { ad: { name, description_short: descriptionShort, thumbnail, url, cta_button: ctaButton, impressionUrl } } = data
$('.ad-name').text(name)
$('.ad-short-description').text(descriptionShort)
$('.ad-cta-button').text(ctaButton)
$('.ad-url').attr('href', url)
$('.ad-prefix').text(prefix)
$('.ad').show()
3 years ago
const urlObject = new URL(url)
if (urlObject.hostname === 'nifty.ink') {
$('.ad-img-url').replaceWith('🎨')
} else {
$('.ad-img-url').attr('src', thumbnail)
}
3 years ago
countImpressions(impressionUrl)
}
})
}
}
3 years ago
function getRandomInt (min, max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min)) + min
}
3 years ago
export { showAd, getTextAdData, fetchTextAdData }