macro-parameters 0.0.5 → 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,66 +1,60 @@
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;
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
- );
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));
64
58
  }
65
59
 
66
60
  function cleanPlaceholder(str, params) {
@@ -110,7 +104,7 @@ var PlaceHolders = {
110
104
  // if (isWhaleOSGlobal) {
111
105
  // return "true"
112
106
  // }
113
- var reladvertStatus = false;
107
+ var reladvertStatus = "false";
114
108
  var userAgent = navigator.userAgent.toUpperCase();
115
109
  if (userAgent.indexOf("AOC") > -1) {
116
110
  reladvertStatus = getCookie("relAdvert");
@@ -118,7 +112,7 @@ var PlaceHolders = {
118
112
  else {
119
113
  reladvertStatus = getCookie("relAdvert");
120
114
  }
121
- reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
115
+ reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
122
116
  return reladvertStatus;
123
117
  },
124
118
  "[device_dnt]": function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macro-parameters",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Provide unified macro parameter retrieval",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,17 +43,23 @@ export function getProfileId() {
43
43
  }
44
44
  }
45
45
 
46
- export function setCookie(name, value, expires, path, domain, secure) {
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) {
47
53
  var cookieString =
48
- name +
49
- "=" +
50
- escape(value) +
51
- (expires ? ";expires=" + expires.toGMTString() : "") +
52
- (path ? ";path=" + path : "") +
53
- (domain ? ";domain=" + domain : "") +
54
- (secure ? ";secure" : "");
54
+ name +
55
+ "=" +
56
+ escape(value) +
57
+ (expires ? ";expires=" + expires.toGMTString() : "") +
58
+ (path ? ";path=" + path : "") +
59
+ (domain ? ";domain=" + domain : "") +
60
+ (secure ? ";secure" : "");
55
61
  document.cookie = cookieString;
56
- }
62
+ }
57
63
 
58
64
  export function getLocationOrigin() {
59
65
  return (
package/src/replace.ts CHANGED
@@ -55,15 +55,15 @@ const PlaceHolders: any = {
55
55
  // if (isWhaleOSGlobal) {
56
56
  // return "true"
57
57
  // }
58
- var reladvertStatus = false;
59
- var userAgent = navigator.userAgent.toUpperCase();
58
+ let reladvertStatus = "false";
59
+ const userAgent = navigator.userAgent.toUpperCase();
60
60
  if (userAgent.indexOf("AOC") > -1) {
61
61
  reladvertStatus = getCookie("relAdvert");
62
62
  } else {
63
63
  reladvertStatus = getCookie("relAdvert");
64
64
  }
65
65
 
66
- reladvertStatus = reladvertStatus == null ? false : reladvertStatus;
66
+ reladvertStatus = reladvertStatus == null ? "false" : reladvertStatus;
67
67
  return reladvertStatus;
68
68
  },
69
69
  "[device_dnt]"() {