macro-parameters 0.0.4 → 0.0.6

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,47 +1,101 @@
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
- }
10
-
11
- function getLocalStorage(name) {
12
- if (typeof localStorage === "object") {
13
- return localStorage.getItem(name)
14
- }
15
- return null;
1
+ function getCookie(name) {
2
+ var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
3
+ var arr;
4
+ var source = document.cookie ||
5
+ (window.localStorage && window.localStorage.cookie) ||
6
+ "";
7
+ return (arr = source.match(reg)) ? unescape(arr[2]) : "";
8
+ }
9
+ function getLocalStorage(name) {
10
+ if (typeof localStorage === "object") {
11
+ return localStorage.getItem(name);
12
+ }
13
+ return null;
14
+ }
15
+ function getTvBrand() {
16
+ if (localStorage.getItem("brand")) { //TODO: 处理whaleos的一些特殊情况,后期可以考虑去除
17
+ return localStorage.getItem("brand");
18
+ }
19
+ var userAgent = navigator.userAgent.toUpperCase();
20
+ var _tvBrand = "others";
21
+ if (userAgent.indexOf("AOC") > -1) {
22
+ _tvBrand = "aoc";
23
+ }
24
+ else if (userAgent.indexOf("PHILIPS") > -1) {
25
+ _tvBrand = "philips";
26
+ }
27
+ else {
28
+ _tvBrand = "others";
29
+ }
30
+ return _tvBrand;
31
+ }
32
+ function getProfileId() {
33
+ //Get the profile id from cookie
34
+ var _profileId = getCookie("profileid") || getCookie("profileId");
35
+ var items = [];
36
+ if (_profileId && _profileId != "") {
37
+ // if profile id exists split it with underscore
38
+ items = _profileId.split("_");
39
+ return items[1];
40
+ }
41
+ else {
42
+ return "Unknown";
43
+ }
44
+ }
45
+ function setCookie(name, value, expires, path, domain, secure) {
46
+ var cookieString = name +
47
+ "=" +
48
+ escape(value) +
49
+ (expires ? ";expires=" + expires.toGMTString() : "") +
50
+ ("") +
51
+ ("") +
52
+ ("");
53
+ document.cookie = cookieString;
54
+ }
55
+ function getLocationOrigin() {
56
+ return (location.origin ||
57
+ "".concat(location.protocol, "//").concat(location.host || location.hostname).concat(location.port));
16
58
  }
17
59
 
60
+ function cleanPlaceholder(str, params) {
61
+ for (var k in PlaceHolders) {
62
+ var param = k.replace('[', '\\[').replace(']', '\\]');
63
+ var paramName = k.replace('[', '').replace(']', '');
64
+ str = str.replace(new RegExp(param, 'g'), params[paramName] || PlaceHolders[k]() || "");
65
+ }
66
+ return replaceEmpty(str);
67
+ }
68
+ function replaceEmpty(content) {
69
+ var reg = /\[.*?\]/g;
70
+ return content.replace(reg, "");
71
+ }
18
72
  var PlaceHolders = {
19
73
  "[tv_domain]": function () {
20
74
  return document.domain;
21
75
  },
22
76
  "[app_name]": function () {
23
- return window.externalMacroParam && window.externalMacroParam.app_name;
77
+ return getExternalMacroParam("app_name");
24
78
  },
25
79
  "[bundle_id]": function () {
26
- return window.externalMacroParam && window.externalMacroParam.bundle_id;
80
+ return getExternalMacroParam("bundle_id");
27
81
  },
28
82
  "[app_store_url]": function () {
29
- return window.externalMacroParam && window.externalMacroParam.app_store_url;
83
+ return getExternalMacroParam("app_store_url");
30
84
  },
31
85
  "[src_page_url]": function () {
32
86
  return encodeURIComponent(getLocationOrigin());
33
87
  },
34
88
  "[player_height]": function () {
35
- return window.externalMacroParam && window.externalMacroParam.player_height;
89
+ return getExternalMacroParam("player_height");
36
90
  },
37
91
  "[player_width]": function () {
38
- return window.externalMacroParam && window.externalMacroParam.player_width;
92
+ return getExternalMacroParam("player_width");
39
93
  },
40
94
  "[channel_no]": function () {
41
- return window.externalMacroParam && window.externalMacroParam.channel_no;
95
+ return getExternalMacroParam("channel_no");
42
96
  },
43
97
  "[channel_category]": function () {
44
- return window.externalMacroParam && window.externalMacroParam.channel_category;
98
+ return getExternalMacroParam("channel_category");
45
99
  },
46
100
  "[whale_ad_id]": function () {
47
101
  // return WhaleADID;
@@ -50,21 +104,22 @@ var PlaceHolders = {
50
104
  // if (isWhaleOSGlobal) {
51
105
  // return "true"
52
106
  // }
53
- // var reladvertStatus = false;
54
- // var userAgent = navigator.userAgent.toUpperCase();
55
- // if (userAgent.indexOf("AOC") > -1) {
56
- // reladvertStatus = getCookie("relAdvert");
57
- // } else {
58
- // reladvertStatus = getCookie("relAdvert");
59
- // }
60
- // reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
61
- // return reladvertStatus;
107
+ var reladvertStatus = "false";
108
+ var userAgent = navigator.userAgent.toUpperCase();
109
+ if (userAgent.indexOf("AOC") > -1) {
110
+ reladvertStatus = getCookie("relAdvert");
111
+ }
112
+ else {
113
+ reladvertStatus = getCookie("relAdvert");
114
+ }
115
+ reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
116
+ return reladvertStatus;
62
117
  },
63
118
  "[device_dnt]": function () {
64
- return (window.externalMacroParam && window.externalMacroParam.device_dnt) || (getCookie("relAdvert") == 'true' ? 0 : 1);
119
+ return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
65
120
  },
66
121
  "[tv_brand]": function () {
67
- //return getTvBrand();
122
+ return getTvBrand();
68
123
  },
69
124
  "[cntry]": function () {
70
125
  //return countryGlobal;
@@ -73,27 +128,29 @@ var PlaceHolders = {
73
128
  //return geoIpCountryGlobal;
74
129
  },
75
130
  "[platform_id]": function () {
76
- //return getProfileId();
131
+ return getProfileId();
77
132
  },
78
133
  "[device_user_agent]": function () {
79
134
  var UA = navigator.userAgent;
80
135
  return encodeURIComponent(UA);
81
136
  },
82
137
  "[device_ip_address]": function () {
83
- return window.externalMacroParam && window.externalMacroParam.device_ip_address;
138
+ return getExternalMacroParam("device_ip_address");
84
139
  },
85
140
  "[menu_language]": function () {
86
- // if (langGlobal) {
87
- // return (langGlobal.length > 2) ? langGlobal.slice(0, 2) : langGlobal;
88
- // } else {
89
- // return 'un';
90
- // }
141
+ var lang = navigator.language;
142
+ if (lang) {
143
+ return (lang.length > 2) ? lang.slice(0, 2) : lang;
144
+ }
145
+ else {
146
+ return 'un';
147
+ }
91
148
  },
92
149
  "[privacy_policy]": function () {
93
- return window.externalMacroParam && window.externalMacroParam.privacy_policy;
150
+ return getExternalMacroParam("privacy_policy");
94
151
  },
95
152
  "[whale_gdpr]": function () {
96
- return window.externalMacroParam && window.externalMacroParam.whale_gdpr || (getCookie("relAdvert") == 'true' ? 1 : 0);
153
+ return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
97
154
  },
98
155
  "[whale_gdpr_consent]": function () {
99
156
  return getCookie("tcString") || getLocalStorage('default_tcString');
@@ -102,20 +159,19 @@ var PlaceHolders = {
102
159
  return new Date().getTime();
103
160
  },
104
161
  "[ad_sdk_ver]": function () {
105
- // return ZeasnADVersion;
162
+ return "";
106
163
  },
107
164
  "[time_zone]": function () {
108
165
  return new Date().getTimezoneOffset();
109
166
  },
110
167
  "[google_pal]": function () {
111
- // if (!(window as any).googleNonce && getCookie("googleNonce")) {
112
- // return getCookie("googleNonce");
113
- // }
114
- // if ((window as any).googleNonce) {
115
- // setCookie("googleNonce", (window as any).googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
116
- // }
117
- // return (window as any).googleNonce || '';
118
- return "1";
168
+ if (!window.googleNonce && getCookie("googleNonce")) {
169
+ return getCookie("googleNonce");
170
+ }
171
+ if (window.googleNonce) {
172
+ setCookie("googleNonce", window.googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
173
+ }
174
+ return window.googleNonce || '';
119
175
  },
120
176
  "[device_lmt]": function () {
121
177
  return getCookie("relAdvert") === 'true' ? 0 : 1;
@@ -136,23 +192,19 @@ var PlaceHolders = {
136
192
  return getCookie("usertag");
137
193
  }
138
194
  };
139
- function getLocationOrigin() {
140
- return (location.origin ||
141
- "".concat(location.protocol, "//").concat(location.host || location.hostname).concat(location.port));
142
- }
143
- function cleanPlaceholder(str) {
144
- for (var k in PlaceHolders) {
145
- var param = k.replace('[', '\\[').replace(']', '\\]');
146
- str = str.replace(new RegExp(param, 'g'), PlaceHolders[k]() || "");
195
+ function getExternalMacroParam(name) {
196
+ var externalMacroParam = window.externalMacroParam;
197
+ if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
198
+ return externalMacroParam[name];
199
+ }
200
+ else {
201
+ return "";
147
202
  }
148
- return replaceEmpty(str);
149
- }
150
- function replaceEmpty(content) {
151
- var reg = /\[.*?\]/g;
152
- return content.replace(reg, "");
153
203
  }
204
+
154
205
  var MacroSubstitution = /** @class */ (function () {
155
206
  function MacroSubstitution() {
207
+ this.params = {};
156
208
  }
157
209
  MacroSubstitution.prototype.set = function (params) {
158
210
  if (!params) {
@@ -162,13 +214,14 @@ var MacroSubstitution = /** @class */ (function () {
162
214
  for (var key in params) {
163
215
  if (params.hasOwnProperty(key)) {
164
216
  console.log(key + ": " + params[key]);
165
- this[key] = params[key];
217
+ this.params[key] = params[key];
166
218
  }
167
219
  }
168
220
  };
169
221
  MacroSubstitution.prototype.handle = function (str) {
170
- console.log(cleanPlaceholder(str));
171
- return cleanPlaceholder(str);
222
+ console.log(cleanPlaceholder(str, this.params));
223
+ console.log(this.params);
224
+ return cleanPlaceholder(str, this.params);
172
225
  };
173
226
  return MacroSubstitution;
174
227
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macro-parameters",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Provide unified macro parameter retrieval",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,70 @@
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
+ }
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(
47
+ name: string,
48
+ value: string,
49
+ expires?: any,
50
+ path?: string | undefined,
51
+ domain?: string | undefined,
52
+ secure?: string | undefined) {
53
+ var cookieString =
54
+ name +
55
+ "=" +
56
+ escape(value) +
57
+ (expires ? ";expires=" + expires.toGMTString() : "") +
58
+ (path ? ";path=" + path : "") +
59
+ (domain ? ";domain=" + domain : "") +
60
+ (secure ? ";secure" : "");
61
+ document.cookie = cookieString;
62
+ }
63
+
64
+ export function getLocationOrigin() {
65
+ return (
66
+ location.origin ||
67
+ `${location.protocol}//${location.host || location.hostname}${location.port
68
+ }`
69
+ );
70
+ }
package/src/main.ts CHANGED
@@ -1,148 +1,11 @@
1
- import { getCookie, getLocalStorage } from "../script/utils"
2
- const PlaceHolders: any = {
3
- "[tv_domain]"() {
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
- return cleanPlaceholder(str)
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
+ let reladvertStatus = "false";
59
+ const 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
+ }
package/script/utils.js DELETED
@@ -1,16 +0,0 @@
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
- }