@etspress/netflix 0.1.23 → 0.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etspress/netflix",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "private": false,
5
5
  "description": "流媒体合租主题插件",
6
6
  "license": "MIT",
@@ -18,7 +18,7 @@
18
18
  "id": "netflix",
19
19
  "name": "流媒体合租主题",
20
20
  "description": "流媒体合租商店主题与页面展示配置",
21
- "version": "0.1.23",
21
+ "version": "0.1.25",
22
22
  "runtime": {
23
23
  "type": "npm-static",
24
24
  "publicRoot": "public"
package/plugin.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "id": "netflix",
5
5
  "name": "流媒体合租主题",
6
- "version": "0.1.23",
6
+ "version": "0.1.25",
7
7
  "description": "流媒体合租商店主题与页面展示配置。",
8
8
  "author": "D&J Studio",
9
9
  "license": "MIT",
package/public/console.js CHANGED
@@ -38,6 +38,9 @@
38
38
  var captchaImage = '';
39
39
  var authChallengeToken = '';
40
40
  var authInviteTicket = '';
41
+ var homeConfigCache = null;
42
+ var homeConfigCacheAt = 0;
43
+ var homeConfigRequest = null;
41
44
 
42
45
  function isThemeRoute(path) {
43
46
  path = path || location.pathname;
@@ -143,6 +146,7 @@
143
146
  }
144
147
  hostStateSaved = false;
145
148
  document.documentElement.classList.remove('nfc-active');
149
+ if (!isThemeRoute() && typeof window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ === 'function') window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__();
146
150
  root = null;
147
151
  host = null;
148
152
  }
@@ -165,6 +169,24 @@
165
169
  });
166
170
  }
167
171
 
172
+ function loadThemeHomeConfig() {
173
+ if (homeConfigCache && Date.now() - homeConfigCacheAt < 60000) return Promise.resolve(homeConfigCache);
174
+ if (homeConfigRequest) return homeConfigRequest;
175
+ homeConfigRequest = fetch('/plugins/appstore/api/plugins/netflix/public-home-config', { cache: 'no-store' })
176
+ .then(function (response) {
177
+ if (!response.ok) throw new Error('主题配置暂不可用');
178
+ return response.json();
179
+ })
180
+ .then(function (payload) {
181
+ homeConfigCache = payload && payload.config || {};
182
+ homeConfigCacheAt = Date.now();
183
+ return homeConfigCache;
184
+ })
185
+ .catch(function () { return homeConfigCache || {}; })
186
+ .finally(function () { homeConfigRequest = null; });
187
+ return homeConfigRequest;
188
+ }
189
+
168
190
  function openAffiliate() {
169
191
  var headers = apiHeaders();
170
192
  headers['Content-Type'] = 'application/json';
@@ -263,6 +285,8 @@
263
285
  language.addEventListener('change', function () { localStorage.setItem('locale', language.value); location.reload(); });
264
286
  root.querySelector('.nfc-to-top').addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); });
265
287
  document.documentElement.classList.add('nfc-active');
288
+ document.documentElement.classList.remove('nfc-route-pending');
289
+ if (typeof window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ === 'function') window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__();
266
290
  host = document.querySelector('#app');
