macro-parameters 0.0.7 → 0.0.8

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 CHANGED
@@ -1,307 +1 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
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 */
16
-
17
-
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
- };
33
-
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);
45
- }
46
- return null;
47
- }
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
- }
100
- }
101
-
102
- var App = {
103
- "[tv_domain]": function () {
104
- return document.domain;
105
- },
106
- "[app_name]": function () {
107
- return getExternalMacroParam("app_name");
108
- },
109
- "[bundle_id]": function () {
110
- return getExternalMacroParam("bundle_id");
111
- },
112
- "[app_store_url]": function () {
113
- return getExternalMacroParam("app_store_url");
114
- },
115
- "[src_page_url]": function () {
116
- return encodeURIComponent(getLocationOrigin());
117
- },
118
- "[player_height]": function () {
119
- return getExternalMacroParam("player_height");
120
- },
121
- "[player_width]": function () {
122
- return getExternalMacroParam("player_width");
123
- },
124
- "[placement]": function () {
125
- return getExternalMacroParam("placement");
126
- }
127
- };
128
-
129
- var Content = {
130
- "[provider_id]": function () {
131
- return getExternalMacroParam("provider_id");
132
- },
133
- "[channel_no]": function () {
134
- return getExternalMacroParam("channel_no");
135
- },
136
- "[channel_category]": function () {
137
- return getExternalMacroParam("channel_category");
138
- },
139
- "[channel_name]": function () {
140
- return getExternalMacroParam("channel_category");
141
- },
142
- "[iab_category]": function () {
143
- return getExternalMacroParam("iab_category");
144
- },
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;
168
- },
169
- "[tv_brand]": function () {
170
- return getTvBrand();
171
- },
172
- "[cntry]": function () {
173
- //return countryGlobal;
174
- },
175
- "[geo_ip_country]": function () {
176
- //return geoIpCountryGlobal;
177
- },
178
- "[platform_id]": function () {
179
- return getProfileId();
180
- },
181
- "[device_user_agent]": function () {
182
- var UA = navigator.userAgent;
183
- return encodeURIComponent(UA);
184
- },
185
- "[device_ip_address]": function () {
186
- return getExternalMacroParam("device_ip_address");
187
- },
188
- "[menu_language]": function () {
189
- var lang = navigator.language;
190
- if (lang) {
191
- return (lang.length > 2) ? lang.slice(0, 2) : lang;
192
- }
193
- else {
194
- return 'un';
195
- }
196
- },
197
- "[time_zone]": function () {
198
- return new Date().getTimezoneOffset();
199
- },
200
- };
201
-
202
- var GDPR = {
203
- "[whale_gdpr]": function () {
204
- return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
205
- },
206
- "[whale_gdpr_consent]": function () {
207
- return getCookie("tcString") || getLocalStorage('default_tcString');
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 = {
236
- "[rnd]": function () {
237
- return new Date().getTime();
238
- },
239
- "[timestamp]": function () {
240
- return new Date().getTime();
241
- },
242
- "[ad_sdk_ver]": function () {
243
- return "";
244
- },
245
- "[google_pal]": function () {
246
- if (!window.googleNonce && getCookie("googleNonce")) {
247
- return getCookie("googleNonce");
248
- }
249
- if (window.googleNonce) {
250
- setCookie("googleNonce", window.googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
251
- }
252
- return window.googleNonce || '';
253
- },
254
- };
255
-
256
- //非WhaleAdsMacros定义,但是实际需要用到的参数
257
- var Other = {
258
- "[device_id]": function () {
259
- return getCookie("deviceid") || getCookie("deviceId");
260
- },
261
- "[session_id]": function () {
262
- return window.session_id;
263
- },
264
- "[usertag]": function () {
265
- return getCookie("usertag");
266
- }
267
- };
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]() || "");
274
- }
275
- return replaceEmpty(str);
276
- }
277
- function replaceEmpty(content) {
278
- var reg = /\[.*?\]/g;
279
- return content.replace(reg, "");
280
- }
281
- var PlaceHolders = __assign(__assign(__assign(__assign(__assign(__assign({}, App), Content), Device), GDPR), Generic), Other);
282
-
283
- var MacroSubstitution = /** @class */ (function () {
284
- function MacroSubstitution() {
285
- this.params = {};
286
- }
287
- MacroSubstitution.prototype.set = function (params) {
288
- if (!params) {
289
- console.log("Invalid settings");
290
- return;
291
- }
292
- for (var key in params) {
293
- if (params.hasOwnProperty(key)) {
294
- console.log(key + ": " + params[key]);
295
- this.params[key] = params[key];
296
- }
297
- }
298
- };
299
- MacroSubstitution.prototype.handle = function (str) {
300
- console.log(cleanPlaceholder(str, this.params));
301
- console.log(this.params);
302
- return cleanPlaceholder(str, this.params);
303
- };
304
- return MacroSubstitution;
305
- }());
306
-
307
- export { MacroSubstitution as default };
1
+ var e=function(){return e=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},e.apply(this,arguments)};function n(e){var n,r=new RegExp("(^| )"+e+"=([^;]*)(;|$)");return(n=(document.cookie||window.localStorage&&window.localStorage.cookie||"").match(r))?unescape(n[2]):""}function r(e){var n=window.externalMacroParam;return n&&"object"==typeof n&&n.hasOwnProperty(e)?n[e]:""}"function"==typeof SuppressedError&&SuppressedError;var t={"[provider_id]":function(){return r("provider_id")},"[channel_no]":function(){return r("channel_no")},"[channel_category]":function(){return r("channel_category")},"[channel_name]":function(){return r("channel_category")},"[iab_category]":function(){return r("iab_category")},"[avod_id]":function(){return r("avod_id")},"[avod_genre]":function(){return r("avod_genre")},"[avod_title]":function(){return r("avod_title")},"[oriented_age]":function(){return r("oriented_age")},"[oriented_gender]":function(){return r("oriented_gender")},"[ssai_vendor]":function(){return r("ssai_vendor")}},o={"[whale_ad_id]":function(){},"[tv_brand]":function(){return function(){if(localStorage.getItem("brand"))return localStorage.getItem("brand");var e=navigator.userAgent.toUpperCase();return e.indexOf("AOC")>-1?"aoc":e.indexOf("PHILIPS")>-1?"philips":"others"}()},"[cntry]":function(){},"[geo_ip_country]":function(){},"[platform_id]":function(){return(e=n("profileid")||n("profileId"))&&""!=e?e.split("_")[1]:"Unknown";var e},"[device_user_agent]":function(){var e=navigator.userAgent;return encodeURIComponent(e)},"[device_ip_address]":function(){return r("device_ip_address")},"[menu_language]":function(){var e=navigator.language;return e?e.length>2?e.slice(0,2):e:"un"},"[time_zone]":function(){return(new Date).getTimezoneOffset()}},i={"[whale_gdpr]":function(){return r("whale_gdpr")||("true"==n("relAdvert")?1:0)},"[whale_gdpr_consent]":function(){return n("tcString")||(e="default_tcString","object"==typeof localStorage?localStorage.getItem(e):null);var e},"[relevant_ads]":function(){var e="false";return e=null==(e=(navigator.userAgent.toUpperCase().indexOf("AOC"),n("relAdvert")))?"false":e},"[device_dnt]":function(){return r("device_dnt")||("true"==n("relAdvert")?0:1)},"[device_lmt]":function(){return"true"===n("relAdvert")?0:1},"[privacy_policy]":function(){return r("privacy_policy")}},a={"[rnd]":function(){return(new Date).getTime()},"[timestamp]":function(){return(new Date).getTime()},"[ad_sdk_ver]":function(){return""},"[google_pal]":function(){return!window.googleNonce&&n("googleNonce")?n("googleNonce"):(window.googleNonce&&(e="googleNonce",r=window.googleNonce,t=new Date((new Date).getTime()+216e5),o=e+"="+escape(r)+(t?";expires="+t.toGMTString():""),document.cookie=o),window.googleNonce||"");var e,r,t,o}},c={"[device_id]":function(){return n("deviceid")||n("deviceId")},"[session_id]":function(){return window.session_id},"[usertag]":function(){return n("usertag")}};function u(e,n){for(var r in l){var t=r.replace("[","\\[").replace("]","\\]"),o=r.replace("[","").replace("]","");e=e.replace(new RegExp(t,"g"),n[o]||l[r]()||"")}return i=/\[.*?\]/g,e.replace(i,"");var i}var l=e(e(e(e(e(e({},{"[tv_domain]":function(){return document.domain},"[app_name]":function(){return r("app_name")},"[bundle_id]":function(){return r("bundle_id")},"[app_store_url]":function(){return r("app_store_url")},"[src_page_url]":function(){return encodeURIComponent(location.origin||"".concat(location.protocol,"//").concat(location.host||location.hostname).concat(location.port))},"[player_height]":function(){return r("player_height")},"[player_width]":function(){return r("player_width")},"[placement]":function(){return r("placement")}}),t),o),i),a),c),d=function(){function e(){this.params={}}return e.prototype.set=function(e){if(e)for(var n in e)e.hasOwnProperty(n)&&(console.log(n+": "+e[n]),this.params[n]=e[n]);else console.log("Invalid settings")},e.prototype.handle=function(e){return console.log(u(e,this.params)),console.log(this.params),u(e,this.params)},e}();export{d as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macro-parameters",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Provide unified macro parameter retrieval",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  "author": "caiyuanjia",
10
10
  "license": "ISC",
11
11
  "devDependencies": {
12
+ "@rollup/plugin-terser": "^0.4.4",
12
13
  "rollup": "^4.21.1",
13
14
  "rollup-plugin-typescript2": "^0.36.0",
14
15
  "typescript": "^5.5.4"
package/rollup.config.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import typescript2 from 'rollup-plugin-typescript2';
2
+ import terser from '@rollup/plugin-terser';
2
3
 
3
4
  export default {
4
5
  input: 'src/main.ts',
@@ -8,6 +9,7 @@ export default {
8
9
  name: 'AdMacro'
9
10
  },
10
11
  plugins: [
11
- typescript2()
12
+ typescript2(),
13
+ terser()
12
14
  ]
13
15
  };