itube-specs 0.0.808 → 0.0.809

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@
12
12
  </template>
13
13
 
14
14
  <script setup lang="ts">
15
- import { BannerHelper } from '~/utils/banner-helper';
15
+ import { BannerHelper } from '../../utils/banner-helper';
16
16
  import { AdBannerType, AdSpotType } from '../../runtime';
17
17
  </script>
18
18
 
@@ -12,7 +12,7 @@
12
12
  </template>
13
13
 
14
14
  <script setup lang="ts">
15
- import { BannerHelper } from '~/utils/banner-helper';
15
+ import { BannerHelper } from '../../utils/banner-helper';
16
16
  import { AdBannerType, AdSpotType } from '../../runtime';
17
17
  </script>
18
18
 
@@ -8,7 +8,7 @@
8
8
 
9
9
  <script setup lang="ts">
10
10
 
11
- import { BannerHelper } from '~/utils/banner-helper';
11
+ import { BannerHelper } from '../../utils/banner-helper';
12
12
  import { AdBannerType, AdSpotType } from '../../runtime';
13
13
  </script>
14
14
 
@@ -20,7 +20,7 @@
20
20
  <script setup lang="ts">
21
21
  import { ITubePlayer } from 'itube-modern-player/vue';
22
22
  import type { Player, PlayerOptions, VideoSource, LocaleCode, AdsOptions, PreviewMetaItem, SceneGroup } from 'itube-modern-player';
23
- import { AdvertsHelper } from '@/utils/adverts-helper';
23
+ import { AdvertsHelper } from '../../utils/adverts-helper';
24
24
  import { AdSpotType, ThumbSize } from '../../runtime';
25
25
  import type { IVideoData, IVideoCard } from '../../types';
26
26
  import playIcon from '~/assets/icons/player/play.svg?raw';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.808",
