Last active
June 21, 2025 01:42
-
-
Save cwsaylor/d56eefa0c7724b94f4cbe5672c28002f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name ShipStation Allow Manual Focus Only | |
// @namespace http://tampermonkey.net/ | |
// @version 1.3 | |
// @description Only allow scan input to be focused by mouse click | |
// @match https://*.shipstation.com/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const SCAN_INPUT_ID = 'scan-search-box'; | |
let allowFocus = false; | |
function preventAutoFocus(input) { | |
// Block programmatic or keyboard focus | |
input.addEventListener('focus', (e) => { | |
if (!allowFocus) { | |
input.blur(); | |
e.preventDefault(); | |
e.stopPropagation(); | |
} | |
}); | |
// Detect manual clicks to allow focus temporarily | |
input.addEventListener('mousedown', () => { | |
allowFocus = true; | |
}); | |
// Once they leave the field, reset | |
input.addEventListener('blur', () => { | |
allowFocus = false; | |
}); | |
} | |
function waitForInputAndApply() { | |
const input = document.getElementById(SCAN_INPUT_ID); | |
if (input) { | |
preventAutoFocus(input); | |
return true; | |
} | |
return false; | |
} | |
// ShipStation is an SPA, so poll until the input appears | |
const interval = setInterval(() => { | |
if (waitForInputAndApply()) { | |
clearInterval(interval); | |
} | |
}, 300); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment