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