@taole/dev-helper 0.0.31 → 0.1.1

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.
@@ -5,20 +5,62 @@
5
5
 
6
6
  // const name = 'open-diandian';
7
7
  // 测试使用open-diandain-app标签
8
- // TODO: 后期可以考虑优化为根据域名自动选择appid
8
+ const appInfoMap = {
9
+ 'wx6cd4c28b58e8737f': { // 点点开黑
10
+ app_name: '点点开黑',
11
+ link_ios: "com.tuwan.diandian://openPage",
12
+ link_android: "intent://diandain:8888/splash#Intent;scheme=taole;package=com.tuwan.yw;S.browser_fallback_url=https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw;end",
13
+ fallback_link_ios: "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746",
14
+ fallback_link_android: 'https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw',
15
+ },
16
+ 'wx0e4a6eed634134ce': { // 兔小铲
17
+ app_name: '兔小铲',
18
+ link_ios: "", // 空缺,后期补充
19
+ link_android: "tuxiaochan://diandain:8888/splash",
20
+ fallback_link_ios: 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939',
21
+ fallback_link_android: 'https://m.malink.cn/s/rYNfAj',
22
+ },
23
+ 'wxcd28679e4d8c1792': { // 点点狼人
24
+ app_name: '点点狼人',
25
+ link_ios: "", // 空缺,后期补充
26
+ link_android: "taole://diandainwolf:8888/splash",
27
+ fallback_link_ios: 'https://apps.apple.com/mo/app/%E7%82%B9%E7%82%B9%E7%8B%BC%E4%BA%BA%E6%9D%80-%E8%AF%AD%E9%9F%B3%E7%A4%BE%E4%BA%A4%E6%8E%A8%E7%90%86%E6%B8%B8%E6%88%8F/id1557616226',
28
+ fallback_link_android: '',
29
+ },
30
+ };
31
+ function resolveTwKit() {
32
+ if (window.twKit) {
33
+ return;
34
+ }
35
+ const script = document.createElement('script');
36
+ script.src = 'https://asset.tuwan.com/script/tw-kit/0.4.12/cdn/index.js';
37
+ document.head.appendChild(script);
38
+ return new Promise((resolve, reject) => {
39
+ script.onload = () => {
40
+ resolve();
41
+ };
42
+ script.onerror = () => {
43
+ reject(new Error('load tw-kit error'));
44
+ };
45
+ });
46
+ }
47
+ let id = 1;
9
48
  function defineTag() {
10
49
  customElements.define(
11
50
  "open-diandain-app",
12
51
  class extends HTMLElement {
13
52
  static get observedAttributes() {
14
- // 后期考虑去掉fallback_link_ios和fallback_link_android
15
- return ['appid', 'extinfo', 'fallback_link_ios', 'fallback_link_android'];
53
+ return ['appid', 'extinfo', 'debug'];
16
54
  }
17
55
  constructor() {
18
56
  super();
57
+ this._debug = false;
19
58
  this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
20
- this._txcAppid = 'wx0e4a6eed634134ce'; // 兔小铲
21
59
  this._openAppTag = null;
60
+ this._appid = '';
61
+ this._appInfo = null;
62
+ this._alink_fallback = '';
63
+ this._alink_link = '';
22
64
  this._template = null;
23
65
  this._alink = null;
24
66
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -27,11 +69,24 @@
27
69
  this._isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
28
70
  this._isHarmony = /Harmony/i.test(navigator.userAgent);
29
71
  this._isMobile = this._isAndroid || this._isIOS || this._isHarmony;
72
+ this._isConnected = false;
73
+ this._id = id++;
74
+ this._clipboardText = '';
75
+ this._clipboardTextPs = null;
76
+ this._clipboardTextTimer = null;
77
+ }
78
+ _log(...args) {
79
+ if (this._debug) {
80
+ console.log('open-diandian:[' + this._id + ']', ...args);
81
+ }
30
82
  }
31
83
  attributeChangedCallback() {
84
+ this._log("attributeChangedCallback");
32
85
  this._updateTagAttr();
33
86
  }
34
87
  connectedCallback() {
88
+ this._log("connectedCallback");
89
+ this._isConnected = true;
35
90
  if (this._isWechat) {
36
91
  this._genTemplate();
37
92
  if (!this._openAppTag) {
@@ -57,7 +112,7 @@
57
112
  this._template.content.appendChild(this._openAppTag);
58
113
  this.attachShadow({ mode: 'open' });
59
114
  this.shadowRoot.appendChild(this._template.content);
60
- console.log('open-diandian: wx-open-launch-app appended');
115
+ this._log('open-diandian: wx-open-launch-app appended');
61
116
  // 监听打开app失败的情况,跳转fallback链接
62
117
  this._openAppTag.addEventListener('error', (e) => {
63
118
  if (this._isHarmony) {
@@ -67,7 +122,7 @@
67
122
  var tmplnk = document.createElement("a");
68
123
  tmplnk.href = this._alink_fallback;
69
124
  tmplnk.click();
70
- console.log('open-diandian: wx-open-launch-app error', this._alink_fallback);
125
+ this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
71
126
  });
72
127
  } else {
73
128
  this._updateTagAttr();
@@ -83,23 +138,50 @@
83
138
  this.attachShadow({ mode: 'open' });
84
139
  this.shadowRoot.appendChild(this._template.content);
85
140
  this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
86
- console.log('open-diandian: open link appended');
87
- // only test
88
- // if(this._isHarmony){
89
- // this._showOpenInBrowserHint();
90
- // }
141
+ this._log('open-diandian: open link appended');
142
+ this._clickLink = false;
143
+ this._pagehideCallback = this._pagehideCallback || (() => {
144
+ if (document.hidden) {
145
+ if (this._clickLink) {
146
+ this._log("open app successfully");
147
+ if (this._alink_click_timer) {
148
+ clearTimeout(this._alink_click_timer);
149
+ this._alink_click_timer = null;
150
+ }
151
+ this._clickLink = false;
152
+ }
153
+ }
154
+ });
155
+ window.removeEventListener("visibilitychange", this._pagehideCallback);
156
+ window.addEventListener("visibilitychange", this._pagehideCallback);
91
157
  }
92
158
  this._updateTagAttr();
159
+ this._initClipboardText();
160
+ } else {
161
+ this._log('open-diandian: not supported pc platform');
93
162
  }
94
163
  }
95
164
  _handleAlinkClick() {
96
- setTimeout(() => {
97
- var tmplnk = document.createElement("a");
98
- tmplnk.href = this._alink_fallback;
99
- tmplnk.click();
100
- }, 1000);
165
+ this._writeClickboard();
166
+ if (this._alink_link != this._alink_fallback) {
167
+ this._log("this._alink is clicked");
168
+ // 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
169
+ if (this._alink_click_timer) {
170
+ clearTimeout(this._alink_click_timer);
171
+ }
172
+ this._clickLink = true;
173
+ this._alink_click_timer = setTimeout(() => {
174
+ this._log("3s timeout, open app failed, jump to fallback link");
175
+ this._alink_click_timer = null;
176
+ var tmplnk = document.createElement("a");
177
+ tmplnk.href = this._alink_fallback;
178
+ tmplnk.click();
179
+ }, 3000);
180
+ }
101
181
  }
102
182
  disconnectedCallback() {
183
+ this._log("disconnectedCallback");
184
+ this._isConnected = false;
103
185
  if (this._openAppTag) {
104
186
  this._openAppTag.remove();
105
187
  this._openAppTag = null;
@@ -109,10 +191,67 @@
109
191
  this._alink = null;
110
192
  }
111
193
  }
194
+ _initClipboardText() {
195
+ // 延迟20ms执行,如果20ms后卸载了,直接不执行了
196
+ this._clipboardTextTimer = setTimeout(() => {
197
+ if (!this._isConnected) {
198
+ this._log("not connected, no need to init clipboard text");
199
+ return;
200
+ }
201
+ const extinfo = this.getAttribute('extinfo') || '';
202
+ if (!extinfo) {
203
+ this._log("extinfo is empty, no need to init clipboard text");
204
+ return;
205
+ }
206
+ this._log("initClipboardText");
207
+ if (!this._clipboardTextPs) {
208
+ this._clipboardTextPs = new Promise(async (resolve, reject) => {
209
+ try {
210
+ await resolveTwKit();
211
+ const urlText = `https://${twKit.isTest ? 'y-test.tuwan.com' : 'y.tuwan.com'}/events/app_transfer_page?extinfo=` + encodeURIComponent(extinfo);
212
+ const shorUrl = await twKit.genShortUrl(urlText);
213
+ this._clipboardText = `【${this._appInfo.app_name}】 ${shorUrl} `;
214
+ this._log("initClipboardText success", this._clipboardText);
215
+ resolve();
216
+ } catch (error) {
217
+ this._log("initClipboardText error", error);
218
+ reject(error);
219
+ }
220
+ });
221
+ }
222
+ }, 25);
223
+ }
224
+ async _writeClickboard() {
225
+ const text = this._clipboardText;
226
+ if (!text) {
227
+ this._log("clipboard text is empty, no need to write clipboard");
228
+ return;
229
+ }
230
+ if (!navigator.clipboard) {
231
+ const textarea = document.createElement("textarea");
232
+ textarea.value = text;
233
+ textarea.style.position = "fixed"; // 防止闪烁
234
+ document.body.appendChild(textarea);
235
+ textarea.focus();
236
+ textarea.select();
237
+ try {
238
+ document.execCommand("copy");
239
+ } catch (err) {
240
+ this._log('open-diandian: _writeClickboard error 1', err, text);
241
+ }
242
+ document.body.removeChild(textarea);
243
+ } else {
244
+ try {
245
+ await navigator.clipboard.writeText(text);
246
+ } catch (err) {
247
+ this._log('open-diandian: _writeClickboard error 2', err, text);
248
+ }
249
+ }
250
+ }
112
251
  _showOpenInBrowserHint() { // 提示用户在浏览器中打开
113
- console.log('open-diandian: showOpenInBrowserHint');
252
+ this._log('open-diandian: showOpenInBrowserHint');
114
253
  let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
115
- if(_hHintDiv){
254
+ if (_hHintDiv) {
116
255
  _hHintDiv.remove();
117
256
  _hHintDiv = null;
118
257
  }
@@ -130,7 +269,7 @@
130
269
  _hHintDiv.style.backgroundSize = '80vw auto';
131
270
  _hHintDiv.style.backgroundPosition = 'top right';
132
271
  _hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
133
- _hHintDiv.onclick = function() {
272
+ _hHintDiv.onclick = function () {
134
273
  _hHintDiv.remove();
135
274
  _hHintDiv = null;
136
275
  };
@@ -143,55 +282,27 @@
143
282
  this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
144
283
  }
145
284
  }
146
- _genFallbackLink() {
147
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
148
- const isTxc = this.getAttribute('appid') === this._txcAppid;
149
- if (isDianDian) {
150
- if (this._isIOS) {
151
- if (this.appid)
152
- this._alink_fallback = "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746";
153
- } else {
154
- var packageName = "com.tuwan.yw";
155
- this._alink_fallback = "https://sj.qq.com/myapp/detail.htm?apkName=" + packageName;
156
- }
157
- } else if (isTxc) {
158
- if (this._isIOS) {
159
- this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
160
- } else {
161
- this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
162
- }
285
+ _updateTagAttr() {
286
+ this._debug = this.getAttribute('debug') !== null;
287
+ this._appid = this.getAttribute('appid') || this._defaultAppid;
288
+ this._appInfo = appInfoMap[this._appid];
289
+ if (!this._appInfo) {
290
+ console.error('open-diandian: appid not supported', this._appid);
291
+ return;
292
+ }
293
+ this._log('open-diandian: appInfo', this._appInfo);
294
+ if (this._isIOS) {
295
+ this._alink_fallback = this._appInfo.fallback_link_ios;
296
+ this._alink_link = this._appInfo.link_ios || this._alink_fallback;
163
297
  } else {
164
- if (this._isIOS) {
165
- this._alink_fallback = this.getAttribute('fallback_link_ios');
166
- } else {
167
- this._alink_fallback = this.getAttribute('fallback_link_android');
168
- }
298
+ this._alink_fallback = this._appInfo.fallback_link_android;
299
+ this._alink_link = this._appInfo.link_android || this._alink_fallback;
169
300
  }
170
- }
171
- _updateTagAttr() {
172
- this._genFallbackLink();
173
301
  if (this._openAppTag) {
174
- this._openAppTag.setAttribute('appid', this.getAttribute('appid') || this._defaultAppid);
302
+ this._openAppTag.setAttribute('appid', this._appid);
175
303
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
176
304
  } else if (this._alink) {
177
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
178
- const isTxc = this.getAttribute('appid') === this._txcAppid;
179
- if (isDianDian) {
180
- if (this._isIOS) {
181
- this._alink.href = "com.tuwan.diandian://openPage";
182
- } else {
183
- var packageName = "com.tuwan.yw";
184
- this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
185
- }
186
- } else if (isTxc) {
187
- if (this._isAndroid || this._isHarmony) {
188
- this._alink.href = "tuxiaochan://diandain:8888/splash";
189
- } else if (this._isIOS) { // ios 跳转appstore
190
- this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
191
- } else {
192
- this._alink.href = "https://m.malink.cn/s/rYNfAj";
193
- }
194
- }
305
+ this._alink.href = this._alink_link;
195
306
  }
196
307
  }
197
308
  },
@@ -1,19 +1,61 @@
1
1
  // const name = 'open-diandian';
2
2
  // 测试使用open-diandain-app标签
3
- // TODO: 后期可以考虑优化为根据域名自动选择appid
3
+ const appInfoMap = {
4
+ 'wx6cd4c28b58e8737f': { // 点点开黑
5
+ app_name: '点点开黑',
6
+ link_ios: "com.tuwan.diandian://openPage",
7
+ link_android: "intent://diandain:8888/splash#Intent;scheme=taole;package=com.tuwan.yw;S.browser_fallback_url=https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw;end",
8
+ fallback_link_ios: "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746",
9
+ fallback_link_android: 'https://sj.qq.com/myapp/detail.htm?apkName=com.tuwan.yw',
10
+ },
11
+ 'wx0e4a6eed634134ce': { // 兔小铲
12
+ app_name: '兔小铲',
13
+ link_ios: "", // 空缺,后期补充
14
+ link_android: "tuxiaochan://diandain:8888/splash",
15
+ fallback_link_ios: 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939',
16
+ fallback_link_android: 'https://m.malink.cn/s/rYNfAj',
17
+ },
18
+ 'wxcd28679e4d8c1792': { // 点点狼人
19
+ app_name: '点点狼人',
20
+ link_ios: "", // 空缺,后期补充
21
+ link_android: "taole://diandainwolf:8888/splash",
22
+ fallback_link_ios: 'https://apps.apple.com/mo/app/%E7%82%B9%E7%82%B9%E7%8B%BC%E4%BA%BA%E6%9D%80-%E8%AF%AD%E9%9F%B3%E7%A4%BE%E4%BA%A4%E6%8E%A8%E7%90%86%E6%B8%B8%E6%88%8F/id1557616226',
23
+ fallback_link_android: '',
24
+ },
25
+ }
26
+ function resolveTwKit() {
27
+ if (window.twKit) {
28
+ return;
29
+ }
30
+ const script = document.createElement('script');
31
+ script.src = 'https://asset.tuwan.com/script/tw-kit/0.4.12/cdn/index.js';
32
+ document.head.appendChild(script);
33
+ return new Promise((resolve, reject) => {
34
+ script.onload = () => {
35
+ resolve();
36
+ }
37
+ script.onerror = () => {
38
+ reject(new Error('load tw-kit error'));
39
+ }
40
+ });
41
+ }
42
+ let id = 1;
4
43
  function defineTag() {
5
44
  customElements.define(
6
45
  "open-diandain-app",
7
46
  class extends HTMLElement {
8
47
  static get observedAttributes() {
9
- // 后期考虑去掉fallback_link_ios和fallback_link_android
10
- return ['appid', 'extinfo', 'fallback_link_ios', 'fallback_link_android'];
48
+ return ['appid', 'extinfo', 'debug'];
11
49
  }
12
50
  constructor() {
13
51
  super();
52
+ this._debug = false;
14
53
  this._defaultAppid = 'wx6cd4c28b58e8737f';// 点点开黑
15
- this._txcAppid = 'wx0e4a6eed634134ce'; // 兔小铲
16
54
  this._openAppTag = null;
55
+ this._appid = '';
56
+ this._appInfo = null;
57
+ this._alink_fallback = '';
58
+ this._alink_link = '';
17
59
  this._template = null;
18
60
  this._alink = null;
19
61
  this._isApp = (window.AndroidJs && window.AndroidJs.publicInteraction) || (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.AndroidJs);
@@ -22,11 +64,24 @@ function defineTag() {
22
64
  this._isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
23
65
  this._isHarmony = /Harmony/i.test(navigator.userAgent);
24
66
  this._isMobile = this._isAndroid || this._isIOS || this._isHarmony;
67
+ this._isConnected = false;
68
+ this._id = id++;
69
+ this._clipboardText = '';
70
+ this._clipboardTextPs = null;
71
+ this._clipboardTextTimer = null;
72
+ }
73
+ _log(...args) {
74
+ if (this._debug) {
75
+ console.log('open-diandian:[' + this._id + ']', ...args);
76
+ }
25
77
  }
26
78
  attributeChangedCallback() {
79
+ this._log("attributeChangedCallback")
27
80
  this._updateTagAttr();
28
81
  }
29
82
  connectedCallback() {
83
+ this._log("connectedCallback")
84
+ this._isConnected = true;
30
85
  if (this._isWechat) {
31
86
  this._genTemplate();
32
87
  if (!this._openAppTag) {
@@ -52,7 +107,7 @@ function defineTag() {
52
107
  this._template.content.appendChild(this._openAppTag);
53
108
  this.attachShadow({ mode: 'open' });
54
109
  this.shadowRoot.appendChild(this._template.content);
55
- console.log('open-diandian: wx-open-launch-app appended');
110
+ this._log('open-diandian: wx-open-launch-app appended');
56
111
  // 监听打开app失败的情况,跳转fallback链接
57
112
  this._openAppTag.addEventListener('error', (e) => {
58
113
  if (this._isHarmony) {
@@ -62,7 +117,7 @@ function defineTag() {
62
117
  var tmplnk = document.createElement("a");
63
118
  tmplnk.href = this._alink_fallback;
64
119
  tmplnk.click();
65
- console.log('open-diandian: wx-open-launch-app error', this._alink_fallback);
120
+ this._log('open-diandian: wx-open-launch-app error', this._alink_fallback);
66
121
  });
67
122
  } else {
68
123
  this._updateTagAttr();
@@ -78,23 +133,50 @@ function defineTag() {
78
133
  this.attachShadow({ mode: 'open' });
79
134
  this.shadowRoot.appendChild(this._template.content);
80
135
  this._alink.addEventListener('click', this._handleAlinkClick.bind(this));
81
- console.log('open-diandian: open link appended');
82
- // only test
83
- // if(this._isHarmony){
84
- // this._showOpenInBrowserHint();
85
- // }
136
+ this._log('open-diandian: open link appended');
137
+ this._clickLink = false;
138
+ this._pagehideCallback = this._pagehideCallback || (() => {
139
+ if (document.hidden) {
140
+ if (this._clickLink) {
141
+ this._log("open app successfully");
142
+ if (this._alink_click_timer) {
143
+ clearTimeout(this._alink_click_timer);
144
+ this._alink_click_timer = null;
145
+ }
146
+ this._clickLink = false;
147
+ }
148
+ }
149
+ });
150
+ window.removeEventListener("visibilitychange", this._pagehideCallback);
151
+ window.addEventListener("visibilitychange", this._pagehideCallback);
86
152
  }
87
153
  this._updateTagAttr();
154
+ this._initClipboardText();
155
+ } else {
156
+ this._log('open-diandian: not supported pc platform');
88
157
  }
89
158
  }
90
159
  _handleAlinkClick() {
91
- setTimeout(() => {
92
- var tmplnk = document.createElement("a");
93
- tmplnk.href = this._alink_fallback;
94
- tmplnk.click();
95
- }, 1000);
160
+ this._writeClickboard();
161
+ if (this._alink_link != this._alink_fallback) {
162
+ this._log("this._alink is clicked");
163
+ // 端外使用scheme打开app,3秒内如果页面有隐藏过,那么认为拉端成功了,否则跳转到fallback链接
164
+ if (this._alink_click_timer) {
165
+ clearTimeout(this._alink_click_timer);
166
+ }
167
+ this._clickLink = true;
168
+ this._alink_click_timer = setTimeout(() => {
169
+ this._log("3s timeout, open app failed, jump to fallback link");
170
+ this._alink_click_timer = null;
171
+ var tmplnk = document.createElement("a");
172
+ tmplnk.href = this._alink_fallback;
173
+ tmplnk.click();
174
+ }, 3000);
175
+ }
96
176
  }
97
177
  disconnectedCallback() {
178
+ this._log("disconnectedCallback")
179
+ this._isConnected = false;
98
180
  if (this._openAppTag) {
99
181
  this._openAppTag.remove();
100
182
  this._openAppTag = null;
@@ -104,10 +186,67 @@ function defineTag() {
104
186
  this._alink = null;
105
187
  }
106
188
  }
189
+ _initClipboardText() {
190
+ // 延迟20ms执行,如果20ms后卸载了,直接不执行了
191
+ this._clipboardTextTimer = setTimeout(() => {
192
+ if (!this._isConnected) {
193
+ this._log("not connected, no need to init clipboard text")
194
+ return;
195
+ }
196
+ const extinfo = this.getAttribute('extinfo') || '';
197
+ if (!extinfo) {
198
+ this._log("extinfo is empty, no need to init clipboard text")
199
+ return;
200
+ }
201
+ this._log("initClipboardText")
202
+ if (!this._clipboardTextPs) {
203
+ this._clipboardTextPs = new Promise(async (resolve, reject) => {
204
+ try {
205
+ await resolveTwKit();
206
+ const urlText = `https://${twKit.isTest ? 'y-test.tuwan.com' : 'y.tuwan.com'}/events/app_transfer_page?extinfo=` + encodeURIComponent(extinfo);
207
+ const shorUrl = await twKit.genShortUrl(urlText);
208
+ this._clipboardText = `【${this._appInfo.app_name}】 ${shorUrl} `;
209
+ this._log("initClipboardText success", this._clipboardText);
210
+ resolve();
211
+ } catch (error) {
212
+ this._log("initClipboardText error", error);
213
+ reject(error);
214
+ }
215
+ });
216
+ }
217
+ }, 25);
218
+ }
219
+ async _writeClickboard() {
220
+ const text = this._clipboardText;
221
+ if (!text) {
222
+ this._log("clipboard text is empty, no need to write clipboard")
223
+ return;
224
+ }
225
+ if (!navigator.clipboard) {
226
+ const textarea = document.createElement("textarea");
227
+ textarea.value = text;
228
+ textarea.style.position = "fixed"; // 防止闪烁
229
+ document.body.appendChild(textarea);
230
+ textarea.focus();
231
+ textarea.select();
232
+ try {
233
+ document.execCommand("copy");
234
+ } catch (err) {
235
+ this._log('open-diandian: _writeClickboard error 1', err, text);
236
+ }
237
+ document.body.removeChild(textarea);
238
+ } else {
239
+ try {
240
+ await navigator.clipboard.writeText(text);
241
+ } catch (err) {
242
+ this._log('open-diandian: _writeClickboard error 2', err, text);
243
+ }
244
+ }
245
+ }
107
246
  _showOpenInBrowserHint() { // 提示用户在浏览器中打开
108
- console.log('open-diandian: showOpenInBrowserHint');
247
+ this._log('open-diandian: showOpenInBrowserHint');
109
248
  let _hHintDiv = document.getElementById('open-diandian-h-hint-div');
110
- if(_hHintDiv){
249
+ if (_hHintDiv) {
111
250
  _hHintDiv.remove();
112
251
  _hHintDiv = null;
113
252
  }
@@ -125,7 +264,7 @@ function defineTag() {
125
264
  _hHintDiv.style.backgroundSize = '80vw auto';
126
265
  _hHintDiv.style.backgroundPosition = 'top right';
127
266
  _hHintDiv.style.backgroundColor = 'rgba(0,0,0,0.5)';
128
- _hHintDiv.onclick = function() {
267
+ _hHintDiv.onclick = function () {
129
268
  _hHintDiv.remove();
130
269
  _hHintDiv = null;
131
270
  };
@@ -138,55 +277,27 @@ function defineTag() {
138
277
  this._template.innerHTML = '<style>:host {display: block;width: 100%;height: 100%;overflow: hidden;opacity: 0;background:transparent;}</style>';
139
278
  }
140
279
  }
141
- _genFallbackLink() {
142
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
143
- const isTxc = this.getAttribute('appid') === this._txcAppid;
144
- if (isDianDian) {
145
- if (this._isIOS) {
146
- if (this.appid)
147
- this._alink_fallback = "https://apps.apple.com/cn/app/%E7%82%B9%E7%82%B9-%E8%AF%AD%E9%9F%B3%E5%BC%80%E9%BB%91/id1449564746";
148
- } else {
149
- var packageName = "com.tuwan.yw";
150
- this._alink_fallback = "https://sj.qq.com/myapp/detail.htm?apkName=" + packageName;
151
- }
152
- } else if (isTxc) {
153
- if (this._isIOS) {
154
- this._alink_fallback = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
155
- } else {
156
- this._alink_fallback = "https://m.malink.cn/s/rYNfAj";
157
- }
280
+ _updateTagAttr() {
281
+ this._debug = this.getAttribute('debug') !== null;
282
+ this._appid = this.getAttribute('appid') || this._defaultAppid;
283
+ this._appInfo = appInfoMap[this._appid];
284
+ if (!this._appInfo) {
285
+ console.error('open-diandian: appid not supported', this._appid);
286
+ return;
287
+ }
288
+ this._log('open-diandian: appInfo', this._appInfo);
289
+ if (this._isIOS) {
290
+ this._alink_fallback = this._appInfo.fallback_link_ios;
291
+ this._alink_link = this._appInfo.link_ios || this._alink_fallback;
158
292
  } else {
159
- if (this._isIOS) {
160
- this._alink_fallback = this.getAttribute('fallback_link_ios');
161
- } else {
162
- this._alink_fallback = this.getAttribute('fallback_link_android');
163
- }
293
+ this._alink_fallback = this._appInfo.fallback_link_android;
294
+ this._alink_link = this._appInfo.link_android || this._alink_fallback;
164
295
  }
165
- }
166
- _updateTagAttr() {
167
- this._genFallbackLink();
168
296
  if (this._openAppTag) {
169
- this._openAppTag.setAttribute('appid', this.getAttribute('appid') || this._defaultAppid);
297
+ this._openAppTag.setAttribute('appid', this._appid);
170
298
  this._openAppTag.setAttribute('extinfo', this.getAttribute('extinfo') || "");
171
299
  } else if (this._alink) {
172
- const isDianDian = this.getAttribute('appid') === this._defaultAppid;
173
- const isTxc = this.getAttribute('appid') === this._txcAppid;
174
- if (isDianDian) {
175
- if (this._isIOS) {
176
- this._alink.href = "com.tuwan.diandian://openPage";
177
- } else {
178
- var packageName = "com.tuwan.yw";
179
- this._alink.href = "intent://diandain:8888/splash#Intent;scheme=taole;package=" + packageName + ";S.browser_fallback_url=" + this._alink_fallback + ";end";
180
- }
181
- } else if (isTxc) {
182
- if (this._isAndroid || this._isHarmony) {
183
- this._alink.href = "tuxiaochan://diandain:8888/splash";
184
- } else if (this._isIOS) { // ios 跳转appstore
185
- this._alink.href = 'https://apps.apple.com/us/app/%E5%85%94%E5%B0%8F%E9%93%B2/id6745920939';
186
- } else {
187
- this._alink.href = "https://m.malink.cn/s/rYNfAj";
188
- }
189
- }
300
+ this._alink.href = this._alink_link;
190
301
  }
191
302
  }
192
303
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/dev-helper",
3
- "version": "0.0.31",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npx -y rimraf dist && rollup -c",