bid-extension/bid-extension/content.js

28 lines
2.7 KiB
JavaScript

let t=null,d="";const a=()=>{const e="bid-extensions";if(document.getElementById(e))return;const o=document.createElement("div");o.id=e,document.body.appendChild(o);const s=document.createElement("script");s.src=chrome.runtime.getURL("inject-ui.js"),s.type="module",document.body.appendChild(s),window.addEventListener("message",i=>{if(i.source!==window)return;const n=i.data;n?.direction==="to-content"&&(n.type==="SAVE_KEY"&&chrome.storage.local.set({key:n.payload},()=>{console.log("✅ Key saved:",n.payload)}),n.type==="GET_KEY"&&chrome.storage.local.get(["key"],r=>{window.postMessage({direction:"from-content",type:"GET_KEY_RESULT",value:r.key},"*")}))})};document.addEventListener("selectionchange",()=>{d=window?.getSelection()?.toString().trim()});document.addEventListener("mousedown",e=>{t&&!t.contains(e.target)&&(t.style.display="none")});document.addEventListener("mouseup",e=>{d&&setTimeout(()=>{l(e.pageX,e.pageY)},10)});document.addEventListener("keydown",function(e){e.ctrlKey&&e.code==="Space"&&(e.preventDefault(),window.scrollTo({top:0,behavior:"smooth"}))});function p(){t=document.createElement("div"),t.innerHTML=`
<div style="display: flex; flex-direction: column; gap: 8px;">
<button id="esearch-btn" style="
padding: 3px 3px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
width: 80px;
font-weight: bold;
">🔍 ESearch</button>
<button id="erp-btn" style="
padding: 3px 3px;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
width: 80px;
font-weight: bold;
">🔍 ERP VPN</button>
</div>
`,Object.assign(t.style,{position:"absolute",display:"none",zIndex:999999,backgroundColor:"#fff",color:"#000",border:"1px solid #ccc",borderRadius:"5px",padding:"8px",boxShadow:"0 2px 6px rgba(0,0,0,0.2)",fontSize:"14px"}),document.body.appendChild(t),document.getElementById("esearch-btn")?.addEventListener("click",()=>{c(`https://esearch.danielvu.com?keyword=${d}`)}),document.getElementById("erp-btn")?.addEventListener("click",()=>{c(`https://int.ipsupply.com.au/erptools/001_search-vpn?search=${d}`)})}function l(e,o){t.style.top=`${o+10}px`,t.style.left=`${e+10}px`,t.style.display="block"}function c(e){chrome.runtime.sendMessage({type:"SEARCH",url:e}),t.style.display="none"}const u=()=>{const e=window.location.href;(Object.values({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"}).some(i=>e.includes(i))||e.includes("https://members.brokerbin.com/"))&&a(),p()};u();