@leeguoo/pwtk-network-debugger 1.2.22 → 1.2.24

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
@@ -7976,21 +7976,13 @@ async function createShareLink(requestData) {
7976
7976
  decryptedResponse: requestData.decryptedResponse,
7977
7977
  error: requestData.error,
7978
7978
  creator: "PWTK Network Debugger by Leo (@leeguoo)",
7979
- version: "1.2.22"
7979
+ version: "1.2.24"
7980
7980
  }
7981
7981
  };
7982
- const currentDomain = window.location.hostname;
7983
- const isOnCurlDomain = currentDomain === "curl.bwg.leeguoo.com" || currentDomain === "localhost";
7984
7982
  const originalFetch = window.__originalFetch || window.fetch;
7985
- let apiUrl;
7983
+ const apiUrl = "https://curl.bwg.leeguoo.com/api/share";
7984
+ logger.debug("使用分享API:", apiUrl);
7986
7985
  let response;
7987
- if (isOnCurlDomain) {
7988
- apiUrl = "/api/share";
7989
- logger.debug("使用同域API:", apiUrl);
7990
- } else {
7991
- apiUrl = "https://curl.bwg.leeguoo.com/api/share";
7992
- logger.debug("使用跨域API:", apiUrl);
7993
- }
7994
7986
  try {
7995
7987
  response = await originalFetch(apiUrl, {
7996
7988
  method: "POST",
@@ -8065,7 +8057,7 @@ function formatAsCurl(requestData) {
8065
8057
  }
8066
8058
  return curl;
8067
8059
  }
8068
- class DebugPanel {
8060
+ const _DebugPanel = class _DebugPanel {
8069
8061
  constructor(interceptor, config = {}) {
8070
8062
  this.isDragging = false;
8071
8063
  this.isResizing = false;
@@ -8074,17 +8066,22 @@ class DebugPanel {
8074
8066
  this.consoleHistory = [];
8075
8067
  this.requestsCache = [];
8076
8068
  this.interceptor = interceptor;
8069
+ const savedConfig = this.loadConfig();
8077
8070
  this.config = {
8078
8071
  position: "bottom-right",
8079
8072
  theme: "dark",
8080
8073
  minimized: false,
8081
8074
  showConsole: true,
8075
+ ...savedConfig,
8076
+ // 先应用保存的配置
8082
8077
  ...config
8078
+ // 再应用传入的配置(优先级最高)
8083
8079
  };
8084
8080
  this.createPanel();
8085
8081
  this.bindEvents();
8086
8082
  this.startListening();
8087
8083
  logger.setPanel(this);
8084
+ this.loadPosition();
8088
8085
  }
8089
8086
  createPanel() {
8090
8087
  if (!document.getElementById("network-debugger-styles")) {
@@ -8515,6 +8512,7 @@ Created by Leo (@leeguoo)`);
8515
8512
  }
8516
8513
  });
8517
8514
  }
8515
+ this.saveConfig();
8518
8516
  }
8519
8517
  toggleFullscreen() {
8520
8518
  this.container.classList.toggle("fullscreen");
@@ -8688,6 +8686,9 @@ Created by Leo (@leeguoo)`);
8688
8686
  handleMouseUp() {
8689
8687
  if (this.isDragging || this.isResizing) {
8690
8688
  this.container.style.transition = "all 0.3s ease";
8689
+ if (this.isDragging) {
8690
+ this.savePosition();
8691
+ }
8691
8692
  }
8692
8693
  this.isDragging = false;
8693
8694
  this.isResizing = false;
@@ -8704,7 +8705,89 @@ Created by Leo (@leeguoo)`);
8704
8705
  const styles2 = document.getElementById("network-debugger-styles");
8705
8706
  if (styles2) styles2.remove();
8706
8707
  }
8707
- }
8708
+ // ========== localStorage 方法 ==========
8709
+ /**
8710
+ * 从 localStorage 加载配置
8711
+ */
8712
+ loadConfig() {
8713
+ try {
8714
+ const saved = localStorage.getItem(_DebugPanel.STORAGE_KEY);
8715
+ if (saved) {
8716
+ const config = JSON.parse(saved);
8717
+ logger.debug("加载保存的配置:", config);
8718
+ return config;
8719
+ }
8720
+ } catch (error) {
8721
+ logger.error("加载配置失败:", error);
8722
+ }
8723
+ return {};
8724
+ }
8725
+ /**
8726
+ * 保存配置到 localStorage
8727
+ */
8728
+ saveConfig() {
8729
+ try {
8730
+ const configToSave = {
8731
+ position: this.config.position,
8732
+ theme: this.config.theme,
8733
+ minimized: this.config.minimized,
8734
+ showConsole: this.config.showConsole
8735
+ };
8736
+ localStorage.setItem(_DebugPanel.STORAGE_KEY, JSON.stringify(configToSave));
8737
+ logger.debug("配置已保存:", configToSave);
8738
+ } catch (error) {
8739
+ logger.error("保存配置失败:", error);
8740
+ }
8741
+ }
8742
+ /**
8743
+ * 加载保存的位置
8744
+ */
8745
+ loadPosition() {
8746
+ try {
8747
+ const positionKey = `${_DebugPanel.STORAGE_KEY}-position`;
8748
+ const saved = localStorage.getItem(positionKey);
8749
+ if (saved) {
8750
+ const position = JSON.parse(saved);
8751
+ if (position.left !== void 0) {
8752
+ this.container.style.left = position.left + "px";
8753
+ }
8754
+ if (position.top !== void 0) {
8755
+ this.container.style.top = position.top + "px";
8756
+ }
8757
+ if (position.right !== void 0) {
8758
+ this.container.style.right = position.right + "px";
8759
+ }
8760
+ if (position.bottom !== void 0) {
8761
+ this.container.style.bottom = position.bottom + "px";
8762
+ }
8763
+ logger.debug("加载保存的位置:", position);
8764
+ }
8765
+ } catch (error) {
8766
+ logger.error("加载位置失败:", error);
8767
+ }
8768
+ }
8769
+ /**
8770
+ * 保存当前位置
8771
+ */
8772
+ savePosition() {
8773
+ try {
8774
+ const positionKey = `${_DebugPanel.STORAGE_KEY}-position`;
8775
+ const rect = this.container.getBoundingClientRect();
8776
+ const position = {
8777
+ left: rect.left,
8778
+ top: rect.top,
8779
+ right: window.innerWidth - rect.right,
8780
+ bottom: window.innerHeight - rect.bottom
8781
+ };
8782
+ localStorage.setItem(positionKey, JSON.stringify(position));
8783
+ logger.debug("位置已保存:", position);
8784
+ } catch (error) {
8785
+ logger.error("保存位置失败:", error);
8786
+ }
8787
+ }
8788
+ };
8789
+ _DebugPanel.STORAGE_KEY = "pwtk-debugger-config";
8790
+ let DebugPanel = _DebugPanel;
8708
8791
  class NetworkDebugger {
8709
8792
  constructor() {
8710
8793
  this.interceptor = null;