From 4d645fa3f74ff047c6b24ea5a6e1253f597a8bf6 Mon Sep 17 00:00:00 2001 From: Long Bui <55575791+builong1999@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:20:42 +0700 Subject: [PATCH] Release local storage saving --- index.css | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- index.js | 6 +++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/index.css b/index.css index f23afc1..232ee03 100644 --- a/index.css +++ b/index.css @@ -1 +1,52 @@ -#barcode-submit{background-color: #00A09D; color: white; width: 100%; font-size: 12px; font-weight: 500;}#barcode-input{width: 100%; font-size: 12px !important;}.page{min-width: 200px; font-size: 10px;}.page p{margin-bottom: 0px;}.detail .d-collapse{cursor: pointer;}.detail .d-collapse img{height: 15px!important;}.detail .d-collapse.show .show,.detail .d-collapse.show .show{display: inline-block;}.detail .d-collapse .show{display: none;}.detail .d-collapse.show .hide{display: none;}.detail .d-collapse .hide{display: inline-block;}.detail .d-collapse .input{margin-top: 5px; font-size: 12px;} \ No newline at end of file +#barcode-submit { + background-color: #00A09D; + color: white; + width: 100%; + font-size: 12px; + font-weight: 500; +} + +#barcode-input { + width: 100%; + font-size: 12px !important; + height:100px +} + +.page { + min-width: 200px; + font-size: 10px; +} + +.page p { + margin-bottom: 0px; +} + +.detail .d-collapse { + cursor: pointer; +} + +.detail .d-collapse img { + height: 15px !important; +} + +.detail .d-collapse.show .show, +.detail .d-collapse.show .show { + display: inline-block; +} + +.detail .d-collapse .show { + display: none; +} + +.detail .d-collapse.show .hide { + display: none; +} + +.detail .d-collapse .hide { + display: inline-block; +} + +.detail .d-collapse .input { + margin-top: 5px; + font-size: 12px; +} \ No newline at end of file diff --git a/index.js b/index.js index c1ca7f7..e858da0 100644 --- a/index.js +++ b/index.js @@ -1 +1,5 @@ -let submitButton=document.getElementById("barcode-submit"),inputText=document.getElementById("barcode-input"),barcode=document.getElementById("barcode-input"),selector=document.getElementById("element-input");for(let e of document.querySelectorAll(".hdl-button"))e.addEventListener("click",()=>{let e=document.querySelector(".d-collapse"),t=e.classList.contains("hide")?"show":"hide";e.classList.remove("hide","show"),e.classList.add(t)});async function sendEvent(){let[e]=await chrome.tabs.query({active:!0,currentWindow:!0});chrome.scripting.executeScript({target:{tabId:e.id},function:simulateBarcodeScan,args:[barcode.value,selector.value]})}function simulateBarcodeScan(e,t){if(""===t||"body"===t||null===(t=document.querySelector(t))){t=document.querySelector("body");for(let n=0;n{10!=e.keyCode&&13!=e.keyCode||!e.ctrlKey||sendEvent()}),submitButton.addEventListener("click",sendEvent); \ No newline at end of file +let submitButton=document.getElementById("barcode-submit"),inputText=document.getElementById("barcode-input"),barcode=document.getElementById("barcode-input"),selector=document.getElementById("element-input");for(let e of document.querySelectorAll(".hdl-button")) +e.addEventListener("click",()=>{let e=document.querySelector(".d-collapse"),t=e.classList.contains("hide")?"show":"hide";e.classList.remove("hide","show"),e.classList.add(t)});chrome.storage.sync.get(["barcodeStorage"],function(res){if(res){if(res?.barcodeStorage){inputText.value=res.barcodeStorage}}});inputText.addEventListener('keyup',evt=>{chrome.storage.sync.set({'barcodeStorage':inputText.value})}) +async function sendEvent(){let[e]=await chrome.tabs.query({active:!0,currentWindow:!0});chrome.scripting.executeScript({target:{tabId:e.id},function:simulateBarcodeScan,args:[barcode.value,selector.value]})} +function simulateBarcodeScan(e,t){if(""===t||"body"===t||null===(t=document.querySelector(t))){t=document.querySelector("body");for(let n=0;n{(10!=e.keyCode&&13!=e.keyCode)||!e.ctrlKey||sendEvent()}),submitButton.addEventListener("click",sendEvent) \ No newline at end of file