content-script.js 1 KB
chrome.runtime.sendMessage({
  type: "sessionStorage",
  value: window.sessionStorage,
});

chrome.runtime.onMessage.addListener((res) => {
  const { type } = res;
  switch (type) {
    case "setSessionStorage":
      window.sessionStorage.setItem(res.key, res.value);
      break;
    case "removeSessionStorage":
      window.sessionStorage.removeItem(res.key);
      break;
    case "reload":
      window.location.reload();
      break;
    case "getLocalStorage":
      chrome.runtime.sendMessage(window.sessionStorage);
      break;
    default:
      return;
  }
});

function injectCustomJs(jsPath) {
  jsPath = jsPath || "inject.js";
  var temp = document.createElement("script");
  temp.setAttribute("type", "module");
  temp.setAttribute("data-namespace", "qx-developer-tool-inject");
  temp.src = chrome.extension.getURL(jsPath);
  temp.onload = function () {
    // 放在页面不好看,执行完后移除掉
    // this.parentNode.removeChild(this);
  };
  document.body.appendChild(temp);
}

injectCustomJs();