diff --git a/.DS_Store b/.DS_Store
index 70fdd9b..b3e0eb6 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/background.js b/background.js
index 4cc32a3..bd5877c 100644
--- a/background.js
+++ b/background.js
@@ -1,10 +1,13 @@
-chrome.commands.onCommand.addListener(function (command) {
- if (command === "open_plugin") {
- chrome.windows.create({
- url: "popup.html",
- type: "popup",
- width: 640,
- height: 800
- });
- }
+// 仅在插件安装时设置默认 popup 页面,不再在 startup 中干扰当前 UI
+chrome.runtime.onInstalled.addListener(() => {
+ chrome.storage.local.get(["token", "loginAt"], (res) => {
+ const maxAge = 24 * 60 * 60 * 1000; // 1天有效期
+ const now = Date.now();
+
+ if (!res.token || !res.loginAt || (now - res.loginAt > maxAge)) {
+ chrome.action.setPopup({ popup: "login.html" });
+ } else {
+ chrome.action.setPopup({ popup: "popup.html" });
+ }
+ });
});
diff --git a/login.html b/login.html
new file mode 100644
index 0000000..bdc66c4
--- /dev/null
+++ b/login.html
@@ -0,0 +1,59 @@
+
+
+
+
+ 知识库系统登录
+
+
+
+知识库系统登录
+
+
+
+
+
+
+
+
+
diff --git a/login.js b/login.js
new file mode 100644
index 0000000..b7ff31d
--- /dev/null
+++ b/login.js
@@ -0,0 +1,42 @@
+const TOKEN_EXPIRE_MS = 24 * 60 * 60 * 1000; // 默认保留 1天
+
+document.getElementById("loginBtn").addEventListener("click", async () => {
+ const username = document.getElementById("username").value.trim();
+ const password = document.getElementById("password").value.trim();
+ const errorBox = document.getElementById("errorBox");
+ errorBox.textContent = "";
+
+ if (!username || !password) {
+ errorBox.textContent = "请输入用户名和密码";
+ return;
+ }
+
+ try {
+ const res = await fetch("http://app.wisdompulse.cn/api/v1/user/login", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ username, password })
+ });
+
+ const data = await res.json();
+ if (res.ok && data.token) {
+ await chrome.storage.local.set({
+ token: data.token,
+ username: data.username || username,
+ loginAt: Date.now()
+ });
+ chrome.action.setPopup({ popup: "popup.html" });
+ window.location.href = "popup.html";
+ } else {
+ errorBox.textContent = data.message || "登录失败";
+ }
+ } catch (err) {
+ errorBox.textContent = "网络错误,请稍后重试";
+ }
+});
+
+document.addEventListener("keydown", (e) => {
+ if (e.key === "Enter") {
+ document.getElementById("loginBtn").click();
+ }
+});
diff --git a/manifest.json b/manifest.json
index 8e21a7e..53e49f6 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "渠道应用开发部知识库",
- "version": "1.1",
+ "version": "1.2",
"description": "通过关键词快速搜索内部文档",
"permissions": ["storage"],
"host_permissions": [
@@ -11,16 +11,8 @@
"background": {
"service_worker": "background.js"
},
- "commands": {
- "open_plugin": {
- "suggested_key": {
- "default": "Alt+K"
- },
- "description": "打开渠道应用开发部知识库插件"
- }
- },
"action": {
- "default_popup": "popup.html",
+ "default_popup": "login.html",
"default_icon": {
"16": "icon.png",
"48": "icon.png",
diff --git a/popup.html b/popup.html
index adbf4a5..1bf4206 100644
--- a/popup.html
+++ b/popup.html
@@ -8,9 +8,15 @@