macro-parameters 0.0.4 → 0.0.5
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/index.js +111 -52
- package/package.json +1 -1
- package/script/utils.js +48 -0
- package/src/main.ts +9 -145
- package/src/replace.ts +153 -0
package/index.js
CHANGED
|
@@ -13,35 +13,95 @@ function getLocalStorage(name) {
|
|
|
13
13
|
return localStorage.getItem(name)
|
|
14
14
|
}
|
|
15
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
|
+
}
|
|
32
|
+
|
|
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
|
+
}
|
|
45
|
+
|
|
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
|
+
|
|
58
|
+
function getLocationOrigin() {
|
|
59
|
+
return (
|
|
60
|
+
location.origin ||
|
|
61
|
+
`${location.protocol}//${location.host || location.hostname}${location.port
|
|
62
|
+
}`
|
|
63
|
+
);
|
|
16
64
|
}
|
|
17
65
|
|
|
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]() || "");
|
|
71
|
+
}
|
|
72
|
+
return replaceEmpty(str);
|
|
73
|
+
}
|
|
74
|
+
function replaceEmpty(content) {
|
|
75
|
+
var reg = /\[.*?\]/g;
|
|
76
|
+
return content.replace(reg, "");
|
|
77
|
+
}
|
|
18
78
|
var PlaceHolders = {
|
|
19
79
|
"[tv_domain]": function () {
|
|
20
80
|
return document.domain;
|
|
21
81
|
},
|
|
22
82
|
"[app_name]": function () {
|
|
23
|
-
return
|
|
83
|
+
return getExternalMacroParam("app_name");
|
|
24
84
|
},
|
|
25
85
|
"[bundle_id]": function () {
|
|
26
|
-
return
|
|
86
|
+
return getExternalMacroParam("bundle_id");
|
|
27
87
|
},
|
|
28
88
|
"[app_store_url]": function () {
|
|
29
|
-
return
|
|
89
|
+
return getExternalMacroParam("app_store_url");
|
|
30
90
|
},
|
|
31
91
|
"[src_page_url]": function () {
|
|
32
92
|
return encodeURIComponent(getLocationOrigin());
|
|
33
93
|
},
|
|
34
94
|
"[player_height]": function () {
|
|
35
|
-
return
|
|
95
|
+
return getExternalMacroParam("player_height");
|
|
36
96
|
},
|
|
37
97
|
"[player_width]": function () {
|
|
38
|
-
return
|
|
98
|
+
return getExternalMacroParam("player_width");
|
|
39
99
|
},
|
|
40
100
|
"[channel_no]": function () {
|
|
41
|
-
return
|
|
101
|
+
return getExternalMacroParam("channel_no");
|
|
42
102
|
},
|
|
43
103
|
"[channel_category]": function () {
|
|
44
|
-
return
|
|
104
|
+
return getExternalMacroParam("channel_category");
|
|
45
105
|
},
|
|
46
106
|
"[whale_ad_id]": function () {
|
|
47
107
|
// return WhaleADID;
|
|
@@ -50,21 +110,22 @@ var PlaceHolders = {
|
|
|
50
110
|
// if (isWhaleOSGlobal) {
|
|
51
111
|
// return "true"
|
|
52
112
|
// }
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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;
|
|
62
123
|
},
|
|
63
124
|
"[device_dnt]": function () {
|
|
64
|
-
return (
|
|
125
|
+
return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
|
|
65
126
|
},
|
|
66
127
|
"[tv_brand]": function () {
|
|
67
|
-
|
|
128
|
+
return getTvBrand();
|
|
68
129
|
},
|
|
69
130
|
"[cntry]": function () {
|
|
70
131
|
//return countryGlobal;
|
|
@@ -73,27 +134,29 @@ var PlaceHolders = {
|
|
|
73
134
|
//return geoIpCountryGlobal;
|
|
74
135
|
},
|
|
75
136
|
"[platform_id]": function () {
|
|
76
|
-
|
|
137
|
+
return getProfileId();
|
|
77
138
|
},
|
|
78
139
|
"[device_user_agent]": function () {
|
|
79
140
|
var UA = navigator.userAgent;
|
|
80
141
|
return encodeURIComponent(UA);
|
|
81
142
|
},
|
|
82
143
|
"[device_ip_address]": function () {
|
|
83
|
-
return
|
|
144
|
+
return getExternalMacroParam("device_ip_address");
|
|
84
145
|
},
|
|
85
146
|
"[menu_language]": function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
147
|
+
var lang = navigator.language;
|
|
148
|
+
if (lang) {
|
|
149
|
+
return (lang.length > 2) ? lang.slice(0, 2) : lang;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return 'un';
|
|
153
|
+
}
|
|
91
154
|
},
|
|
92
155
|
"[privacy_policy]": function () {
|
|
93
|
-
return
|
|
156
|
+
return getExternalMacroParam("privacy_policy");
|
|
94
157
|
},
|
|
95
158
|
"[whale_gdpr]": function () {
|
|
96
|
-
return
|
|
159
|
+
return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
|
|
97
160
|
},
|
|
98
161
|
"[whale_gdpr_consent]": function () {
|
|
99
162
|
return getCookie("tcString") || getLocalStorage('default_tcString');
|
|
@@ -102,20 +165,19 @@ var PlaceHolders = {
|
|
|
102
165
|
return new Date().getTime();
|
|
103
166
|
},
|
|
104
167
|
"[ad_sdk_ver]": function () {
|
|
105
|
-
|
|
168
|
+
return "";
|
|
106
169
|
},
|
|
107
170
|
"[time_zone]": function () {
|
|
108
171
|
return new Date().getTimezoneOffset();
|
|
109
172
|
},
|
|
110
173
|
"[google_pal]": function () {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return "1";
|
|
174
|
+
if (!window.googleNonce && getCookie("googleNonce")) {
|
|
175
|
+
return getCookie("googleNonce");
|
|
176
|
+
}
|
|
177
|
+
if (window.googleNonce) {
|
|
178
|
+
setCookie("googleNonce", window.googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
|
|
179
|
+
}
|
|
180
|
+
return window.googleNonce || '';
|
|
119
181
|
},
|
|
120
182
|
"[device_lmt]": function () {
|
|
121
183
|
return getCookie("relAdvert") === 'true' ? 0 : 1;
|
|
@@ -136,23 +198,19 @@ var PlaceHolders = {
|
|
|
136
198
|
return getCookie("usertag");
|
|
137
199
|
}
|
|
138
200
|
};
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
str = str.replace(new RegExp(param, 'g'), PlaceHolders[k]() || "");
|
|
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 "";
|
|
147
208
|
}
|
|
148
|
-
return replaceEmpty(str);
|
|
149
|
-
}
|
|
150
|
-
function replaceEmpty(content) {
|
|
151
|
-
var reg = /\[.*?\]/g;
|
|
152
|
-
return content.replace(reg, "");
|
|
153
209
|
}
|
|
210
|
+
|
|
154
211
|
var MacroSubstitution = /** @class */ (function () {
|
|
155
212
|
function MacroSubstitution() {
|
|
213
|
+
this.params = {};
|
|
156
214
|
}
|
|
157
215
|
MacroSubstitution.prototype.set = function (params) {
|
|
158
216
|
if (!params) {
|
|
@@ -162,13 +220,14 @@ var MacroSubstitution = /** @class */ (function () {
|
|
|
162
220
|
for (var key in params) {
|
|
163
221
|
if (params.hasOwnProperty(key)) {
|
|
164
222
|
console.log(key + ": " + params[key]);
|
|
165
|
-
this[key] = params[key];
|
|
223
|
+
this.params[key] = params[key];
|
|
166
224
|
}
|
|
167
225
|
}
|
|
168
226
|
};
|
|
169
227
|
MacroSubstitution.prototype.handle = function (str) {
|
|
170
|
-
console.log(cleanPlaceholder(str));
|
|
171
|
-
|
|
228
|
+
console.log(cleanPlaceholder(str, this.params));
|
|
229
|
+
console.log(this.params);
|
|
230
|
+
return cleanPlaceholder(str, this.params);
|
|
172
231
|
};
|
|
173
232
|
return MacroSubstitution;
|
|
174
233
|
}());
|
package/package.json
CHANGED
package/script/utils.js
CHANGED
|
@@ -14,3 +14,51 @@ export function getLocalStorage(name) {
|
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
+
export 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
|
+
}
|
|
32
|
+
|
|
33
|
+
export 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
|
+
}
|
|
45
|
+
|
|
46
|
+
export function setCookie(name, value, expires, path, domain, secure) {
|
|
47
|
+
var cookieString =
|
|
48
|
+
name +
|
|
49
|
+
"=" +
|
|
50
|
+
escape(value) +
|
|
51
|
+
(expires ? ";expires=" + expires.toGMTString() : "") +
|
|
52
|
+
(path ? ";path=" + path : "") +
|
|
53
|
+
(domain ? ";domain=" + domain : "") +
|
|
54
|
+
(secure ? ";secure" : "");
|
|
55
|
+
document.cookie = cookieString;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getLocationOrigin() {
|
|
59
|
+
return (
|
|
60
|
+
location.origin ||
|
|
61
|
+
`${location.protocol}//${location.host || location.hostname}${location.port
|
|
62
|
+
}`
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/main.ts
CHANGED
|
@@ -1,148 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return document.domain
|
|
5
|
-
},
|
|
6
|
-
"[app_name]"() {
|
|
7
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.app_name;
|
|
8
|
-
},
|
|
9
|
-
"[bundle_id]"() {
|
|
10
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.bundle_id;
|
|
11
|
-
},
|
|
12
|
-
"[app_store_url]"() {
|
|
13
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.app_store_url;
|
|
14
|
-
},
|
|
15
|
-
"[src_page_url]"() {
|
|
16
|
-
return encodeURIComponent(getLocationOrigin());
|
|
17
|
-
},
|
|
18
|
-
"[player_height]"() {
|
|
19
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.player_height;
|
|
20
|
-
},
|
|
21
|
-
"[player_width]"() {
|
|
22
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.player_width;
|
|
23
|
-
},
|
|
24
|
-
"[channel_no]"() {
|
|
25
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.channel_no;
|
|
26
|
-
},
|
|
27
|
-
"[channel_category]"() {
|
|
28
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.channel_category;
|
|
29
|
-
},
|
|
30
|
-
"[whale_ad_id]"() {
|
|
31
|
-
// return WhaleADID;
|
|
32
|
-
},
|
|
33
|
-
"[relevant_ads]"() {
|
|
34
|
-
// if (isWhaleOSGlobal) {
|
|
35
|
-
// return "true"
|
|
36
|
-
// }
|
|
37
|
-
// var reladvertStatus = false;
|
|
38
|
-
// var userAgent = navigator.userAgent.toUpperCase();
|
|
39
|
-
// if (userAgent.indexOf("AOC") > -1) {
|
|
40
|
-
// reladvertStatus = getCookie("relAdvert");
|
|
41
|
-
// } else {
|
|
42
|
-
// reladvertStatus = getCookie("relAdvert");
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
|
|
46
|
-
// return reladvertStatus;
|
|
47
|
-
},
|
|
48
|
-
"[device_dnt]"() {
|
|
49
|
-
return ((window as any).externalMacroParam && (window as any).externalMacroParam.device_dnt) || (getCookie("relAdvert") == 'true' ? 0 : 1);
|
|
50
|
-
},
|
|
51
|
-
"[tv_brand]"() {
|
|
52
|
-
//return getTvBrand();
|
|
53
|
-
},
|
|
54
|
-
"[cntry]"() {
|
|
55
|
-
//return countryGlobal;
|
|
56
|
-
},
|
|
57
|
-
"[geo_ip_country]"() {
|
|
58
|
-
//return geoIpCountryGlobal;
|
|
59
|
-
},
|
|
60
|
-
"[platform_id]"() {
|
|
61
|
-
//return getProfileId();
|
|
62
|
-
},
|
|
63
|
-
"[device_user_agent]"() {
|
|
64
|
-
const UA = navigator.userAgent;
|
|
65
|
-
return encodeURIComponent(UA);
|
|
66
|
-
},
|
|
67
|
-
"[device_ip_address]"() {
|
|
68
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.device_ip_address;
|
|
69
|
-
},
|
|
70
|
-
"[menu_language]"() {
|
|
71
|
-
// if (langGlobal) {
|
|
72
|
-
// return (langGlobal.length > 2) ? langGlobal.slice(0, 2) : langGlobal;
|
|
73
|
-
// } else {
|
|
74
|
-
// return 'un';
|
|
75
|
-
// }
|
|
76
|
-
},
|
|
77
|
-
"[privacy_policy]"() {
|
|
78
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.privacy_policy;
|
|
79
|
-
},
|
|
80
|
-
"[whale_gdpr]"() {
|
|
81
|
-
return (window as any).externalMacroParam && (window as any).externalMacroParam.whale_gdpr || (getCookie("relAdvert") == 'true' ? 1 : 0);
|
|
82
|
-
},
|
|
83
|
-
"[whale_gdpr_consent]"() {
|
|
84
|
-
return getCookie("tcString") || getLocalStorage('default_tcString');
|
|
85
|
-
},
|
|
86
|
-
"[rnd]"() {
|
|
87
|
-
return new Date().getTime();
|
|
88
|
-
},
|
|
89
|
-
"[ad_sdk_ver]"() {
|
|
90
|
-
// return ZeasnADVersion;
|
|
91
|
-
},
|
|
92
|
-
"[time_zone]"() {
|
|
93
|
-
return new Date().getTimezoneOffset();
|
|
94
|
-
},
|
|
95
|
-
"[google_pal]"() {
|
|
96
|
-
// if (!(window as any).googleNonce && getCookie("googleNonce")) {
|
|
97
|
-
// return getCookie("googleNonce");
|
|
98
|
-
// }
|
|
99
|
-
// if ((window as any).googleNonce) {
|
|
100
|
-
// setCookie("googleNonce", (window as any).googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
|
|
101
|
-
// }
|
|
102
|
-
// return (window as any).googleNonce || '';
|
|
103
|
-
return "1";
|
|
104
|
-
},
|
|
105
|
-
"[device_lmt]"() {
|
|
106
|
-
return getCookie("relAdvert") === 'true' ? 0 : 1
|
|
107
|
-
},
|
|
108
|
-
"[avod_id]"() {
|
|
109
|
-
return ""
|
|
110
|
-
},
|
|
111
|
-
"[avod_title]"() {
|
|
112
|
-
return ""
|
|
113
|
-
},
|
|
114
|
-
"[device_id]"() {
|
|
115
|
-
return getCookie("deviceid") || getCookie("deviceId")
|
|
116
|
-
},
|
|
117
|
-
"[session_id]"() {
|
|
118
|
-
return (window as any).session_id;
|
|
119
|
-
},
|
|
120
|
-
"[usertag]"() {
|
|
121
|
-
return getCookie("usertag")
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
function getLocationOrigin() {
|
|
125
|
-
return (
|
|
126
|
-
location.origin ||
|
|
127
|
-
`${location.protocol}//${location.host || location.hostname}${location.port
|
|
128
|
-
}`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
function cleanPlaceholder(str: string) {
|
|
132
|
-
for (let k in PlaceHolders) {
|
|
133
|
-
let param = k.replace('[', '\\[').replace(']', '\\]');
|
|
134
|
-
str = str.replace(new RegExp(param, 'g'), PlaceHolders[k]() || "");
|
|
135
|
-
}
|
|
136
|
-
return replaceEmpty(str);
|
|
137
|
-
}
|
|
138
|
-
function replaceEmpty(content: string) {
|
|
139
|
-
const reg = /\[.*?\]/g;
|
|
140
|
-
return content.replace(reg, "")
|
|
141
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
cleanPlaceholder
|
|
3
|
+
} from "./replace"
|
|
142
4
|
|
|
143
5
|
class MacroSubstitution {
|
|
6
|
+
params: object
|
|
144
7
|
constructor() {
|
|
145
|
-
|
|
8
|
+
this.params = {}
|
|
146
9
|
}
|
|
147
10
|
|
|
148
11
|
set(params: object) {
|
|
@@ -153,14 +16,15 @@ class MacroSubstitution {
|
|
|
153
16
|
for (let key in params) {
|
|
154
17
|
if (params.hasOwnProperty(key)) {
|
|
155
18
|
console.log(key + ": " + params[key]);
|
|
156
|
-
this[key] = params[key];
|
|
19
|
+
this.params[key] = params[key];
|
|
157
20
|
}
|
|
158
21
|
}
|
|
159
22
|
}
|
|
160
23
|
|
|
161
24
|
handle(str: string) {
|
|
162
|
-
console.log(cleanPlaceholder(str));
|
|
163
|
-
|
|
25
|
+
console.log(cleanPlaceholder(str, this.params));
|
|
26
|
+
console.log(this.params)
|
|
27
|
+
return cleanPlaceholder(str, this.params)
|
|
164
28
|
}
|
|
165
29
|
|
|
166
30
|
}
|
package/src/replace.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCookie,
|
|
3
|
+
getLocalStorage,
|
|
4
|
+
getLocationOrigin,
|
|
5
|
+
getTvBrand,
|
|
6
|
+
getProfileId,
|
|
7
|
+
setCookie
|
|
8
|
+
} from "../script/utils"
|
|
9
|
+
export function cleanPlaceholder(str: string, params: object) {
|
|
10
|
+
for (let k in PlaceHolders) {
|
|
11
|
+
let param = k.replace('[', '\\[').replace(']', '\\]');
|
|
12
|
+
let paramName = k.replace('[', '').replace(']', '');
|
|
13
|
+
str = str.replace(new RegExp(param, 'g'), params[paramName] || PlaceHolders[k]() || "");
|
|
14
|
+
}
|
|
15
|
+
return replaceEmpty(str);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function replaceEmpty(content: string) {
|
|
19
|
+
const reg = /\[.*?\]/g;
|
|
20
|
+
return content.replace(reg, "")
|
|
21
|
+
}
|
|
22
|
+
|
|
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
|
+
}
|