macro-parameters 0.0.10 → 0.1.0
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 +1 -1
- package/package.json +1 -1
- package/script/utils.ts +0 -79
- package/src/main.ts +0 -30
- package/src/replace.ts +0 -36
- package/type/app.ts +0 -34
- package/type/content.ts +0 -38
- package/type/device.ts +0 -42
- package/type/gdpr.ts +0 -40
- package/type/generic.ts +0 -26
- package/type/index.ts +0 -15
- package/type/other.ts +0 -15
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e=function(){return e=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++)for(var r in n=arguments[t])Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r]);return e},e.apply(this,arguments)};function n(e){var n,t=new RegExp("(^| )"+e+"=([^;]*)(;|$)");return(n=(document.cookie||window.localStorage&&window.localStorage.cookie||"").match(t))?unescape(n[2]):""}function t(e){return"object"==typeof localStorage?localStorage.getItem(e):null}function o(e,n,t,o,r,a){var i=e+"="+escape(n)+(t?";expires="+t.toGMTString():"");document.cookie=i}function r(e){var n=window.externalMacroParam;return n&&"object"==typeof n&&n.hasOwnProperty(e)?n[e]:""}function a(){var e=n("WhaleADID");return null!=e&&""!=e&&null!=e&&e&&e.match(/-/g)&&4==e.match(/-/g).length?o("WhaleADID",e,new Date((new Date).getTime()+31536e6)):o("WhaleADID",e=function(){function e(e){var n=(Math.random().toString(16)+"000000000").substr(2,8);return e?"-"+n.substr(0,4)+"-"+n.substr(4,4):n}return e()+e(!0)+e(!0)+e()}(),new Date((new Date).getTime()+31536e6)),e}"function"==typeof SuppressedError&&SuppressedError;var i={"[whale_ad_id]":function(){return a()},"[tv_brand]":function(){return function(){if(localStorage.getItem("brand"))return localStorage.getItem("brand");var e="others",n=navigator.userAgent.toLocaleLowerCase(),t=n.indexOf("titanos")>-1,o=n.indexOf("aoc")>-1,r=n.indexOf("philips")>-1,a=n.indexOf("tcl")>-1||n.indexOf("tbrowser")>-1,i=n.indexOf("moka")>-1,c=n.indexOf("skw")>-1,u=n.indexOf("tizen")>-1||n.indexOf("samsung")>-1||n.indexOf("smarthub")>-1,l=n.indexOf("webos")>-1||n.indexOf("lg")>-1||n.indexOf("web0s")>-1||n.indexOf("netcast")>-1,s=n.indexOf("vstvb")>-1;switch(!0){case t:e="Philips";break;case o:e="AOC";break;case r:e="Philips";break;case a:e="TCL";break;case i:e="MOKA";break;case c:e="Skyworth";break;case u:e="Samsung";break;case l:e="LG";break;case s:e="Vestel"}return e}()},"[cntry]":function(){return t("macro_cntry")},"[geo_ip_country]":function(){return t("macro_cntry")},"[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()}},c={"[whale_gdpr]":function(){return r("whale_gdpr")||("true"==n("relAdvert")?1:0)},"[whale_gdpr_consent]":function(){return n("tcString")||t("default_tcString")},"[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(){}},u={"[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&&o("googleNonce",window.googleNonce,new Date((new Date).getTime()+216e5)),window.googleNonce||"")}},l={"[device_id]":function(){return n("deviceid")||n("deviceId")},"[session_id]":function(){return window.session_id},"[usertag]":function(){return n("usertag")}};var s=e(e(e(e(e(e({},{"[tv_domain]":function(){return document.domain},"[app_name]":function(){},"[bundle_id]":function(){},"[app_store_url]":function(){},"[src_page_url]":function(){return encodeURIComponent(location.origin||"".concat(location.protocol,"//").concat(location.host||location.hostname).concat(location.port))},"[player_height]":function(){},"[player_width]":function(){},"[placement]":function(){},"[app_store]":function(){return r("app_store")||"Zeasn"}}),{"[provider_id]":function(){},"[channel_no]":function(){},"[channel_category]":function(){},"[channel_name]":function(){},"[iab_category]":function(){},"[avod_id]":function(){},"[avod_genre]":function(){},"[avod_title]":function(){},"[oriented_age]":function(){},"[oriented_gender]":function(){},"[ssai_vendor]":function(){}}),i),c),u),l),d=function(){function e(){var e,n,t;this.params={},e="https://ipapi.zeasn.com/ipapi/location",n=function(e){var n,t,o=e.iso_code;n="macro_cntry",t=o,"object"==typeof localStorage&&localStorage.setItem(n,t)},t=document.createElement("script"),window.zeasnIpapiCallback=function(e){n(e),document.body.removeChild(t)},t.src="".concat(e,"?callback=zeasnIpapiCallback"),document.body.appendChild(t)}return e.prototype.set=function(e){if(e)for(var n in e)e.hasOwnProperty(n)&&(this.params[n]=e[n]);else console.log("Invalid settings")},e.prototype.handle=function(e){return function(e,n){for(var t in s){var o=t.replace("[","\\[").replace("]","\\]"),r=t.replace("[","").replace("]","");e=e.replace(new RegExp(o,"g"),n[r]||s[t]()||"")}return a=/\[.*?\]/g,e.replace(a,"");var a}(e,this.params)},e}();export{d as MacroSubstitution};
|
package/package.json
CHANGED
package/script/utils.ts
DELETED
|
@@ -1,79 +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
|
-
}
|
|
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
|
-
}
|
|
71
|
-
|
|
72
|
-
export function getExternalMacroParam(name: string): string {
|
|
73
|
-
const externalMacroParam = (window as any).externalMacroParam;
|
|
74
|
-
if (externalMacroParam && typeof externalMacroParam === "object" && externalMacroParam.hasOwnProperty(name)) {
|
|
75
|
-
return externalMacroParam[name];
|
|
76
|
-
} else {
|
|
77
|
-
return "";
|
|
78
|
-
}
|
|
79
|
-
}
|
package/src/main.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cleanPlaceholder
|
|
3
|
-
} from "./replace"
|
|
4
|
-
|
|
5
|
-
class MacroSubstitution {
|
|
6
|
-
params: object
|
|
7
|
-
constructor() {
|
|
8
|
-
this.params = {}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
set(params: object): void {
|
|
12
|
-
if (!params) {
|
|
13
|
-
console.log("Invalid settings");
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
for (let key in params) {
|
|
17
|
-
if (params.hasOwnProperty(key)) {
|
|
18
|
-
this.params[key] = params[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
handle(str: string): string {
|
|
24
|
-
return cleanPlaceholder(str, this.params)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
export {
|
|
29
|
-
MacroSubstitution
|
|
30
|
-
}
|
package/src/replace.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
App,
|
|
3
|
-
Content,
|
|
4
|
-
Device,
|
|
5
|
-
GDPR,
|
|
6
|
-
Generic,
|
|
7
|
-
Other
|
|
8
|
-
} from "../type";
|
|
9
|
-
export function cleanPlaceholder(str: string, params: object): string {
|
|
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): string {
|
|
19
|
-
const reg = /\[.*?\]/g;
|
|
20
|
-
return content.replace(reg, "")
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const PlaceHolders: any = {
|
|
24
|
-
//Type: APP
|
|
25
|
-
...App,
|
|
26
|
-
//Type: Content
|
|
27
|
-
...Content,
|
|
28
|
-
//Type: Device
|
|
29
|
-
...Device,
|
|
30
|
-
//Type: GDPR
|
|
31
|
-
...GDPR,
|
|
32
|
-
//Type: Generic
|
|
33
|
-
...Generic,
|
|
34
|
-
//Type: Other
|
|
35
|
-
...Other
|
|
36
|
-
};
|
package/type/app.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getExternalMacroParam,
|
|
3
|
-
getLocationOrigin
|
|
4
|
-
} from "../script/utils"
|
|
5
|
-
const App = {
|
|
6
|
-
"[tv_domain]"() {
|
|
7
|
-
return document.domain
|
|
8
|
-
},
|
|
9
|
-
"[app_name]"() {
|
|
10
|
-
// return getExternalMacroParam("app_name");
|
|
11
|
-
},
|
|
12
|
-
"[bundle_id]"() {
|
|
13
|
-
// return getExternalMacroParam("bundle_id");
|
|
14
|
-
},
|
|
15
|
-
"[app_store_url]"() {
|
|
16
|
-
// return getExternalMacroParam("app_store_url");
|
|
17
|
-
},
|
|
18
|
-
"[src_page_url]"() {
|
|
19
|
-
return encodeURIComponent(getLocationOrigin());
|
|
20
|
-
},
|
|
21
|
-
"[player_height]"() {
|
|
22
|
-
// return getExternalMacroParam("player_height");
|
|
23
|
-
},
|
|
24
|
-
"[player_width]"() {
|
|
25
|
-
// return getExternalMacroParam("player_width");
|
|
26
|
-
},
|
|
27
|
-
"[placement]"() {
|
|
28
|
-
// return getExternalMacroParam("placement");
|
|
29
|
-
},
|
|
30
|
-
"[app_store]"(){
|
|
31
|
-
return getExternalMacroParam("app_store") || "Zeasn";
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export { App }
|
package/type/content.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { getExternalMacroParam } from "../script/utils"
|
|
3
|
-
const Content = {
|
|
4
|
-
"[provider_id]"() {
|
|
5
|
-
// return getExternalMacroParam("provider_id");
|
|
6
|
-
},
|
|
7
|
-
"[channel_no]"() {
|
|
8
|
-
// return getExternalMacroParam("channel_no");
|
|
9
|
-
},
|
|
10
|
-
"[channel_category]"() {
|
|
11
|
-
// return getExternalMacroParam("channel_category");
|
|
12
|
-
},
|
|
13
|
-
"[channel_name]"() {
|
|
14
|
-
// return getExternalMacroParam("channel_category");
|
|
15
|
-
},
|
|
16
|
-
"[iab_category]"() {
|
|
17
|
-
// return getExternalMacroParam("iab_category");
|
|
18
|
-
},
|
|
19
|
-
"[avod_id]"() {
|
|
20
|
-
// return getExternalMacroParam("avod_id");
|
|
21
|
-
},
|
|
22
|
-
"[avod_genre]"() {
|
|
23
|
-
// return getExternalMacroParam("avod_genre");
|
|
24
|
-
},
|
|
25
|
-
"[avod_title]"() {
|
|
26
|
-
// return getExternalMacroParam("avod_title");
|
|
27
|
-
},
|
|
28
|
-
"[oriented_age]"() {
|
|
29
|
-
// return getExternalMacroParam("oriented_age");
|
|
30
|
-
},
|
|
31
|
-
"[oriented_gender]"() {
|
|
32
|
-
// return getExternalMacroParam("oriented_gender");
|
|
33
|
-
},
|
|
34
|
-
"[ssai_vendor]"() {
|
|
35
|
-
// return getExternalMacroParam("ssai_vendor");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export { Content }
|
package/type/device.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getExternalMacroParam,
|
|
3
|
-
getTvBrand,
|
|
4
|
-
getProfileId
|
|
5
|
-
} from "../script/utils"
|
|
6
|
-
const Device = {
|
|
7
|
-
"[whale_ad_id]"() {
|
|
8
|
-
// return WhaleADID;
|
|
9
|
-
},
|
|
10
|
-
"[tv_brand]"() {
|
|
11
|
-
return getTvBrand();
|
|
12
|
-
},
|
|
13
|
-
"[cntry]"() {
|
|
14
|
-
//return countryGlobal;
|
|
15
|
-
},
|
|
16
|
-
"[geo_ip_country]"() {
|
|
17
|
-
//return geoIpCountryGlobal;
|
|
18
|
-
},
|
|
19
|
-
"[platform_id]"() {
|
|
20
|
-
return getProfileId();
|
|
21
|
-
},
|
|
22
|
-
"[device_user_agent]"() {
|
|
23
|
-
const UA = navigator.userAgent;
|
|
24
|
-
return encodeURIComponent(UA);
|
|
25
|
-
},
|
|
26
|
-
"[device_ip_address]"() {
|
|
27
|
-
return getExternalMacroParam("device_ip_address");
|
|
28
|
-
},
|
|
29
|
-
"[menu_language]"() {
|
|
30
|
-
const lang = navigator.language;
|
|
31
|
-
if (lang) {
|
|
32
|
-
return (lang.length > 2) ? lang.slice(0, 2) : lang;
|
|
33
|
-
} else {
|
|
34
|
-
return 'un';
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"[time_zone]"() {
|
|
38
|
-
return new Date().getTimezoneOffset();
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { Device }
|
package/type/gdpr.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
getCookie,
|
|
4
|
-
getExternalMacroParam,
|
|
5
|
-
getLocalStorage
|
|
6
|
-
} from "../script/utils"
|
|
7
|
-
const GDPR = {
|
|
8
|
-
"[whale_gdpr]"() {
|
|
9
|
-
return getExternalMacroParam("whale_gdpr") || (getCookie("relAdvert") == 'true' ? 1 : 0);
|
|
10
|
-
},
|
|
11
|
-
"[whale_gdpr_consent]"() {
|
|
12
|
-
return getCookie("tcString") || getLocalStorage('default_tcString');
|
|
13
|
-
},
|
|
14
|
-
"[relevant_ads]"() {
|
|
15
|
-
// if (isWhaleOSGlobal) {
|
|
16
|
-
// return "true"
|
|
17
|
-
// }
|
|
18
|
-
let reladvertStatus = "false";
|
|
19
|
-
const userAgent = navigator.userAgent.toUpperCase();
|
|
20
|
-
if (userAgent.indexOf("AOC") > -1) {
|
|
21
|
-
reladvertStatus = getCookie("relAdvert");
|
|
22
|
-
} else {
|
|
23
|
-
reladvertStatus = getCookie("relAdvert");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
|
|
27
|
-
return reladvertStatus;
|
|
28
|
-
},
|
|
29
|
-
"[device_dnt]"() {
|
|
30
|
-
return getExternalMacroParam("device_dnt") || (getCookie("relAdvert") == 'true' ? 0 : 1);
|
|
31
|
-
},
|
|
32
|
-
"[device_lmt]"() {
|
|
33
|
-
return getCookie("relAdvert") === 'true' ? 0 : 1
|
|
34
|
-
},
|
|
35
|
-
"[privacy_policy]"() {
|
|
36
|
-
// return getExternalMacroParam("privacy_policy");
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { GDPR }
|
package/type/generic.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCookie,
|
|
3
|
-
setCookie
|
|
4
|
-
} from "../script/utils"
|
|
5
|
-
const Generic = {
|
|
6
|
-
"[rnd]"() {
|
|
7
|
-
return new Date().getTime();
|
|
8
|
-
},
|
|
9
|
-
"[timestamp]"() {
|
|
10
|
-
return new Date().getTime();
|
|
11
|
-
},
|
|
12
|
-
"[ad_sdk_ver]"() {
|
|
13
|
-
return "";
|
|
14
|
-
},
|
|
15
|
-
"[google_pal]"() {
|
|
16
|
-
if (!(window as any).googleNonce && getCookie("googleNonce")) {
|
|
17
|
-
return getCookie("googleNonce");
|
|
18
|
-
}
|
|
19
|
-
if ((window as any).googleNonce) {
|
|
20
|
-
setCookie("googleNonce", (window as any).googleNonce, new Date(new Date().getTime() + 6 * 60 * 60 * 1000));
|
|
21
|
-
}
|
|
22
|
-
return (window as any).googleNonce || '';
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { Generic }
|
package/type/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { App } from "./app"
|
|
2
|
-
import { Content } from "./content"
|
|
3
|
-
import { Device } from "./device"
|
|
4
|
-
import { GDPR } from "./gdpr"
|
|
5
|
-
import { Generic } from "./generic"
|
|
6
|
-
import { Other } from "./other"
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
App,
|
|
10
|
-
Content,
|
|
11
|
-
Device,
|
|
12
|
-
GDPR,
|
|
13
|
-
Generic,
|
|
14
|
-
Other
|
|
15
|
-
}
|
package/type/other.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//非WhaleAdsMacros定义,但是实际需要用到的参数
|
|
2
|
-
import { getCookie } from "../script/utils"
|
|
3
|
-
const Other = {
|
|
4
|
-
"[device_id]"() {
|
|
5
|
-
return getCookie("deviceid") || getCookie("deviceId")
|
|
6
|
-
},
|
|
7
|
-
"[session_id]"() {
|
|
8
|
-
return (window as any).session_id;
|
|
9
|
-
},
|
|
10
|
-
"[usertag]"() {
|
|
11
|
-
return getCookie("usertag")
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { Other }
|