diff --git a/background.js b/background.js new file mode 100644 index 0000000..1f4f883 --- /dev/null +++ b/background.js @@ -0,0 +1,10 @@ +chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { + if (changeInfo.status === 'complete' && tab.url == "https://shopkager.com/cart/detail") { + chrome.scripting + .executeScript({ + target: { tabId }, + files: ["inject.js"], + }) + .then(() => console.log("script injected")); + } +}); diff --git a/inject.js b/inject.js new file mode 100644 index 0000000..26a6f9a --- /dev/null +++ b/inject.js @@ -0,0 +1,134 @@ + +var head = document.getElementsByTagName('HEAD')[0]; +var link = document.createElement('link'); +link.rel = 'stylesheet'; +link.type = 'text/css'; +link.href = 'https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.1/css/mdb.min.css'; +head.appendChild(link); + + + + +const body = document.getElementsByTagName("body"); +const modal = document.createElement("div"); +modal.className = "modal fade right"; +modal.tabIndex = "-1"; +modal.id = "modal"; +modal.ariaHidden = "false"; +const modaldialog = document.createElement("div"); +modaldialog.className = "modal-dialog modal-side modal-top-right modal-notify "; +const modalcontent = document.createElement("div"); +modalcontent.className = "modal-content"; +const modalheader = document.createElement("div"); +modalheader.className = "modal-header"; +const closebtn = document.createElement("button"); +closebtn.type = "button"; +closebtn.className = "close"; +closebtn.ariaLabel = "close"; +closebtn.id = "close"; +closebtn.onclick = function () { + let d = document.getElementById('modal') + d.style.display = "none" +}; +const span = document.createElement("span"); +span.ariaHidden = "true"; +span.className = "text-dark"; +span.innerHTML = "×"; +closebtn.appendChild(span); + +const modaltitle = document.createElement("h4"); +modaltitle.className = "modal-title text-dark" +modaltitle.textContent = "Pay With CIEF"; + + +const ciflogo = document.createElement("img"); +ciflogo.className = "image-fluid"; +ciflogo.style = 'margin-top: 30px; width: 100%; height: 60%; max-height: 60px !important;'; +ciflogo.src = "https://www.cief-malaysia.com/wp-content/uploads/2022/10/cropped-cief-dark-2.png"; +// ciflogo.src ="https://www.cief-malaysia.com/wp-content/uploads/2018/05/cropped-CIEF-logo-min-1-32x32.png"; + + + +const modalbody = document.createElement("div"); +modalbody.className = "modal-body"; +const bodyrow = document.createElement("div"); +bodyrow.className = "row"; +const col3 = document.createElement("div"); +col3.className = "col-4 "; +col3.appendChild(ciflogo); +bodyrow.appendChild(col3); +const col9 = document.createElement("div"); +col9.className = "col-8"; +const discription = document.createElement("p"); +discription.textContent = " Following a spike in demand for Alipay pay-on-behalf payments and the subsequent freezing of a significant number of accounts, we have finally found a solution! "; +const cardtext = document.createElement("p"); +cardtext.className = "card-text"; +cardtext.textContent = "blah blah blah"; +col9.appendChild(discription); +bodyrow.appendChild(col9); +modalbody.appendChild(bodyrow); + +const modalfooter = document.createElement("div"); +modalfooter.className = "modal-footer justify-content-center"; +const paywithcief = document.createElement("button"); +paywithcief.className = "btn btn-danger"; +paywithcief.textContent = "pay with cief"; +paywithcief.onclick = function (){extractdata()} +const nothanks = document.createElement("button"); +nothanks.className = "btn btn-outline-danger waves-effect"; +nothanks.textContent = "No, thanks"; +nothanks.onclick = function () { + let d = document.getElementById('modal') + d.style.display = "none" +}; +modalfooter.appendChild(paywithcief); +modalfooter.appendChild(nothanks); + +modalheader.appendChild(modaltitle); +modalheader.appendChild(closebtn); +modalcontent.appendChild(modalheader); +modalcontent.appendChild(modalbody); +modalcontent.appendChild(modalfooter); +modaldialog.appendChild(modalcontent); +modal.appendChild(modaldialog); + + +document.body.appendChild(modal); + +document.querySelector(".modal").classList.add("show"); +document.querySelector(".modal").style.display = "block"; + +function extractdata() { + var table1 = document.getElementsByTagName('table')[0]; + for (var i = 0; i < table1.tBodies.length; i++) { + + var rows = table1.tBodies[i].rows; + for (var j = 0; j < rows.length; j++) { + + var cells = rows[j].cells; + + for (var k = 0; k < cells.length; k++) { + if (k == 2) { + console.log('product name:', cells[2].children[0].children[0].textContent); + } + if (k == 3) { + + console.log('product price:', cells[3].textContent); + } + } + } + }; + + redirect(); + +} + +function redirect () { + setTimeout(billplzurl, 2000); + + } + +function billplzurl() { + document.location.href = 'https://dev.exchange.cief-malaysia.com'; + } + diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..460ded4 --- /dev/null +++ b/manifest.json @@ -0,0 +1,24 @@ + +{ + "manifest_version": 3, + "name": "Pay with cief", + "version": "1.0", + "description": "A Chrome extension that allows customers to pay with cief on the 1688.com checkout page.", + "permissions": [ + "activeTab", + "tabs", + "nativeMessaging", + "scripting", + "notifications" + + ], + + "background": { + "service_worker": "background.js" + }, + + "host_permissions": [ + "https://1688.com/", + "https://shopkager.com/" + ] +} \ No newline at end of file