The script automatically focuses on the ISBN input field after submission. Very useful when working with barcode scanner app.
- Tampermoneky
- Click this link
// ==UserScript== | |
// @name Focus and Autofocus ISBN Input | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0.0 | |
// @description Automatically focuses and selects text in the ISBN input after saving a product. | |
// @author Yukai | |
// @match https://www.taaze.tw/addProdUsed.html?typeFlg=IB | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=taaze.tw | |
// @downloadURL https://gist.githubusercontent.com/Yukaii/9d1893b134b5721b53622834385fa956/raw/taaze-isbn-helper.user.js | |
// @updateURL https://gist.githubusercontent.com/Yukaii/9d1893b134b5721b53622834385fa956/raw/taaze-isbn-helper.user.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to handle the button click | |
function handleButtonClick() { | |
const isbnInput = document.getElementById('isbnInput'); | |
if (isbnInput) { | |
// Add autofocus attribute | |
isbnInput.setAttribute('autofocus', 'autofocus'); | |
// Focus and select the text in the input | |
isbnInput.focus(); | |
isbnInput.select(); | |
} | |
} | |
// Add event listener to the button | |
const addButton = document.getElementById('addBtn'); | |
if (addButton) { | |
addButton.addEventListener('click', handleButtonClick); | |
} | |
})(); |