4
+ "version": "0.0.809",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
package/plugins/adv.ts ADDED
@@ -0,0 +1,15 @@
1
+ // Инициализирует рекламу на клиенте после отрисовки страницы (page:finish),
2
+ // отложенно через requestIdleCallback — чтобы не блокировать основной поток.
3
+ export default defineNuxtPlugin(async (nuxtApp) => {
4
+ if (import.meta.client) {
5
+ nuxtApp.hook('page:finish', () => {
6
+ const init = () => AdvertsHelper.initAdv();
7
+
8
+ if ('requestIdleCallback' in window) {
9
+ requestIdleCallback(init);
10
+ } else {
11
+ setTimeout(init, 200);
12
+ }
13
+ });
14
+ }
15
+ });
@@ -0,0 +1,55 @@
1
+ import type { AdSpotType } from '../runtime';
2
+
3
+ /** Хелпер для работы с рекламным слайдером */
4
+ export class AdvSliderHelper {
5
+ /** Удаляет ранее вставленные скрипты слайдера с указанным src */
6
+ private static cleanOldSlider(scriptUrl: string) {
7
+ document.querySelectorAll('script').forEach(script => {
8
+ if (script.src.includes(scriptUrl)) {
9
+ script.remove();
10
+ }
11
+ });
12
+ }
13
+
14
+ /** Создаёт и вставляет в `<head>` скрипт слайдера для указанных спотов (только на клиенте) */
15
+ private static attachSliderScript(scriptUrl: string, spots: string | number) {
16
+ const ridts = `?_ridts_=${Date.now()}`;
17
+
18
+ const script = document.createElement('script');
19
+ const scriptAttrs = {
20
+ type: 'text/javascript',
21
+ async: 'async',
22
+ src: scriptUrl + ridts,
23
+ defer: 'defer',
24
+ };
25
+
26
+ script.dataset.spots = String(spots);
27
+ script.dataset.subid1 = '%subid1%';
28
+ script.dataset.subid2 = '%subid2%';
29
+ script.dataset.tag = 'asg';
30
+
31
+ Object.entries(scriptAttrs).forEach(([key, value]) => {
32
+ script.setAttribute(key, value);
33
+ });
34
+
35
+ if (import.meta.client) {
36
+ document.head.appendChild(script);
37
+ }
38
+ }
39
+
40
+
41
+ /** Инициализирует слайдер: чистит старые скрипты и подключает новый (кроме страницы adv/banner) */
42
+ public static async initSlider(config: Record<AdSpotType, number | string>, type: AdSpotType) {
43
+ const domain = await AdvertsHelper.getAntiAdblockDomain();
44
+ const scriptUrl = `https://${domain}/bAm3r8d.js`;
45
+
46
+ const route = useRoute();
47
+
48
+ if (route && route.fullPath.includes('adv/banner')) {
49
+ return;
50
+ }
51
+
52
+ AdvSliderHelper.cleanOldSlider(scriptUrl);
53
+ AdvSliderHelper.attachSliderScript(scriptUrl, config[type]);
54
+ }
55
+ }
@@ -0,0 +1,83 @@
1
+ import { AdSpotType } from '../runtime';
2
+ import type { Niche } from '../runtime';
3
+ import { NicheHelper } from './niche-helper';
4
+ import { PopunderHelper } from './popunder-helper';
5
+
6
+ /** Класс для работы с рекламой */
7
+ export class AdvertsHelper {
8
+ /** Метод для получения текущего антиадблок домена */
9
+ public static async getAntiAdblockDomain(): Promise<string> {
10
+ const { state, update } = useAntiadBlockDomains();
11
+
12
+ if (!state.value.data) {
13
+ await update();
14
+ }
15
+
16
+ return state.value.data || '';
17
+ };
18
+
19
+ /** Метод для спота получения линка преролла по типу спота и нише */
20
+ public static async getPrerollVastLink(type: AdSpotType, niche?: Niche): Promise<string> {
21
+ const defaultValue = '';
22
+
23
+ if (!useRuntimeConfig().public.featureFlags.AdsPrerollEnabled) {
24
+ return defaultValue;
25
+ }
26
+
27
+ const _niche = niche || NicheHelper.getSiteDefaultNiche();
28
+ const nicheConfig = useRuntimeConfig().public.adsConfig.Preroll[_niche];
29
+
30
+ if (nicheConfig) {
31
+ const domain = await this.getAntiAdblockDomain();
32
+ return `https://${domain}/api/spots/${nicheConfig[type]}`;
33
+ } else {
34
+ return defaultValue;
35
+ }
36
+ }
37
+
38
+ /** Метод для инициализации попандера */
39
+ public static async initPopunders(niche?: Niche): Promise<undefined> {
40
+ const type = PopunderHelper.hasQueryUtmParams() ? AdSpotType.Primary : AdSpotType.Secondary;
41
+
42
+ if (!useRuntimeConfig().public.featureFlags.AdsPopunderEnabled || import.meta.server) {
43
+ return;
44
+ }
45
+
46
+ const _niche = niche || NicheHelper.getSiteDefaultNiche();
47
+ const nicheConfig = useRuntimeConfig().public.adsConfig.Popunder[_niche];
48
+
49
+ if (nicheConfig) {
50
+ await PopunderHelper.initPopunder(nicheConfig, type);
51
+ }
52
+ }
53
+
54
+ /** Метод получения линка для нативки */
55
+ public static async initBanners(): Promise<undefined> {
56
+ if (!useRuntimeConfig().public.featureFlags.AdsNativeEnabled || import.meta.server) {
57
+ return;
58
+ }
59
+
60
+ await BannerHelper.initBanner();
61
+ }
62
+
63
+ /** Метод для инициализации рекламного слайдера по нише */
64
+ public static async initSlider(niche?: Niche): Promise<undefined> {
65
+ if (!useRuntimeConfig().public.featureFlags.AdsSliderEnabled) {
66
+ return;
67
+ }
68
+
69
+ const _niche = niche || NicheHelper.getSiteDefaultNiche();
70
+ const nicheConfig = useRuntimeConfig().public.adsConfig.Slider[_niche];
71
+
72
+ await AdvSliderHelper.initSlider(nicheConfig, AdSpotType.Primary);
73
+ }
74
+
75
+ /** Запуск рекламы */
76
+ public static async initAdv() {
77
+ await Promise.all([
78
+ AdvertsHelper.initBanners(),
79
+ AdvertsHelper.initPopunders(),
80
+ AdvertsHelper.initSlider(),
81
+ ]);
82
+ }
83
+ }
@@ -0,0 +1,60 @@
1
+ import type { AdBannerType, AdSpotType } from '../runtime';
2
+ import { NicheHelper } from './niche-helper';
3
+
4
+ /** Хелпер для работы с баннерной (нативной) рекламой */
5
+ export class BannerHelper {
6
+ /** Удаляет ранее вставленные скрипты баннера с указанным src */
7
+ private static cleanOldBanners(scriptUrl: string) {
8
+ document.querySelectorAll('script').forEach(script => {
9
+ if (script.src.includes(scriptUrl)) {
10
+ script.remove();
11
+ }
12
+ });
13
+ }
14
+
15
+ /** Создаёт и вставляет в `<head>` скрипт баннера (с задержкой 250мс, только на клиенте) */
16
+ private static attachBannerScript(scriptUrl: string) {
17
+ const ridts = `?_ridts_=${Date.now()}`;
18
+
19
+ const script = document.createElement('script');
20
+ const scriptAttrs = {
21
+ type: 'text/javascript',
22
+ async: 'async',
23
+ src: scriptUrl + ridts,
24
+ defer: 'defer',
25
+ };
26
+
27
+ script.dataset.subid1 = '%subid1%';
28
+
29
+ Object.entries(scriptAttrs).forEach(([key, value]) => {
30
+ script.setAttribute(key, value);
31
+ });
32
+
33
+ if (import.meta.client) {
34
+ setTimeout(() => {
35
+ document.head.appendChild(script);
36
+ }, 250);
37
+ }
38
+ }
39
+
40
+ /** Возвращает идентификатор спота баннера по типу баннера и спота для дефолтной ниши сайта */
41
+ public static getBannerSpot(bannerType: AdBannerType, spotType: AdSpotType) {
42
+ const _niche = NicheHelper.getSiteDefaultNiche();
43
+ const nicheConfig = useRuntimeConfig().public.adsConfig[bannerType][_niche];
44
+
45
+ if (nicheConfig) {
46
+ return nicheConfig[spotType];
47
+ }
48
+
49
+ return '';
50
+ };
51
+
52
+ /** Инициализирует баннер: чистит старые скрипты и подключает свежий */
53
+ public static async initBanner() {
54
+ const domain = await AdvertsHelper.getAntiAdblockDomain();
55
+ const scriptUrl = `https://${domain}/fowuag19.js`;
56
+
57
+ BannerHelper.cleanOldBanners(scriptUrl);
58
+ BannerHelper.attachBannerScript(scriptUrl);
59
+ }
60
+ }
@@ -0,0 +1,110 @@
1
+ import type { AdSpotType } from '../runtime';
2
+
3
+ /** Хелпер для работы с попандерной рекламой и UTM-метками */
4
+ export class PopunderHelper {
5
+ private static utmParamsKeys = [
6
+ 'utm_campaign',
7
+ 'utm_medium',
8
+ 'utm_source',
9
+ ];
10
+
11
+ /** Открыта ли страница уже после срабатывания попандера (по метке `asgtbndr` в URL) */
12
+ private static isPageOpenAfterPopunder() {
13
+ return !!(new URLSearchParams(location.search).get('asgtbndr'));
14
+ }
15
+
16
+ /** Сохраняет UTM-параметры из URL в sessionStorage */
17
+ private static saveUtmParams() {
18
+ const query = new URLSearchParams(location.search);
19
+
20
+ query.forEach((value, key) => {
21
+ if (PopunderHelper.utmParamsKeys.includes(key)) {
22
+ sessionStorage.setItem(key, value);
23
+ }
24
+ });
25
+ };
26
+
27
+ /** Удаляет старые скрипты попандера и связанные с ним глобальные переменные window */
28
+ private static cleanOldPopunders(scriptUrl: string) {
29
+ document.querySelectorAll('script').forEach(script => {
30
+ if (script.src.includes(scriptUrl)) {
31
+ script.remove();
32
+ }
33
+ });
34
+
35
+ const puWindowKeys = [
36
+ 'AsgBanner',
37
+ 'NaConf',
38
+ 'asgAdgptLoaded',
39
+ 'asgPopScript',
40
+ 'asgfp'
41
+ ];
42
+
43
+ puWindowKeys.forEach((key) => {
44
+ if (window[key]) {
45
+ delete window[key];
46
+ }
47
+ });
48
+ }
49
+
50
+ /** Создаёт и вставляет в `<head>` скрипт попандера для указанных спотов (только на клиенте) */
51
+ private static attachPopunderScript(scriptUrl: string, spots: string) {
52
+ const ridts = `?_ridts_=${Date.now()}`;
53
+
54
+ const script = document.createElement('script');
55
+ const scriptAttrs = {
56
+ type: 'text/javascript',
57
+ async: 'async',
58
+ src: scriptUrl + ridts,
59
+ defer: 'defer',
60
+ };
61
+
62
+ script.dataset.spots = spots;
63
+ script.dataset.subid1 = '%subid1%';
64
+ script.dataset.tag = 'asg';
65
+
66
+ Object.entries(scriptAttrs).forEach(([key, value]) => {
67
+ script.setAttribute(key, value);
68
+ });
69
+
70
+ if (import.meta.client) {
71
+ document.head.appendChild(script);
72
+ }
73
+ }
74
+
75
+ /** Возвращает сохранённые в sessionStorage UTM-параметры */
76
+ public static getSessionUtmParams(): Record<string, string> {
77
+ const result = {} as Record<string, string>;
78
+
79
+ PopunderHelper.utmParamsKeys.forEach((key) => {
80
+ if (sessionStorage.getItem(key)) {
81
+ result[key] = sessionStorage.getItem(key) as string;
82
+ }
83
+ });
84
+
85
+ return result;
86
+ }
87
+
88
+ /** Присутствуют ли в URL все ожидаемые UTM-параметры */
89
+ public static hasQueryUtmParams(): boolean {
90
+ const query = new URLSearchParams(location.search);
91
+ return PopunderHelper.utmParamsKeys.every((key) => query.has(key));
92
+ }
93
+
94
+ /** Инициализирует попандер: чистит старые скрипты, подключает новый, сохраняет UTM */
95
+ public static async initPopunder(config: Record<AdSpotType, number | string>, type: AdSpotType) {
96
+ if (PopunderHelper.isPageOpenAfterPopunder()) {
97
+ return;
98
+ }
99
+
100
+ const domain = await AdvertsHelper.getAntiAdblockDomain();
101
+ const scriptUrl = `https://${domain}/D2a1OF3.js`;
102
+
103
+ /** Clean old scripts */
104
+ PopunderHelper.cleanOldPopunders(scriptUrl);
105
+
106
+ PopunderHelper.attachPopunderScript(scriptUrl, String(config[type]));
107
+
108
+ PopunderHelper.saveUtmParams();
109
+ }
110
+ }