@leeguoo/pwtk-network-debugger 1.2.2 → 1.2.4

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/dist/index.esm.js CHANGED
@@ -6675,6 +6675,7 @@ class NetworkInterceptor {
6675
6675
  this.requests = /* @__PURE__ */ new Map();
6676
6676
  this.listeners = [];
6677
6677
  this.decryptConfig = { enabled: false };
6678
+ window.__originalFetch = window.fetch;
6678
6679
  this.interceptXHR();
6679
6680
  this.interceptFetch();
6680
6681
  }
@@ -6711,6 +6712,9 @@ class NetworkInterceptor {
6711
6712
  generateRequestId() {
6712
6713
  return Math.random().toString(36).substr(2, 9);
6713
6714
  }
6715
+ isInternalUrl(url) {
6716
+ return url.includes("/ip/getSK") || url.includes("/api/dokv/storage") || url.includes("/api/share");
6717
+ }
6714
6718
  notifyListeners(request) {
6715
6719
  this.listeners.forEach((listener) => {
6716
6720
  try {
@@ -6730,7 +6734,8 @@ class NetworkInterceptor {
6730
6734
  if (headers.cid && this.decryptConfig.autoFetchKeys !== false) {
6731
6735
  try {
6732
6736
  const apiUrl = this.decryptConfig.keyApiUrl || "https://gw-card-pay.buyacard.cc/ip/getSK";
6733
- const response = await fetch(apiUrl, {
6737
+ const originalFetch = window.__originalFetch || window.fetch;
6738
+ const response = await originalFetch(apiUrl, {
6734
6739
  headers: {
6735
6740
  cid: headers.cid,
6736
6741
  client: headers.client || "S_WEB",
@@ -6781,10 +6786,12 @@ class NetworkInterceptor {
6781
6786
  let url = "";
6782
6787
  let requestHeaders = {};
6783
6788
  const startTime = Date.now();
6789
+ let isInternalRequest = false;
6784
6790
  const originalOpen = xhr.open;
6785
6791
  xhr.open = function(methodArg, urlArg, ...rest) {
6786
6792
  method = methodArg.toUpperCase();
6787
6793
  url = urlArg;
6794
+ isInternalRequest = self2.isInternalUrl(url);
6788
6795
  return originalOpen.apply(this, [methodArg, urlArg, ...rest]);
6789
6796
  };
6790
6797
  const originalSetRequestHeader = xhr.setRequestHeader;
@@ -6794,6 +6801,9 @@ class NetworkInterceptor {
6794
6801
  };
6795
6802
  const originalSend = xhr.send;
6796
6803
  xhr.send = function(body) {
6804
+ if (isInternalRequest) {
6805
+ return originalSend.call(this, body);
6806
+ }
6797
6807
  const requestData = {
6798
6808
  id: requestId,
6799
6809
  url,
@@ -6816,7 +6826,7 @@ class NetworkInterceptor {
6816
6826
  return originalSend.call(this, body);
6817
6827
  };
6818
6828
  xhr.addEventListener("readystatechange", function() {
6819
- if (xhr.readyState === XMLHttpRequest.DONE) {
6829
+ if (xhr.readyState === XMLHttpRequest.DONE && !isInternalRequest) {
6820
6830
  const endTime = Date.now();
6821
6831
  const requestData = self2.requests.get(requestId);
6822
6832
  if (requestData) {
@@ -6858,13 +6868,16 @@ class NetworkInterceptor {
6858
6868
  window.XMLHttpRequest.prototype = originalXHR.prototype;
6859
6869
  }
6860
6870
  interceptFetch() {
6861
- const originalFetch = window.fetch;
6871
+ const originalFetch = window.__originalFetch || window.fetch;
6862
6872
  const self2 = this;
6863
6873
  window.fetch = async function(input, init) {
6864
6874
  const requestId = self2.generateRequestId();
6865
6875
  const startTime = Date.now();
6866
6876
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
6867
6877
  const method = (init?.method || "GET").toUpperCase();
6878
+ if (self2.isInternalUrl(url)) {
6879
+ return originalFetch.call(this, input, init);
6880
+ }
6868
6881
  const requestHeaders = {};
6869
6882
  if (init?.headers) {
6870
6883
  if (init.headers instanceof Headers) {
@@ -7364,6 +7377,19 @@ const styles = `
7364
7377
  display: none;
7365
7378
  }
7366
7379
 
7380
+ /* 默认折叠headers */
7381
+ .request-details .detail-section.collapsible {
7382
+ /* 默认折叠状态 */
7383
+ }
7384
+
7385
+ .request-details .detail-section.collapsible:not(.expanded) .detail-content {
7386
+ display: none;
7387
+ }
7388
+
7389
+ .request-details .detail-section.collapsible:not(.expanded) .collapse-icon {
7390
+ transform: rotate(-90deg);
7391
+ }
7392
+
7367
7393
  .request-item.expanded .request-details {
7368
7394
  display: block;
7369
7395
  }
@@ -7382,6 +7408,45 @@ const styles = `
7382
7408
  padding-bottom: 4px;
7383
7409
  }
7384
7410
 
7411
+ .detail-title.highlight {
7412
+ color: #FFD700;
7413
+ font-size: 12px;
7414
+ background: rgba(255, 215, 0, 0.1);
7415
+ padding: 6px 8px;
7416
+ border-radius: 4px;
7417
+ border-bottom: 2px solid #FFD700;
7418
+ }
7419
+
7420
+ .detail-title.clickable {
7421
+ cursor: pointer;
7422
+ user-select: none;
7423
+ display: flex;
7424
+ align-items: center;
7425
+ gap: 4px;
7426
+ }
7427
+
7428
+ .detail-title.clickable:hover {
7429
+ background: rgba(76, 175, 80, 0.1);
7430
+ }
7431
+
7432
+ .collapse-icon {
7433
+ display: inline-block;
7434
+ transition: transform 0.2s;
7435
+ font-size: 10px;
7436
+ }
7437
+
7438
+ .detail-section.collapsible {
7439
+ position: relative;
7440
+ }
7441
+
7442
+ .detail-section.collapsible.collapsed .detail-content {
7443
+ display: none;
7444
+ }
7445
+
7446
+ .detail-section.collapsible.collapsed .collapse-icon {
7447
+ transform: rotate(-90deg);
7448
+ }
7449
+
7385
7450
  .detail-content {
7386
7451
  background: #222;
7387
7452
  padding: 8px;
@@ -7655,41 +7720,29 @@ async function createShareLink(requestData) {
7655
7720
  version: "1.2.0"
7656
7721
  }
7657
7722
  };
7658
- const response = await fetch("https://gw-card-pay.buyacard.cc/api/dokv/storage", {
7723
+ const originalFetch = window.__originalFetch || window.fetch;
7724
+ const response = await originalFetch("https://curl.bwg.leeguoo.com/api/share", {
7659
7725
  method: "POST",
7660
7726
  headers: {
7661
7727
  "Content-Type": "application/json"
7662
7728
  },
7663
7729
  body: JSON.stringify({
7664
- projectId: "curl-tool",
7665
- // 使用与原项目相同的项目ID
7666
- key: `share:${generateShareId()}`,
7667
- // 使用相同的key格式
7668
- data: shareData,
7669
- expireIn: 7 * 24 * 60 * 60 * 1e3
7670
- // 7天过期
7730
+ data: shareData
7671
7731
  })
7672
7732
  });
7673
7733
  const result = await response.json();
7674
- if (result.success && (result.id || result.key)) {
7675
- let shareId = result.id;
7676
- if (!shareId && result.key) {
7677
- shareId = result.key.replace("share:", "");
7678
- }
7679
- const shareUrl = `https://curl.bwg.leeguoo.com/share/${shareId}`;
7734
+ if (result.shareId) {
7735
+ const shareUrl = `https://curl.bwg.leeguoo.com/share/${result.shareId}`;
7680
7736
  console.log(`🔗 分享链接创建成功 (by Leo): ${shareUrl}`);
7681
7737
  return shareUrl;
7682
7738
  } else {
7683
- throw new Error(result.message || "创建分享失败");
7739
+ throw new Error(result.error || "创建分享失败");
7684
7740
  }
7685
7741
  } catch (error) {
7686
7742
  console.error("NetworkDebugger: 创建分享链接失败:", error);
7687
7743
  throw error;
7688
7744
  }
7689
7745
  }
7690
- function generateShareId() {
7691
- return Math.random().toString(36).substr(2, 10);
7692
- }
7693
7746
  function extractKeys(headers) {
7694
7747
  if (!headers) return "";
7695
7748
  return headers.keys || headers.cid || headers["x-api-key"] || "";
@@ -7808,7 +7861,7 @@ class DebugPanel {
7808
7861
  <div class="about-panel" data-panel="about" style="display: none;">
7809
7862
  <div style="padding: 20px; color: #fff; text-align: center;">
7810
7863
  <h2 style="margin: 0 0 20px 0;">🔓 PWTK 解密小工具</h2>
7811
- <p style="margin: 10px 0;">Version: 1.2.2</p>
7864
+ <p style="margin: 10px 0;">Version: 1.2.4</p>
7812
7865
  <p style="margin: 10px 0;">👨‍💻 Created by <strong>Leo (@leeguoo)</strong></p>
7813
7866
  <p style="margin: 10px 0;">📧 技术支持:请联系 Leo</p>
7814
7867
  <p style="margin: 10px 0;">🌐 分享服务:curl.bwg.leeguoo.com</p>
@@ -7961,44 +8014,49 @@ class DebugPanel {
7961
8014
  }
7962
8015
  renderRequestDetails(request) {
7963
8016
  let html = "";
7964
- if (Object.keys(request.headers).length > 0) {
8017
+ request.id.replace(/[^a-zA-Z0-9]/g, "");
8018
+ if (request.decryptedRequest) {
7965
8019
  html += `
7966
8020
  <div class="detail-section">
7967
- <div class="detail-title">请求头</div>
8021
+ <div class="detail-title highlight">🔓 解密请求数据</div>
7968
8022
  <div class="detail-content">
7969
- <table class="headers-table">
7970
- ${Object.entries(request.headers).map(
7971
- ([key, value]) => `<tr><td>${key}</td><td>${value}</td></tr>`
7972
- ).join("")}
7973
- </table>
8023
+ <div class="json-content">${this.formatData(request.decryptedRequest)}</div>
7974
8024
  </div>
7975
8025
  </div>
7976
8026
  `;
7977
8027
  }
7978
- if (request.requestBody) {
8028
+ if (request.decryptedResponse) {
7979
8029
  html += `
7980
8030
  <div class="detail-section">
7981
- <div class="detail-title">请求数据</div>
8031
+ <div class="detail-title highlight">🔓 解密响应数据</div>
7982
8032
  <div class="detail-content">
7983
- <div class="json-content">${this.formatData(request.requestBody)}</div>
8033
+ <div class="json-content">${this.formatData(request.decryptedResponse)}</div>
7984
8034
  </div>
7985
8035
  </div>
7986
8036
  `;
7987
8037
  }
7988
- if (request.decryptedRequest) {
8038
+ if (Object.keys(request.headers).length > 0) {
7989
8039
  html += `
7990
- <div class="detail-section">
7991
- <div class="detail-title">解密请求数据 🔓</div>
8040
+ <div class="detail-section collapsible collapsed">
8041
+ <div class="detail-title clickable" onclick="this.parentElement.classList.toggle('collapsed')">
8042
+ <span class="collapse-icon">▼</span> 请求头 (${Object.keys(request.headers).length})
8043
+ </div>
7992
8044
  <div class="detail-content">
7993
- <div class="json-content">${this.formatData(request.decryptedRequest)}</div>
8045
+ <table class="headers-table">
8046
+ ${Object.entries(request.headers).map(
8047
+ ([key, value]) => `<tr><td>${key}</td><td>${value}</td></tr>`
8048
+ ).join("")}
8049
+ </table>
7994
8050
  </div>
7995
8051
  </div>
7996
8052
  `;
7997
8053
  }
7998
8054
  if (request.responseHeaders && Object.keys(request.responseHeaders).length > 0) {
7999
8055
  html += `
8000
- <div class="detail-section">
8001
- <div class="detail-title">响应头</div>
8056
+ <div class="detail-section collapsible collapsed">
8057
+ <div class="detail-title clickable" onclick="this.parentElement.classList.toggle('collapsed')">
8058
+ <span class="collapse-icon">▼</span> 响应头 (${Object.keys(request.responseHeaders).length})
8059
+ </div>
8002
8060
  <div class="detail-content">
8003
8061
  <table class="headers-table">
8004
8062
  ${Object.entries(request.responseHeaders).map(
@@ -8009,22 +8067,22 @@ class DebugPanel {
8009
8067
  </div>
8010
8068
  `;
8011
8069
  }
8012
- if (request.responseBody) {
8070
+ if (request.requestBody && !request.decryptedRequest) {
8013
8071
  html += `
8014
8072
  <div class="detail-section">
8015
- <div class="detail-title">响应数据</div>
8073
+ <div class="detail-title">请求数据</div>
8016
8074
  <div class="detail-content">
8017
- <div class="json-content">${this.formatData(request.responseBody)}</div>
8075
+ <div class="json-content">${this.formatData(request.requestBody)}</div>
8018
8076
  </div>
8019
8077
  </div>
8020
8078
  `;
8021
8079
  }
8022
- if (request.decryptedResponse) {
8080
+ if (request.responseBody && !request.decryptedResponse) {
8023
8081
  html += `
8024
8082
  <div class="detail-section">
8025
- <div class="detail-title">解密响应数据 🔓</div>
8083
+ <div class="detail-title">响应数据</div>
8026
8084
  <div class="detail-content">
8027
- <div class="json-content">${this.formatData(request.decryptedResponse)}</div>
8085
+ <div class="json-content">${this.formatData(request.responseBody)}</div>
8028
8086
  </div>
8029
8087
  </div>
8030
8088
  `;
@@ -8405,7 +8463,7 @@ class NetworkDebugger {
8405
8463
  this.initialized = true;
8406
8464
  console.log(`
8407
8465
  ╔════════════════════════════════════════╗
8408
- ║ 🔓 PWTK 解密小工具 v1.2.2
8466
+ ║ 🔓 PWTK 解密小工具 v1.2.4
8409
8467
  ║ Created by Leo (@leeguoo) ║
8410
8468
  ║ 技术支持: 请联系 Leo ║
8411
8469
  ║ 分享服务: curl.bwg.leeguoo.com ║