diff --git a/.DS_Store b/.DS_Store index 30b1a79..43f9de3 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000..bab0724 Binary files /dev/null and b/assets/.DS_Store differ diff --git a/assets/css/index.css b/assets/css/index.css index 68bea98..97743ce 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -20,6 +20,7 @@ display: flex; flex-direction: column; gap: 10px; + width: 100%; } #bid-extension h2 { diff --git a/content.js b/content.js index 31be8d2..296b74e 100644 --- a/content.js +++ b/content.js @@ -1,6 +1,6 @@ const CONFIG = { - API_BASE_URL: "http://localhost:4000/api/v1", - // API_BASE_URL: "https://bids.apactech.io/api/v1", + // API_BASE_URL: "http://localhost:4000/api/v1", + API_BASE_URL: "https://bids.apactech.io/api/v1", }; let PREV_DATA = null; @@ -23,34 +23,57 @@ function extractDomain(url) { } } +const webs = { + grays: "https://www.grays.com", + langtons: "https://www.langtons.com.au", + lawsons: "https://www.lawsons.com.au", + pickles: "https://www.pickles.com.au", + allbids: "https://www.allbids.com.au", +}; + function extractModelId(url) { switch (extractDomain(url)) { - case "https://www.grays.com": { + case webs.grays: { const match = url.match(/\/lot\/([\d-]+)\//); return match ? match[1] : null; } - case "https://www.langtons.com.au": { + case webs.langtons: { const match = url.match(/auc-var-\d+/); return match[0]; } - case "https://www.lawsons.com.au": { + case webs.lawsons: { const match = url.split("_"); return match ? match[1] : null; } - case "https://www.pickles.com.au": { + case webs.pickles: { const model = url.split("/").pop(); return model ? model : null; } + case webs.allbids: { + const match = url.match(/-(\d+)(?:[\?#]|$)/); + return match ? match[1] : null; + } } } -const showPage = async (pageLink = "pages/popup/popup.html") => { - const res = await fetch(chrome.runtime.getURL(pageLink)); - const html = await res.text(); +const isValidUrl = (url) => { + return !!Object.keys(webs).find((item) => url.includes(webs[item])); +}; - const wrapper = document.createElement("div"); - wrapper.innerHTML = html; - document.body.appendChild(wrapper); +const showPage = async (pageLink = "pages/popup/popup.html") => { + const url = window.location.href; // sửa lỗi ở đây + + if (!isValidUrl(url)) return; + try { + const res = await fetch(chrome.runtime.getURL(pageLink)); + const html = await res.text(); + + const wrapper = document.createElement("div"); + wrapper.innerHTML = html; + document.body.appendChild(wrapper); + } catch (err) { + console.error("Failed to load popup page:", err); + } }; const getKey = () => { @@ -360,13 +383,6 @@ const showInfo = async (model, formElements) => { style.href = chrome.runtime.getURL("assets/css/index.css"); document.head.appendChild(style); - const script = document.createElement("script"); - script.type = "module"; - script.src = chrome.runtime.getURL("pages/popup/popup.js"); - script.defer = true; - - document.body.appendChild(script); - handleSaveKey(); const currentUrl = window.location.href; diff --git a/manifest.json b/manifest.json index b07736c..b345cce 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Bid Extension", - "version": "1.0", + "version": "1.2", "description": "Bid Extension", "action": { "default_popup": "pages/popup/popup.html", diff --git a/pages/.DS_Store b/pages/.DS_Store new file mode 100644 index 0000000..9fa9e9a Binary files /dev/null and b/pages/.DS_Store differ diff --git a/pages/popup/popup.html b/pages/popup/popup.html index 68ead10..85744f7 100644 --- a/pages/popup/popup.html +++ b/pages/popup/popup.html @@ -1,6 +1,6 @@
@@ -90,8 +89,8 @@ style=" display: none; position: fixed; - bottom: 90px; - left: 20px; + bottom: 170px; + right: 20px; z-index: 9999; background-color: #1e1e1e; border-radius: 12px;