Add popunder ads based on file size

This commit is contained in:
2021-06-14 14:56:04 +02:00
parent d1fb97c9b9
commit 8817e7cb16
4 changed files with 34 additions and 16 deletions

View File

@@ -113,7 +113,20 @@
</script>
{{ end }}
{{ if eq .Other.AdUnderType 1}}
{{ if eq .Other.AdPopupType 1 }}
<script data-cfasync="false" type="text/javascript" async src="//depirsmandk5.com/t/9/fret/meow4/1846775/brt.js"></script>
{{ else if eq .Other.AdPopupType 2 }}
<script>
window.addEventListener("load", () => {
(function(s,u,z,p){
s.src=u,s.setAttribute('data-zone',z),p.appendChild(s);
})(
document.createElement('script'),
'https://iclickcdn.com/tag.min.js',
3750089,
document.body||document.documentElement,
)
})
</script>
{{ end }}
{{ end }}

View File

@@ -30,7 +30,7 @@ type viewerData struct {
ViewToken string
AdBannerType int
AdFloaterType int
AdUnderType int
AdPopupType int
FileAdsEnabled bool
UserAdsEnabled bool
Embedded bool
@@ -38,6 +38,10 @@ type viewerData struct {
}
func (vd *viewerData) adType(files []pixelapi.ListFile) {
if len(files) == 0 {
return
}
var avgSize int64
for _, v := range files {
avgSize += v.Size
@@ -67,31 +71,31 @@ func (vd *viewerData) adType(files []pixelapi.ListFile) {
adMavenFloat = 3
// Popunders
clickAduPopunder = 1
clickAduPopup = 1
propellerPopup = 2
)
// Intn returns a number up to n, but never n itself. So to get a random 0
// or 1 we need to give it n=2. We can use this function to make other
// splits like 1/3 1/4, etc
switch i := rand.Intn(3); i {
case 0: // 33%
switch i := rand.Intn(4); i {
case 0: // 25%
vd.AdBannerType = clickAduBanner
case 1: // 33%
case 1: // 25%
vd.AdBannerType = brave
case 2: // 33%
case 2, 3: // 50%
vd.AdBannerType = aAds
default:
panic(fmt.Errorf("random number generator returned unrecognised number: %d", i))
}
// If the file is larger than 10 MB we enable popups
// If the file is larger than 10 MB we enable floating popups
if avgSize > 10e6 {
vd.AdFloaterType = propellerFloat
}
// If the file is larger than 250 MB we enable popunders
if avgSize > 250e6 {
vd.AdUnderType = clickAduPopunder
vd.AdPopupType = clickAduPopup
}
}

View File

@@ -181,6 +181,7 @@ func New(
// Admin settings
{GET, "admin" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},
{GET, "admin/status" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},
{GET, "admin/abuse_reporters" /**/, wc.serveTemplate("admin", handlerOpts{Auth: true})},
{GET, "admin/abuse_reports" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},
{GET, "admin/ip_bans" /* */, wc.serveTemplate("admin", handlerOpts{Auth: true})},