267
291
  if (host) {
268
292
  if (!hostStateSaved) {
@@ -599,6 +623,7 @@
599
623
  var order = responseData(body) || {};
600
624
  var paid = ['paid','fulfilling','partially_delivered','delivered','completed'].indexOf(order.status) >= 0;
601
625
  if (paid) { renderPaymentSuccess(order); return; }
626
+ if (order.status && order.status !== 'pending_payment') { pageReady('payment','<section class="nfc-panel nfc-payment-error">当前订单状态为 '+escapeHtml(statusName(order.status))+',无法继续支付。<a href="/me/orders">返回我的车票</a></section>'); return; }
602
627
  var amount = order.pay_amount || order.total_amount || order.amount || '0';
603
628
  return Promise.allSettled([
604
629
  fetch('/api/v1/order/payment-channels',{method:'POST',credentials:'include',headers:Object.assign({'Content-Type':'application/json'},apiHeaders()),body:JSON.stringify({order_no:paymentOrderNo,amount:amount})}).then(function(r){return r.json().catch(function(){return {}})}),
@@ -649,12 +674,13 @@
649
674
  root = document.createElement('div'); root.id = 'netflix-theme-home'; root.className = 'nfc-console nfc-auth';
650
675
  var brand = homeConfig.brandLogoUrl ? '<img src="' + escapeHtml(homeConfig.brandLogoUrl) + '" alt="' + escapeHtml(homeConfig.brandName || '奈飞小铺') + '">' : escapeHtml(homeConfig.brandName || '奈飞小铺');
651
676
  root.innerHTML = '<header class="nfh-header"><nav class="nfh-header-inner"><a class="nfh-logo" href="/">' + brand + '</a><div class="nfh-header-right"><div class="nfh-header-nav"><a href="/">' + escapeHtml(homeConfig.navHomeLabel || '首页') + '</a><a href="/me/orders">' + escapeHtml(homeConfig.navProductsLabel || '车票') + '</a><a href="/me/affiliate">' + escapeHtml(homeConfig.navPromotionLabel || '推广') + '</a></div></div></nav></header><main class="nfc-auth-main"><section class="nfc-auth-card"><a class="nfc-auth-back" href="/">‹ 返回首页</a>' + content + '</section></main><footer class="nfc-auth-footer">' + escapeHtml(homeConfig.copyrightText || '© 2019 - 2026 奈飞小铺') + '</footer>';
652
- document.body.appendChild(root); document.documentElement.classList.add('nfc-active'); document.documentElement.classList.remove('nfc-auth-route-pending'); animateThemePage(root.querySelector('.nfc-auth-card'));
677
+ document.body.appendChild(root); document.documentElement.classList.add('nfc-active'); document.documentElement.classList.remove('nfc-auth-route-pending'); document.documentElement.classList.remove('nfc-route-pending'); animateThemePage(root.querySelector('.nfc-auth-card'));
653
678
  host = document.querySelector('#app'); if (host) {
654
679
  if (!hostStateSaved) { hostDisplay = host.style.display; hostVisibility = host.style.visibility; hostStateSaved = true; }
655
680
  host.style.visibility = ''; host.style.display = 'none';
656
681
  }
657
682
  if (typeof window.__DUJIAO_RELEASE_CONSOLE_GATE__ === 'function') window.__DUJIAO_RELEASE_CONSOLE_GATE__();
683
+ if (typeof window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ === 'function') window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__();
658
684
  }
659
685
 
660
686
  function loadAuthConfig(kind) {
@@ -789,18 +815,10 @@
789
815
  clearPage();
790
816
  if (!isThemeRoute()) return;
791
817
  var requestedPath = location.pathname;
792
- Promise.allSettled([
793
- fetch('/plugins/appstore/api/plugins/public-assets?context=store', { cache: 'no-store' }).then(function (response) { return response.json(); }),
794
- fetch('/plugins/appstore/api/plugins/netflix/public-home-config', { cache: 'no-store' }).then(function (response) { return response.ok ? response.json() : {}; })
795
- ]).then(function (results) {
796
- if (location.pathname !== requestedPath) return;
797
- var assets = results[0].status === 'fulfilled' ? results[0].value : {};
798
- var config = results[1].status === 'fulfilled' ? results[1].value : {};
799
- if (!Array.isArray(assets.assets) || !assets.assets.some(function (item) { return item.id === 'netflix'; })) {
800
- if (typeof window.__DUJIAO_RELEASE_CONSOLE_GATE__ === 'function') window.__DUJIAO_RELEASE_CONSOLE_GATE__();
801
- return;
802
- }
803
- homeConfig = config.config || {};
818
+ var routeToken = sequence;
819
+ loadThemeHomeConfig().then(function (config) {
820
+ if (routeToken !== sequence || location.pathname !== requestedPath) return;
821
+ homeConfig = config || {};
804
822
  host = document.querySelector('#app');
805
823
  if (!host) return;
806
824
  if (!hostStateSaved) {
@@ -824,8 +842,8 @@
824
842
 
825
843
  window.__NETFLIX_THEME_ROUTE_CHANGE__ = routeChanged;
826
844
  window.__NETFLIX_THEME_RELEASE__ = clearPage;
827
- timer = setInterval(routeChanged, 400);
828
845
  window.addEventListener('popstate', routeChanged);
846
+ timer = setInterval(routeChanged, 1200);
829
847
  window.addEventListener('pagehide', function () { sequence++; clearInterval(timer); clearPage(); });
830
848
  routeChanged();
831
849
  })();
package/public/home.js CHANGED
@@ -39,7 +39,11 @@
39
39
  }
40
40
  function animateThemeEnter(element) { if (window.gsap && element) window.gsap.fromTo(element,{autoAlpha:0,y:10},{autoAlpha:1,y:0,duration:.42,ease:'power2.out',clearProps:'transform'}); }
41
41
  function releaseHomeGate() {
42
+ // This shared gate also protects the destination console route. Do not
43
+ // release it while the homepage is unmounting for an in-app transition.
44
+ if (window.location.pathname !== '/') return;
42
45
  if (typeof window.__DUJIAO_RELEASE_HOME_GATE__ === 'function') window.__DUJIAO_RELEASE_HOME_GATE__();
46
+ if (typeof window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ === 'function') window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__();
43
47
  }
44
48
 
45
49
  function escapeHtml(value) {
@@ -542,9 +546,14 @@
542
546
  window.__NETFLIX_THEME_HOME_ROUTE_SYNC__ = syncRoute;
543
547
  window.addEventListener('popstate', syncRoute);
544
548
  window.addEventListener('hashchange', syncRoute);
545
- checkPlugin();
549
+ if (window.__NETFLIX_THEME_ENABLED__ === true) {
550
+ pluginEnabled = true;
551
+ mount();
552
+ } else {
553
+ checkPlugin();
554
+ }
546
555
  checkTimer = window.setInterval(checkPlugin, 2500);
547
- routeTimer = window.setInterval(syncRoute, 500);
556
+ routeTimer = window.setInterval(syncRoute, 1500);
548
557
  window.addEventListener('pagehide', function () {
549
558
  window.clearInterval(checkTimer);
550
559
  window.clearInterval(routeTimer);
package/public/inject.js CHANGED
@@ -2,14 +2,43 @@
2
2
  var pluginId = 'netflix';
3
3
  var adminPath = '/admin/';
4
4
  var authPath = window.location.pathname;
5
- if ((authPath === '/auth/login' || authPath === '/auth/register') && new URLSearchParams(window.location.search).get('native') !== '1') {
6
- document.documentElement.classList.add('nfc-auth-route-pending');
7
- if (!document.getElementById('nfc-auth-route-gate')) {
8
- var authGateStyle = document.createElement('style');
9
- authGateStyle.id = 'nfc-auth-route-gate';
10
- authGateStyle.textContent = 'html.nfc-auth-route-pending #app{visibility:hidden!important}';
11
- (document.head || document.documentElement).appendChild(authGateStyle);
5
+ var routeParams = new URLSearchParams(window.location.search);
6
+ var gatedThemeRoutes = ['/me/orders', '/me/affiliate', '/me/wallet', '/me', '/me/profile', '/auth/login', '/auth/register', '/pay'];
7
+ var routeIsThemed = gatedThemeRoutes.indexOf(authPath) >= 0 &&
8
+ !(['/me/affiliate', '/auth/login', '/auth/register', '/pay'].indexOf(authPath) >= 0 && routeParams.get('native') === '1') &&
9
+ !(authPath === '/pay' && routeParams.get('guest') === '1');
10
+ if (routeIsThemed) {
11
+ document.documentElement.classList.add('nfc-route-pending');
12
+ if (!document.getElementById('nfc-route-gate-style')) {
13
+ var routeGateStyle = document.createElement('style');
14
+ routeGateStyle.id = 'nfc-route-gate-style';
15
+ routeGateStyle.textContent = 'html.nfc-route-pending #app{visibility:hidden!important}html.nfc-route-pending,html.nfc-route-pending body{background:#fff!important}.nfc-route-loader{position:fixed;inset:0;z-index:99999;display:grid;place-items:center;background:#fff;transition:opacity .18s ease}.nfc-route-loader-badge{position:relative;width:88px;height:88px;display:grid;place-items:center;border:1px solid #eee;border-radius:50%;background:#fff;box-shadow:0 6px 24px #00000014}.nfc-route-loader-inner{width:64px;height:64px;display:grid;place-items:center;border:4px solid #fff;border-radius:50%;background:#ef5350;box-shadow:0 2px 8px #0002}.nfc-route-loader-inner img{width:44px;height:22px;object-fit:contain}.nfc-route-loader-ring{position:absolute;inset:-4px;width:96px;height:96px;animation:nfc-route-loader-spin 1.1s linear infinite}.nfc-route-loader-ring circle{fill:none;stroke:#ef5350;stroke-width:3;stroke-linecap:round;stroke-dasharray:62 240}@keyframes nfc-route-loader-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.nfc-route-loader-ring{animation-duration:3s}}';
16
+ (document.head || document.documentElement).appendChild(routeGateStyle);
12
17
  }
18
+ function releaseThemeRouteGate() {
19
+ document.documentElement.classList.remove('nfc-route-pending');
20
+ if (window.__NETFLIX_THEME_ROUTE_LOADER__) {
21
+ var loader = window.__NETFLIX_THEME_ROUTE_LOADER__;
22
+ window.__NETFLIX_THEME_ROUTE_LOADER__ = null;
23
+ loader.style.opacity = '0';
24
+ loader.style.pointerEvents = 'none';
25
+ window.setTimeout(function () { loader.remove(); }, 200);
26
+ }
27
+ }
28
+ if (typeof window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ !== 'function') window.__NETFLIX_THEME_RELEASE_ROUTE_GATE__ = releaseThemeRouteGate;
29
+ function showThemeRouteLoader() {
30
+ if (window.__NETFLIX_THEME_ROUTE_LOADER__ || document.querySelector('.nfh-route-loader,.nfc-route-loader') || !document.body || !document.documentElement.classList.contains('nfc-route-pending')) return;
31
+ var loader = document.createElement('div');
32
+ loader.className = 'nfc-route-loader';
33
+ loader.setAttribute('role', 'status');
34
+ loader.setAttribute('aria-label', '页面加载中');
35
+ loader.innerHTML = '<div class="nfc-route-loader-badge"><svg class="nfc-route-loader-ring" viewBox="0 0 96 96" aria-hidden="true"><circle cx="48" cy="48" r="45"/></svg><div class="nfc-route-loader-inner"><img src="/plugins/appstore/static-plugins/netflix/assets/txsw-chameleon-logo.svg" alt=""></div></div>';
36
+ window.__NETFLIX_THEME_ROUTE_LOADER__ = loader;
37
+ document.body.appendChild(loader);
38
+ }
39
+ showThemeRouteLoader();
40
+ document.addEventListener('DOMContentLoaded', showThemeRouteLoader, { once: true });
41
+ window.addEventListener('pagehide', releaseThemeRouteGate, { once: true });
13
42
  }
14
43
  if (window.location.pathname.indexOf(adminPath) !== 0) return;
15
44
  if (window.__NETFLIX_THEME_SETTINGS_INJECTOR__) return;
@@ -248,7 +277,7 @@
248
277
  card = createChoiceCard(kind);
249
278
  group.appendChild(card);
250
279
  }
251
- var selected = state.home[kind] === option.value;
280
+ var selected = state.enabled && state.home[kind] === option.value;
252
281
  setCardSelection(card, selected);
253
282
  group.classList.toggle('netflix-theme-plugin-selected', selected);
254
283
  setNativeRadioSelection(group, selected);
@@ -286,6 +315,7 @@
286
315
  function selectPluginChoice(kind, value) {
287
316
  var option = choices[kind];
288
317
  var previous = state.home[kind] || '';
318
+ if (previous === value) return;
289
319
  state.home[kind] = value;
290
320
  syncPage();
291
321
  persistHome().catch(function (error) {
@@ -309,6 +339,13 @@
309
339
  var group = radio && radio.closest('[role="radiogroup"]');
310
340
  var kind = group && group.dataset.netflixKind;
311
341
  if (!kind || !state.home[kind]) return;
342
+ if (state.enabled) {
343
+ event.preventDefault();
344
+ event.stopImmediatePropagation();
345
+ state.home[kind] = choices[kind].value;
346
+ syncPage();
347
+ return;
348
+ }
312
349
  state.home[kind] = '';
313
350
  syncPage();
314
351
  persistHome().catch(function (error) {
@@ -326,6 +363,10 @@
326
363
  var field = (payload.fields || []).find(function (item) { return item.key === configKey; });
327
364
  var home = JSON.parse(field && field.value || '{}');
328
365
  state.home = home && typeof home === 'object' && !Array.isArray(home) ? home : {};
366
+ if (state.enabled) {
367
+ state.home.storefrontTemplate = choices.storefrontTemplate.value;
368
+ state.home.productLayout = choices.productLayout.value;
369
+ }
329
370
  state.configLoaded = true;
330
371
  syncPage();
331
372
  } catch (error) {