Shows ads based on file size
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
{{ define "banner_ads"}}
|
{{ define "banner_ads"}}
|
||||||
|
{{ if eq .Other.AdBannerType 1 }}
|
||||||
{{ if eq .Other.AdBannerType 0 }}
|
|
||||||
<!-- scrolling="no" is not allowed by the W3C, but overflow: hidden doesn't work in chrome, so I have no choice -->
|
<!-- scrolling="no" is not allowed by the W3C, but overflow: hidden doesn't work in chrome, so I have no choice -->
|
||||||
<iframe class="sponsors_banner"
|
<iframe class="sponsors_banner"
|
||||||
data-aa="73974"
|
data-aa="73974"
|
||||||
@@ -8,7 +7,7 @@
|
|||||||
style="width:728px; height:90px; border:none; padding:0; overflow:hidden;"
|
style="width:728px; height:90px; border:none; padding:0; overflow:hidden;"
|
||||||
scrolling="no">
|
scrolling="no">
|
||||||
</iframe>
|
</iframe>
|
||||||
{{ else if eq .Other.AdBannerType 1 }}
|
{{ else if eq .Other.AdBannerType 13 }}
|
||||||
<!-- Amarula electronics -->
|
<!-- Amarula electronics -->
|
||||||
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarula-electronics.com">
|
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarula-electronics.com">
|
||||||
<img src="/res/img/misc/banner_as.png" style="width: 100%; height: 100%" />
|
<img src="/res/img/misc/banner_as.png" style="width: 100%; height: 100%" />
|
||||||
@@ -92,10 +91,9 @@
|
|||||||
<script data-cfasync="false" type="text/javascript" src="//myolnyr5bsk18.com/lv/esnk/1846778/code.js" async id="__clb-1846778"></script>
|
<script data-cfasync="false" type="text/javascript" src="//myolnyr5bsk18.com/lv/esnk/1846778/code.js" async id="__clb-1846778"></script>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ define "floating_ads"}}
|
|
||||||
|
|
||||||
|
{{ define "floating_ads"}}
|
||||||
{{ if eq .Other.AdFloaterType 3 }}
|
{{ if eq .Other.AdFloaterType 3 }}
|
||||||
<!-- AdMaven -->
|
<!-- AdMaven -->
|
||||||
<script data-cfasync="false" async src="//d227cncaprzd7y.cloudfront.net/?acncd=905608"></script>
|
<script data-cfasync="false" async src="//d227cncaprzd7y.cloudfront.net/?acncd=905608"></script>
|
||||||
@@ -115,4 +113,7 @@ window.addEventListener("load", () => {
|
|||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if eq .Other.AdUnderType 1}}
|
||||||
|
<script data-cfasync="false" type="text/javascript" async src="//depirsmandk5.com/t/9/fret/meow4/1846775/brt.js"></script>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@@ -28,11 +28,30 @@ func browserCompat(ua string) bool {
|
|||||||
return strings.Contains(ua, "MSIE") || strings.Contains(ua, "Trident/7.0")
|
return strings.Contains(ua, "MSIE") || strings.Contains(ua, "Trident/7.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
func adType() (banner, floater int) {
|
type viewerData struct {
|
||||||
|
Type string // file or list
|
||||||
|
CaptchaKey string
|
||||||
|
ViewToken string
|
||||||
|
AdBannerType int
|
||||||
|
AdFloaterType int
|
||||||
|
AdUnderType int
|
||||||
|
FileAdsEnabled bool
|
||||||
|
UserAdsEnabled bool
|
||||||
|
Embedded bool
|
||||||
|
APIResponse interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (vd *viewerData) adType(files []pixelapi.ListFile) {
|
||||||
|
var avgSize int64
|
||||||
|
for _, v := range files {
|
||||||
|
avgSize += v.Size
|
||||||
|
}
|
||||||
|
avgSize /= int64(len(files))
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Banners
|
// Banners
|
||||||
aAds = 0
|
none = 0
|
||||||
amarulaElectronics = 1
|
aAds = 1
|
||||||
patreon = 2
|
patreon = 2
|
||||||
soulStudio = 3
|
soulStudio = 3
|
||||||
amarulaSolutions = 4
|
amarulaSolutions = 4
|
||||||
@@ -44,43 +63,40 @@ func adType() (banner, floater int) {
|
|||||||
pdpro3 = 10
|
pdpro3 = 10
|
||||||
pdpro4 = 11
|
pdpro4 = 11
|
||||||
clickAduBanner = 12
|
clickAduBanner = 12
|
||||||
|
amarulaElectronics = 13
|
||||||
|
|
||||||
// Floaters
|
// Floaters
|
||||||
none = 0
|
|
||||||
propellerFloat = 1
|
propellerFloat = 1
|
||||||
adSterraFloat = 2
|
adSterraFloat = 2
|
||||||
adMavenFloat = 3
|
adMavenFloat = 3
|
||||||
|
|
||||||
|
// Popunders
|
||||||
|
clickAduPopunder = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
// Intn returns a number up to n, but never n itself. So to get a random 0
|
// 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
|
// or 1 we need to give it n=2. We can use this function to make other
|
||||||
// splits like 1/3 1/4, etc
|
// splits like 1/3 1/4, etc
|
||||||
switch i := rand.Intn(10); i {
|
switch i := rand.Intn(3); i {
|
||||||
case 0, 1: // 20%
|
case 0: // 33%
|
||||||
banner = clickAduBanner
|
vd.AdBannerType = clickAduBanner
|
||||||
case 2, 3, 4, 5: // 40%
|
case 1: // 33%
|
||||||
banner = brave
|
vd.AdBannerType = brave
|
||||||
case 6, 7, 8, 9: // 40%
|
case 2: // 33%
|
||||||
banner = aAds
|
vd.AdBannerType = aAds
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("random number generator returned unrecognised number: %d", i))
|
panic(fmt.Errorf("random number generator returned unrecognised number: %d", i))
|
||||||
}
|
}
|
||||||
|
|
||||||
floater = propellerFloat
|
// If the file is larger than 10 MB we enable popups
|
||||||
|
if avgSize > 10e6 {
|
||||||
return banner, floater
|
vd.AdFloaterType = propellerFloat
|
||||||
}
|
}
|
||||||
|
|
||||||
type viewerData struct {
|
// If the file is larger than 250 MB we enable popunders
|
||||||
Type string // file or list
|
if avgSize > 250e6 {
|
||||||
CaptchaKey string
|
vd.AdUnderType = clickAduPopunder
|
||||||
ViewToken string
|
}
|
||||||
AdBannerType int
|
|
||||||
AdFloaterType int
|
|
||||||
FileAdsEnabled bool
|
|
||||||
UserAdsEnabled bool
|
|
||||||
Embedded bool
|
|
||||||
APIResponse interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeFileViewer controller for GET /u/:id
|
// ServeFileViewer controller for GET /u/:id
|
||||||
@@ -129,7 +145,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
FileAdsEnabled: files[0].ShowAds,
|
FileAdsEnabled: files[0].ShowAds,
|
||||||
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
|
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
|
||||||
}
|
}
|
||||||
vd.AdBannerType, vd.AdFloaterType = adType()
|
vd.adType(files)
|
||||||
|
|
||||||
if len(ids) > 1 {
|
if len(ids) > 1 {
|
||||||
templateData.Title = fmt.Sprintf("%d files on pixeldrain", len(files))
|
templateData.Title = fmt.Sprintf("%d files on pixeldrain", len(files))
|
||||||
@@ -178,8 +194,7 @@ func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Requ
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "file",
|
Type: "file",
|
||||||
CaptchaKey: wc.captchaSiteKey,
|
CaptchaKey: wc.captchaSiteKey,
|
||||||
AdBannerType: 0, // Always show a-ads on the demo page
|
AdBannerType: 1, // Always show a-ads on the demo page
|
||||||
AdFloaterType: 0, // No floaters
|
|
||||||
FileAdsEnabled: true,
|
FileAdsEnabled: true,
|
||||||
UserAdsEnabled: true,
|
UserAdsEnabled: true,
|
||||||
APIResponse: map[string]interface{}{
|
APIResponse: map[string]interface{}{
|
||||||
@@ -234,7 +249,7 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
|
UserAdsEnabled: !(templateData.Authenticated && templateData.User.Subscription.DisableAdDisplay),
|
||||||
APIResponse: list,
|
APIResponse: list,
|
||||||
}
|
}
|
||||||
vd.AdBannerType, vd.AdFloaterType = adType()
|
vd.adType(list.Files)
|
||||||
|
|
||||||
if _, ok := r.URL.Query()["embed"]; ok {
|
if _, ok := r.URL.Query()["embed"]; ok {
|
||||||
vd.Embedded = true
|
vd.Embedded = true
|
||||||
|
Reference in New Issue
Block a user