Shows ads based on file size

This commit is contained in:
2021-06-10 18:00:04 +02:00
parent d14b05a9c5
commit e84554bd96
2 changed files with 156 additions and 140 deletions

View File

@@ -1,118 +1,119 @@
{{ 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" src="//ad.a-ads.com/73974?size=728x90&background_color={{.Style.Layer1Color.RGB}}&text_color={{.Style.TextColor.RGB}}&title_color={{.Style.HighlightColor.RGB}}&title_hover_color={{.Style.HighlightColor.RGB}}&link_color={{.Style.HighlightColor.RGB}}&link_hover_color={{.Style.HighlightColor.RGB}}"
src="//ad.a-ads.com/73974?size=728x90&background_color={{.Style.Layer1Color.RGB}}&text_color={{.Style.TextColor.RGB}}&title_color={{.Style.HighlightColor.RGB}}&title_hover_color={{.Style.HighlightColor.RGB}}&link_color={{.Style.HighlightColor.RGB}}&link_hover_color={{.Style.HighlightColor.RGB}}" 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 13 }}
{{ else if eq .Other.AdBannerType 1 }} <!-- 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%" />
</a>
{{else if eq .Other.AdBannerType 2}}
<!-- Patreon -->
<div style="text-align: center; line-height: 22px; font-size: 18px;">
<div style="margin: 4px 8px; display: inline-block; vertical-align: middle;">
Pixeldrain needs money to survive<br/>
<a href="/click/7wy9gg2J?target=%2Fsubscribe" class="button button_highlight">
Support me on Patreon and get some neat perks
</a> </a>
</div> {{else if eq .Other.AdBannerType 2}}
<div style="margin: 4px 8px; display: inline-block; vertical-align: middle; text-align: left;"> <!-- Patreon -->
No ads when viewing files<br/> <div style="text-align: center; line-height: 22px; font-size: 18px;">
No ads on your uploaded files<br/> <div style="margin: 4px 8px; display: inline-block; vertical-align: middle;">
Longer file retention<br/> Pixeldrain needs money to survive<br/>
</div> <a href="/click/7wy9gg2J?target=%2Fsubscribe" class="button button_highlight">
<div> Support me on Patreon and get some neat perks
{{else if eq .Other.AdBannerType 3}} </a>
<!-- Soul Studio --> </div>
<a class="sponsors_banner" style="display: inline-block; width: 842px; height: 125px;" href="/click/RJRbh7Tn?target=https%3A%2F%2Fsoulstudio.nl%2Fonline-y"> <div style="margin: 4px 8px; display: inline-block; vertical-align: middle; text-align: left;">
<img src="/res/img/misc/banner_soul_studio.png" style="width: 100%; height: 100%" /> No ads when viewing files<br/>
</a> No ads on your uploaded files<br/>
{{else if eq .Other.AdBannerType 4}} Longer file retention<br/>
<!-- Amarula Jobs --> </div>
<a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarulasolutions.com/jobs"> <div>
<img src="/res/img/misc/banner_amarula_jobs.png" style="width: 100%; height: 100%" /> {{else if eq .Other.AdBannerType 3}}
</a> <!-- Soul Studio -->
{{ else if eq .Other.AdBannerType 6 }} <a class="sponsors_banner" style="display: inline-block; width: 842px; height: 125px;" href="/click/RJRbh7Tn?target=https%3A%2F%2Fsoulstudio.nl%2Fonline-y">
<div class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;"> <img src="/res/img/misc/banner_soul_studio.png" style="width: 100%; height: 100%" />
<script type="text/javascript"> </a>
atOptions = { {{else if eq .Other.AdBannerType 4}}
'key' : 'a62692cf48c3969d426a09c868ae13f7', <!-- Amarula Jobs -->
'format' : 'iframe', <a class="sponsors_banner" style="display: inline-block; width: 576px; height: 96px;" href="/click/DtZ3hHT9?target=https%3A%2F%2Fwww.amarulasolutions.com/jobs">
'height' : 90, <img src="/res/img/misc/banner_amarula_jobs.png" style="width: 100%; height: 100%" />
'width' : 728, </a>
'params' : {} {{ else if eq .Other.AdBannerType 6 }}
}; <div class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;">
document.write('<scr' + 'ipt type="text/javascript" defer src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.highperformancedisplaycontent.com/a62692cf48c3969d426a09c868ae13f7/invoke.js"></scr' + 'ipt>'); <script type="text/javascript">
</script> atOptions = {
</div> 'key' : 'a62692cf48c3969d426a09c868ae13f7',
{{ else if eq .Other.AdBannerType 7 }} 'format' : 'iframe',
<a class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;" href="/brave"> 'height' : 90,
<img src="/res/img/misc/brave-728x90.png" style="width: 100%; height: 100%" /> 'width' : 728,
</a> 'params' : {}
{{ else if eq .Other.AdBannerType 8 }} };
<div style="text-align: center; line-height: 1.4em; font-size: 22px;"> document.write('<scr' + 'ipt type="text/javascript" defer src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.highperformancedisplaycontent.com/a62692cf48c3969d426a09c868ae13f7/invoke.js"></scr' + 'ipt>');
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/> </script>
<div style="margin: 4px; display: inline-block; vertical-align: middle;"> </div>
Are your files expiring too quickly?<br/> {{ else if eq .Other.AdBannerType 7 }}
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a> <a class="sponsors_banner" style="display: inline-block; width: 728px; height: 90px;" href="/brave">
</div> <img src="/res/img/misc/brave-728x90.png" style="width: 100%; height: 100%" />
</div> </a>
{{ else if eq .Other.AdBannerType 9 }} {{ else if eq .Other.AdBannerType 8 }}
<div style="text-align: center; line-height: 1.4em; font-size: 22px;"> <div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/> <img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;"> <div style="margin: 4px; display: inline-block; vertical-align: middle;">
Are your files too large to share?<br/> Are your files expiring too quickly?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a> <a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div> </div>
</div> </div>
{{ else if eq .Other.AdBannerType 10 }} {{ else if eq .Other.AdBannerType 9 }}
<div style="text-align: center; line-height: 1.4em; font-size: 22px;"> <div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/> <img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;"> <div style="margin: 4px; display: inline-block; vertical-align: middle;">
Are you tired of advertisements?<br/> Are your files too large to share?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a> <a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div> </div>
</div> </div>
{{ else if eq .Other.AdBannerType 11 }} {{ else if eq .Other.AdBannerType 10 }}
<div style="text-align: center; line-height: 1.4em; font-size: 22px;"> <div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/> <img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
<div style="margin: 4px; display: inline-block; vertical-align: middle;"> <div style="margin: 4px; display: inline-block; vertical-align: middle;">
Concerned about your online privacy?<br/> Are you tired of advertisements?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a> <a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div> </div>
</div> </div>
{{ else if eq .Other.AdBannerType 12 }} {{ else if eq .Other.AdBannerType 11 }}
<div class="sponsors_banner" style="display: inline-block; width: 300px; height: 100px;"> <div style="text-align: center; line-height: 1.4em; font-size: 22px;">
<script data-cfasync="false" type="text/javascript" src="//myolnyr5bsk18.com/lv/esnk/1846778/code.js" async id="__clb-1846778"></script> <img src="/res/img/pixeldrain_128.png" style="height: 2.4em; vertical-align: middle; margin: 4px;"/>
</div> <div style="margin: 4px; display: inline-block; vertical-align: middle;">
Concerned about your online privacy?<br/>
<a href="/click/7wy9gg2J?target=%2F%23pro" class="button button_highlight">Pixeldrain Pro: Only €2 per month</a>
</div>
</div>
{{ else if eq .Other.AdBannerType 12 }}
<div class="sponsors_banner" style="display: inline-block; width: 300px; height: 100px;">
<script data-cfasync="false" type="text/javascript" src="//myolnyr5bsk18.com/lv/esnk/1846778/code.js" async id="__clb-1846778"></script>
</div>
{{ end }}
{{ end }} {{ end }}
{{ end }}
{{ define "floating_ads"}} {{ define "floating_ads"}}
{{ if eq .Other.AdFloaterType 3 }}
<!-- AdMaven -->
<script data-cfasync="false" async src="//d227cncaprzd7y.cloudfront.net/?acncd=905608"></script>
{{ else if eq .Other.AdFloaterType 2 }}
<!-- AdSterra -->
<script type='text/javascript' async src='//concoursestrickenpuppy.com/4c/4d/90/4c4d90a2e79b0e049f811a663f3e3c07.js'></script>
{{ else if eq .Other.AdFloaterType 1 }}
<!-- PropellerAds -->
<script>
// Load fires when the page is completely finished loading, including assets
window.addEventListener("load", () => {
(function(d,z,s){
s.src='//'+d+'/400/'+z
try{(document.body||document.documentElement).appendChild(s)}catch(e){}
})('in-page-push.com',3724132,document.createElement('script'))
})
</script>
{{ end }}
{{ if eq .Other.AdFloaterType 3 }} {{ if eq .Other.AdUnderType 1}}
<!-- AdMaven --> <script data-cfasync="false" type="text/javascript" async src="//depirsmandk5.com/t/9/fret/meow4/1846775/brt.js"></script>
<script data-cfasync="false" async src="//d227cncaprzd7y.cloudfront.net/?acncd=905608"></script> {{ end }}
{{ else if eq .Other.AdFloaterType 2 }}
<!-- AdSterra -->
<script type='text/javascript' async src='//concoursestrickenpuppy.com/4c/4d/90/4c4d90a2e79b0e049f811a663f3e3c07.js'></script>
{{ else if eq .Other.AdFloaterType 1 }}
<!-- PropellerAds -->
<script>
// Load fires when the page is completely finished loading, including assets
window.addEventListener("load", () => {
(function(d,z,s){
s.src='//'+d+'/400/'+z
try{(document.body||document.documentElement).appendChild(s)}catch(e){}
})('in-page-push.com',3724132,document.createElement('script'))
})
</script>
{{ end }}
{{ end }} {{ end }}

View File

@@ -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 {
vd.AdFloaterType = propellerFloat
}
return banner, floater // If the file is larger than 250 MB we enable popunders
} if avgSize > 250e6 {
vd.AdUnderType = clickAduPopunder
type viewerData struct { }
Type string // file or list
CaptchaKey string
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