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