macro-parameters 0.0.5 → 0.0.7

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.
package/README.md CHANGED
@@ -0,0 +1,22 @@
1
+ # macro-parameters
2
+
3
+ macro-parameters is a JavaScript library for replacing‌ device placeholders
4
+
5
+
6
+
7
+ # Usage
8
+
9
+
10
+
11
+ ```
12
+ import MacroSubstitution from "macro-parameters";
13
+
14
+ const obj = new MacroSubstitution();
15
+ obj.set({
16
+ player_height: "1280",
17
+ player_width: "720",
18
+ });
19
+ obj.handle("https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8?ads.cb=[rnd]&ads.ua=[device_user_agent]&player_height=[player_height]&player_width=[player_width]")
20
+ ```
21
+
22
+ # API
package/index.js CHANGED
@@ -1,81 +1,105 @@
1
- function getCookie(name) {
2
- const reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
3
- let arr;
4
- let source =
5
- document.cookie ||
6
- (window.localStorage && window.localStorage.cookie) ||
7
- "";
8
- return (arr = source.match(reg)) ? unescape(arr[2]) : "";
9
- }
1
+ /******************************************************************************
2
+ Copyright (c) Microsoft Corporation.
10
3
 
11
- function getLocalStorage(name) {
12
- if (typeof localStorage === "object") {
13
- return localStorage.getItem(name)
14
- }
15
- return null;
16
- }
17
- function getTvBrand() {
18
- if (localStorage.getItem("brand")) {//TODO: 处理whaleos的一些特殊情况,后期可以考虑去除
19
- return localStorage.getItem("brand");
20
- }
21
- var userAgent = navigator.userAgent.toUpperCase();
22
- var _tvBrand = "others";
23
- if (userAgent.indexOf("AOC") > -1) {
24
- _tvBrand = "aoc";
25
- } else if (userAgent.indexOf("PHILIPS") > -1) {
26
- _tvBrand = "philips";
27
- } else {
28
- _tvBrand = "others";
29
- }
30
- return _tvBrand;
31
- }
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
32
6
 
33
- function getProfileId() {
34
- //Get the profile id from cookie
35
- var _profileId = getCookie("profileid") || getCookie("profileId");
36
- var items = [];
37
- if (_profileId && _profileId != "") {
38
- // if profile id exists split it with underscore
39
- items = _profileId.split("_");
40
- return items[1];
41
- } else {
42
- return "Unknown";
43
- }
44
- }
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
45
16
 
46
- function setCookie(name, value, expires, path, domain, secure) {
47
- var cookieString =
48
- name +
49
- "=" +
50
- escape(value) +
51
- (expires ? ";expires=" + expires.toGMTString() : "") +
52
- ("") +
53
- ("") +
54
- ("");
55
- document.cookie = cookieString;
56
- }
57
17
 
58
- function getLocationOrigin() {
59
- return (
60
- location.origin ||
61
- `${location.protocol}//${location.host || location.hostname}${location.port
62
- }`
63
- );
64
- }
18
+ var __assign = function() {
19
+ __assign = Object.assign || function __assign(t) {
20
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
21
+ s = arguments[i];
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+
29
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
+ var e = new Error(message);
31
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
+ };
65
33
 
66
- function cleanPlaceholder(str, params) {
67
- for (var k in PlaceHolders) {
68
- var param = k.replace('[', '\\[').replace(']', '\\]');
69
- var paramName = k.replace('[', '').replace(']', '');
70
- str = str.replace(new RegExp(param, 'g'), params[paramName] || PlaceHolders[k]() || "");
34
+ function getCookie(name) {
35
+ var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
36
+ var arr;
37
+ var source = document.cookie ||
38
+ (window.localStorage && window.localStorage.cookie) ||
39
+ "";
40
+ return (arr = source.match(reg)) ? unescape(arr[2]) : "";
41
+ }
42
+ function getLocalStorage(name) {
43
+ if (typeof localStorage === "object") {
44
+ return localStorage.getItem(name);
71
45
  }
72
- return replaceEmpty(str);
46
+ return null;
73
47
  }
74
- function replaceEmpty(content) {
75
- var reg = /\[.*?\]/g;
76
- return content.replace(reg, "");
48
+ function getTvBrand() {
49
+ if (localStorage.getItem("brand")) { //TODO: 处理whaleos的一些特殊情况,后期可以考虑去除
50
+ return localStorage.getItem("brand");
51
+ }
52
+ var userAgent = navigator.userAgent.toUpperCase();
53
+ var _tvBrand = "others";
54
+ if (userAgent.indexOf("AOC") > -1) {
55
+ _tvBrand = "aoc";
56
+ }
57
+ else if (userAgent.indexOf("PHILIPS") > -1) {
58
+ _tvBrand = "philips";
59
+ }
60
+ else {
61
+ _tvBrand = "others";
62
+ }
63
+ return _tvBrand;
64
+ }
65
+ function getProfileId() {
66
+ //Get the profile id from cookie
67
+ var _profileId = getCookie("profileid") || getCookie("profileId");
68
+ var items = [];
69
+ if (_profileId && _profileId != "") {
70
+ // if profile id exists split it with underscore
71
+ items = _profileId.split("_");
72
+ return items[1];
73
+ }
74
+ else {
75
+ return "Unknown";
76
+ }
77
+ }
78
+ function setCookie(name, value, expires, path, domain, secure) {
79
+ var cookieString = name +
80
+ "=" +
81
+ escape(value) +
82
+ (expires ? ";expires=" + expires.toGMTString() : "") +
83
+ ("") +
84
+ ("") +
85
+ ("");
86
+ document.cookie = cookieString;
87
+ }
88
+ function getLocationOrigin() {
89
+ return (location.origin ||
90
+ "".concat(location.protocol, "//").concat(location.host || location.hostname).concat(location.port));
91
+ }
92
+ function getExternalMacroParam(name) {
93
+ var externalMacroParam = window.externalMacroParam;
94
+ if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
95
+ return externalMacroParam[name];
96
+ }
97
+ else {
98
+ return "";
99
+ }
77
100
  }
78
- var PlaceHolders = {
101
+
102
+ var App = {
79
103
  "[tv_domain]": function () {
80
104
  return document.domain;
81
105
  },
@@ -97,32 +121,50 @@ var PlaceHolders = {
97
121
  "[player_width]": function () {
98
122
  return getExternalMacroParam("player_width");
99
123
  },
124
+ "[placement]": function () {
125
+ return getExternalMacroParam("placement");
126
+ }
127
+ };
128
+
129
+ var Content = {
130
+ "[provider_id]": function () {
131
+ return getExternalMacroParam("provider_id");
132
+ },
100
133
  "[channel_no]": function () {
101
134
  return getExternalMacroParam("channel_no");
102
135
  },
103
136
  "[channel_category]": function () {
104
137
  return getExternalMacroParam("channel_category");
105
138
  },
106
- "[whale_ad_id]": function () {
107
- // return WhaleADID;
139
+ "[channel_name]": function () {
140
+ return getExternalMacroParam("channel_category");
108
141
  },
109
- "[relevant_ads]": function () {
110
- // if (isWhaleOSGlobal) {
111
- // return "true"
112
- // }
113
- var reladvertStatus = false;
114
- var userAgent = navigator.userAgent.toUpperCase();
115
- if (userAgent.indexOf("AOC") > -1) {
116
- reladvertStatus = getCookie("relAdvert");
117
- }
118
- else {
119
- reladvertStatus = getCookie("relAdvert");
120
- }
121
- reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
122
- return reladvertStatus;
142
+ "[iab_category]": function () {
143
+ return getExternalMacroParam("iab_category");
123
144
  },
124
- "[device_dnt]": function () {
125
- return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
145
+ "[avod_id]": function () {
146
+ return getExternalMacroParam("avod_id");
147
+ },
148
+ "[avod_genre]": function () {
149
+ return getExternalMacroParam("avod_genre");
150
+ },
151
+ "[avod_title]": function () {
152
+ return getExternalMacroParam("avod_title");
153
+ },
154
+ "[oriented_age]": function () {
155
+ return getExternalMacroParam("oriented_age");
156
+ },
157
+ "[oriented_gender]": function () {
158
+ return getExternalMacroParam("oriented_gender");
159
+ },
160
+ "[ssai_vendor]": function () {
161
+ return getExternalMacroParam("ssai_vendor");
162
+ }
163
+ };
164
+
165
+ var Device = {
166
+ "[whale_ad_id]": function () {
167
+ // return WhaleADID;
126
168
  },
127
169
  "[tv_brand]": function () {
128
170
  return getTvBrand();
@@ -152,24 +194,54 @@ var PlaceHolders = {
152
194
  return 'un';
153
195
  }
154
196
  },
155
- "[privacy_policy]": function () {
156
- return getExternalMacroParam("privacy_policy");
197
+ "[time_zone]": function () {
198
+ return new Date().getTimezoneOffset();
157
199
  },
200
+ };
201
+
202
+ var GDPR = {
158
203
  "[whale_gdpr]": function () {
159
204
  return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
160
205
  },
161
206
  "[whale_gdpr_consent]": function () {
162
207
  return getCookie("tcString") || getLocalStorage('default_tcString');
163
208
  },
209
+ "[relevant_ads]": function () {
210
+ // if (isWhaleOSGlobal) {
211
+ // return "true"
212
+ // }
213
+ var reladvertStatus = "false";
214
+ var userAgent = navigator.userAgent.toUpperCase();
215
+ if (userAgent.indexOf("AOC") > -1) {
216
+ reladvertStatus = getCookie("relAdvert");
217
+ }
218
+ else {
219
+ reladvertStatus = getCookie("relAdvert");
220
+ }
221
+ reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
222
+ return reladvertStatus;
223
+ },
224
+ "[device_dnt]": function () {
225
+ return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
226
+ },
227
+ "[device_lmt]": function () {
228
+ return getCookie("relAdvert") === 'true' ? 0 : 1;
229
+ },
230
+ "[privacy_policy]": function () {
231
+ return getExternalMacroParam("privacy_policy");
232
+ },
233
+ };
234
+
235
+ var Generic = {
164
236
  "[rnd]": function () {
165
237
  return new Date().getTime();
166
238
  },
239
+ "[timestamp]": function () {
240
+ return new Date().getTime();
241
+ },
167
242
  "[ad_sdk_ver]": function () {
168
243
  return "";
169
244
  },
170
- "[time_zone]": function () {
171
- return new Date().getTimezoneOffset();
172
- },
173
245
  "[google_pal]": function () {
174
246
  if (!window.googleNonce && getCookie("googleNonce")) {
175
247
  return getCookie("googleNonce");
@@ -179,15 +251,10 @@ var PlaceHolders = {
179
251
  }
180
252
  return window.googleNonce || '';
181
253
  },
182
- "[device_lmt]": function () {
183
- return getCookie("relAdvert") === 'true' ? 0 : 1;
184
- },
185
- "[avod_id]": function () {
186
- return "";
187
- },
188
- "[avod_title]": function () {
189
- return "";
190
- },
254
+ };
255
+
256
+ //非WhaleAdsMacros定义,但是实际需要用到的参数
257
+ var Other = {
191
258
  "[device_id]": function () {
192
259
  return getCookie("deviceid") || getCookie("deviceId");
193
260
  },
@@ -198,15 +265,20 @@ var PlaceHolders = {
198
265
  return getCookie("usertag");
199
266
  }
200
267
  };
201
- function getExternalMacroParam(name) {
202
- var externalMacroParam = window.externalMacroParam;
203
- if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
204
- return externalMacroParam[name];
205
- }
206
- else {
207
- return "";
268
+
269
+ function cleanPlaceholder(str, params) {
270
+ for (var k in PlaceHolders) {
271
+ var param = k.replace('[', '\\[').replace(']', '\\]');
272
+ var paramName = k.replace('[', '').replace(']', '');
273
+ str = str.replace(new RegExp(param, 'g'), params[paramName] || PlaceHolders[k]() || "");
208
274
  }
275
+ return replaceEmpty(str);
276
+ }
277
+ function replaceEmpty(content) {
278
+ var reg = /\[.*?\]/g;
279
+ return content.replace(reg, "");
209
280
  }
281
+ var PlaceHolders = __assign(__assign(__assign(__assign(__assign(__assign({}, App), Content), Device), GDPR), Generic), Other);
210
282
 
211
283
  var MacroSubstitution = /** @class */ (function () {
212
284
  function MacroSubstitution() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macro-parameters",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Provide unified macro parameter retrieval",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,22 +43,37 @@ export function getProfileId() {
43
43
  }
44
44
  }
45
45
 
46
- export function setCookie(name, value, expires, path, domain, secure) {
46
+ export function setCookie(
47
+ name: string,
48
+ value: string,
49
+ expires?: any,
50
+ path?: string | undefined,
51
+ domain?: string | undefined,
52
+ secure?: string | undefined) {
47
53
  var cookieString =
48
- name +
49
- "=" +
50
- escape(value) +
51
- (expires ? ";expires=" + expires.toGMTString() : "") +
52
- (path ? ";path=" + path : "") +
53
- (domain ? ";domain=" + domain : "") +
54
- (secure ? ";secure" : "");
54
+ name +
55
+ "=" +
56
+ escape(value) +
57
+ (expires ? ";expires=" + expires.toGMTString() : "") +
58
+ (path ? ";path=" + path : "") +
59
+ (domain ? ";domain=" + domain : "") +
60
+ (secure ? ";secure" : "");
55
61
  document.cookie = cookieString;
56
- }
62
+ }
57
63
 
58
- export function getLocationOrigin() {
64
+ export function getLocationOrigin() {
59
65
  return (
60
66
  location.origin ||
61
67
  `${location.protocol}//${location.host || location.hostname}${location.port
62
68
  }`
63
69
  );
70
+ }
71
+
72
+ export function getExternalMacroParam(name: string): string {
73
+ const externalMacroParam = (window as any).externalMacroParam;
74
+ if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
75
+ return externalMacroParam[name];
76
+ } else {
77
+ return "";
78
+ }
64
79
  }
package/src/replace.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
- getCookie,
3
- getLocalStorage,
4
- getLocationOrigin,
5
- getTvBrand,
6
- getProfileId,
7
- setCookie
8
- } from "../script/utils"
2
+ App,
3
+ Content,
4
+ Device,
5
+ GDPR,
6
+ Generic,
7
+ Other
8
+ } from "../type";
9
9
  export function cleanPlaceholder(str: string, params: object) {
10
10
  for (let k in PlaceHolders) {
11
11
  let param = k.replace('[', '\\[').replace(']', '\\]');
@@ -21,133 +21,16 @@ function replaceEmpty(content: string) {
21
21
  }
22
22
 
23
23
  const PlaceHolders: any = {
24
- "[tv_domain]"() {
25
- return document.domain
26
- },
27
- "[app_name]"() {
28
- return getExternalMacroParam("app_name");
29
- },
30
- "[bundle_id]"() {
31
- return getExternalMacroParam("bundle_id");
32
- },
33
- "[app_store_url]"() {
34
- return getExternalMacroParam("app_store_url");
35
- },
36
- "[src_page_url]"() {
37
- return encodeURIComponent(getLocationOrigin());
38
- },
39
- "[player_height]"() {
40
- return getExternalMacroParam("player_height");
41
- },
42
- "[player_width]"() {
43
- return getExternalMacroParam("player_width");
44
- },
45
- "[channel_no]"() {
46
- return getExternalMacroParam("channel_no");
47
- },
48
- "[channel_category]"() {
49
- return getExternalMacroParam("channel_category");
50
- },
51
- "[whale_ad_id]"() {
52
- // return WhaleADID;
53
- },
54
- "[relevant_ads]"() {
55
- // if (isWhaleOSGlobal) {
56
- // return "true"
57
- // }
58
- var reladvertStatus = false;
59
- var userAgent = navigator.userAgent.toUpperCase();
60
- if (userAgent.indexOf("AOC") > -1) {
61
- reladvertStatus = getCookie("relAdvert");
62
- } else {
63
- reladvertStatus = getCookie("relAdvert");
64
- }
65
-
66
- reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
67
- return reladvertStatus;
68
- },
69
- "[device_dnt]"() {
70
- return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
71
- },
72
- "[tv_brand]"() {
73
- return getTvBrand();
74
- },
75
- "[cntry]"() {
76
- //return countryGlobal;
77
- },
78
- "[geo_ip_country]"() {
79
- //return geoIpCountryGlobal;
80
- },
81
- "[platform_id]"() {
82
- return getProfileId();
83
- },
84
- "[device_user_agent]"() {
85
- const UA = navigator.userAgent;
86
- return encodeURIComponent(UA);
87
- },
88
- "[device_ip_address]"() {
89
- return getExternalMacroParam("device_ip_address");
90
- },
91
- "[menu_language]"() {
92
- const lang = navigator.language;
93
- if (lang) {
94
- return (lang.length > 2) ? lang.slice(0, 2) : lang;
95
- } else {
96
- return 'un';
97
- }
98
- },
99
- "[privacy_policy]"() {
100
- return getExternalMacroParam("privacy_policy");
101
- },
102
- "[whale_gdpr]"() {
103
- return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
104
- },
105
- "[whale_gdpr_consent]"() {
106
- return getCookie("tcString") || getLocalStorage('default_tcString');
107
- },
108
- "[rnd]"() {
109
- return new Date().getTime();
110
- },
111
- "[ad_sdk_ver]"() {
112
- return "";
113
- },
114
- "[time_zone]"() {
115
- return new Date().getTimezoneOffset();
116
- },
117
- "[google_pal]"() {
118
- if (!(window as any).googleNonce && getCookie("googleNonce")) {
119
- return getCookie("googleNonce");
120
- }
121
- if ((window as any).googleNonce) {
122
- setCookie("googleNonce", (window as any).googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
123
- }
124
- return (window as any).googleNonce || '';
125
- },
126
- "[device_lmt]"() {
127
- return getCookie("relAdvert") === 'true' ? 0 : 1
128
- },
129
- "[avod_id]"() {
130
- return ""
131
- },
132
- "[avod_title]"() {
133
- return ""
134
- },
135
- "[device_id]"() {
136
- return getCookie("deviceid") || getCookie("deviceId")
137
- },
138
- "[session_id]"() {
139
- return (window as any).session_id;
140
- },
141
- "[usertag]"() {
142
- return getCookie("usertag")
143
- }
144
- };
145
-
146
- function getExternalMacroParam(name: string): string {
147
- const externalMacroParam = (window as any).externalMacroParam;
148
- if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
149
- return externalMacroParam[name];
150
- } else {
151
- return "";
152
- }
153
- }
24
+ //Type: APP
25
+ ...App,
26
+ //Type: Content
27
+ ...Content,
28
+ //Type: Device
29
+ ...Device,
30
+ //Type: GDPR
31
+ ...GDPR,
32
+ //Type: Generic
33
+ ...Generic,
34
+ //Type: Other
35
+ ...Other
36
+ };
package/type/app.ts ADDED
@@ -0,0 +1,31 @@
1
+ import {
2
+ getExternalMacroParam,
3
+ getLocationOrigin
4
+ } from "../script/utils"
5
+ const App = {
6
+ "[tv_domain]"() {
7
+ return document.domain
8
+ },
9
+ "[app_name]"() {
10
+ return getExternalMacroParam("app_name");
11
+ },
12
+ "[bundle_id]"() {
13
+ return getExternalMacroParam("bundle_id");
14
+ },
15
+ "[app_store_url]"() {
16
+ return getExternalMacroParam("app_store_url");
17
+ },
18
+ "[src_page_url]"() {
19
+ return encodeURIComponent(getLocationOrigin());
20
+ },
21
+ "[player_height]"() {
22
+ return getExternalMacroParam("player_height");
23
+ },
24
+ "[player_width]"() {
25
+ return getExternalMacroParam("player_width");
26
+ },
27
+ "[placement]"() {
28
+ return getExternalMacroParam("placement");
29
+ }
30
+ };
31
+ export { App }
@@ -0,0 +1,38 @@
1
+
2
+ import { getExternalMacroParam } from "../script/utils"
3
+ const Content = {
4
+ "[provider_id]"() {
5
+ return getExternalMacroParam("provider_id");
6
+ },
7
+ "[channel_no]"() {
8
+ return getExternalMacroParam("channel_no");
9
+ },
10
+ "[channel_category]"() {
11
+ return getExternalMacroParam("channel_category");
12
+ },
13
+ "[channel_name]"() {
14
+ return getExternalMacroParam("channel_category");
15
+ },
16
+ "[iab_category]"() {
17
+ return getExternalMacroParam("iab_category");
18
+ },
19
+ "[avod_id]"() {
20
+ return getExternalMacroParam("avod_id");
21
+ },
22
+ "[avod_genre]"() {
23
+ return getExternalMacroParam("avod_genre");
24
+ },
25
+ "[avod_title]"() {
26
+ return getExternalMacroParam("avod_title");
27
+ },
28
+ "[oriented_age]"() {
29
+ return getExternalMacroParam("oriented_age");
30
+ },
31
+ "[oriented_gender]"() {
32
+ return getExternalMacroParam("oriented_gender");
33
+ },
34
+ "[ssai_vendor]"() {
35
+ return getExternalMacroParam("ssai_vendor");
36
+ }
37
+ }
38
+ export { Content }
package/type/device.ts ADDED
@@ -0,0 +1,42 @@
1
+ import {
2
+ getExternalMacroParam,
3
+ getTvBrand,
4
+ getProfileId
5
+ } from "../script/utils"
6
+ const Device = {
7
+ "[whale_ad_id]"() {
8
+ // return WhaleADID;
9
+ },
10
+ "[tv_brand]"() {
11
+ return getTvBrand();
12
+ },
13
+ "[cntry]"() {
14
+ //return countryGlobal;
15
+ },
16
+ "[geo_ip_country]"() {
17
+ //return geoIpCountryGlobal;
18
+ },
19
+ "[platform_id]"() {
20
+ return getProfileId();
21
+ },
22
+ "[device_user_agent]"() {
23
+ const UA = navigator.userAgent;
24
+ return encodeURIComponent(UA);
25
+ },
26
+ "[device_ip_address]"() {
27
+ return getExternalMacroParam("device_ip_address");
28
+ },
29
+ "[menu_language]"() {
30
+ const lang = navigator.language;
31
+ if (lang) {
32
+ return (lang.length > 2) ? lang.slice(0, 2) : lang;
33
+ } else {
34
+ return 'un';
35
+ }
36
+ },
37
+ "[time_zone]"() {
38
+ return new Date().getTimezoneOffset();
39
+ },
40
+ }
41
+
42
+ export { Device }
package/type/gdpr.ts ADDED
@@ -0,0 +1,40 @@
1
+
2
+ import {
3
+ getCookie,
4
+ getExternalMacroParam,
5
+ getLocalStorage
6
+ } from "../script/utils"
7
+ const GDPR = {
8
+ "[whale_gdpr]"() {
9
+ return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
10
+ },
11
+ "[whale_gdpr_consent]"() {
12
+ return getCookie("tcString") || getLocalStorage('default_tcString');
13
+ },
14
+ "[relevant_ads]"() {
15
+ // if (isWhaleOSGlobal) {
16
+ // return "true"
17
+ // }
18
+ let reladvertStatus = "false";
19
+ const userAgent = navigator.userAgent.toUpperCase();
20
+ if (userAgent.indexOf("AOC") > -1) {
21
+ reladvertStatus = getCookie("relAdvert");
22
+ } else {
23
+ reladvertStatus = getCookie("relAdvert");
24
+ }
25
+
26
+ reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
27
+ return reladvertStatus;
28
+ },
29
+ "[device_dnt]"() {
30
+ return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
31
+ },
32
+ "[device_lmt]"() {
33
+ return getCookie("relAdvert") === 'true' ? 0 : 1
34
+ },
35
+ "[privacy_policy]"() {
36
+ return getExternalMacroParam("privacy_policy");
37
+ },
38
+ }
39
+
40
+ export { GDPR }
@@ -0,0 +1,26 @@
1
+ import {
2
+ getCookie,
3
+ setCookie
4
+ } from "../script/utils"
5
+ const Generic = {
6
+ "[rnd]"() {
7
+ return new Date().getTime();
8
+ },
9
+ "[timestamp]"() {
10
+ return new Date().getTime();
11
+ },
12
+ "[ad_sdk_ver]"() {
13
+ return "";
14
+ },
15
+ "[google_pal]"() {
16
+ if (!(window as any).googleNonce && getCookie("googleNonce")) {
17
+ return getCookie("googleNonce");
18
+ }
19
+ if ((window as any).googleNonce) {
20
+ setCookie("googleNonce", (window as any).googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
21
+ }
22
+ return (window as any).googleNonce || '';
23
+ },
24
+ }
25
+
26
+ export { Generic }
package/type/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { App } from "./app"
2
+ import { Content } from "./content"
3
+ import { Device } from "./device"
4
+ import { GDPR } from "./gdpr"
5
+ import { Generic } from "./generic"
6
+ import { Other } from "./other"
7
+
8
+ export {
9
+ App,
10
+ Content,
11
+ Device,
12
+ GDPR,
13
+ Generic,
14
+ Other
15
+ }
package/type/other.ts ADDED
@@ -0,0 +1,15 @@
1
+ //非WhaleAdsMacros定义,但是实际需要用到的参数
2
+ import { getCookie } from "../script/utils"
3
+ const Other = {
4
+ "[device_id]"() {
5
+ return getCookie("deviceid") || getCookie("deviceId")
6
+ },
7
+ "[session_id]"() {
8
+ return (window as any).session_id;
9
+ },
10
+ "[usertag]"() {
11
+ return getCookie("usertag")
12
+ }
13
+ }
14
+
15
+ export { Other }