enhance(AD): 表示される広告の選定条件を変更、縦に長いタイプを設定できるように (MisskeyIO#293)

This commit is contained in:
まっちゃとーにゅ 2023-12-28 10:30:20 +09:00 committed by GitHub
parent 44c10ea991
commit 8a8196aa09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 17 deletions

View file

@ -95,7 +95,7 @@ export default defineComponent({
if (props.ad && item._shouldInsertAd_) {
return [h(MkAd, {
key: item.id + ':ad',
prefer: ['horizontal', 'horizontal-big'],
prefer: [],
}), el];
} else {
return el;

View file

@ -63,24 +63,28 @@ const choseAd = (): Ad | null => {
ratio: 0,
} : ad);
let ads = allAds.filter(ad => props.prefer.includes(ad.place));
const valuableAds = allAds.filter(ad => ad.ratio !== 0);
const lowPriorityAds = allAds.filter(ad => ad.ratio === 0);
if (ads.length === 0) {
ads = allAds.filter(ad => ad.place === 'square');
let ads: Ad[];
const preferredAds = valuableAds.filter(ad => props.prefer.includes(ad.place));
if (preferredAds.length !== 0) {
ads = preferredAds;
} else {
ads = lowPriorityAds.filter(ad => props.prefer.includes(ad.place));
}
const lowPriorityAds = ads.filter(ad => ad.ratio === 0);
ads = ads.filter(ad => ad.ratio !== 0);
if (ads.length === 0) {
if (lowPriorityAds.length !== 0) {
return lowPriorityAds[Math.floor(Math.random() * lowPriorityAds.length)];
const nonPreferredAds = valuableAds.filter(ad => !props.prefer.includes(ad.place));
if (nonPreferredAds.length !== 0) {
ads = nonPreferredAds;
} else {
return null;
ads = lowPriorityAds.filter(ad => !props.prefer.includes(ad.place));
}
}
const totalFactor = ads.reduce((a, b) => a + b.ratio, 0);
if (totalFactor === 0) return ads[Math.floor(Math.random() * ads.length)];
const r = Math.random() * totalFactor;
let stackedFactor = 0;
@ -148,7 +152,8 @@ function reduceFrequency(): void {
&.form_vertical {
> .link,
> .link > .img {
max-width: min(100px, 100%);
max-width: min(300px, 100%);
max-height: 450px;
}
}
}