Skip to content

Instantly share code, notes, and snippets.

@lunamoth
Created February 15, 2025 11:57
Show Gist options
  • Save lunamoth/4fb6373a5dd1cc795c4bc2b689e6c9de to your computer and use it in GitHub Desktop.
Save lunamoth/4fb6373a5dd1cc795c4bc2b689e6c9de to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 후잉 입력 자동 포커스
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 후잉 입력 페이지에서 아이템 입력 필드에 자동으로 커서를 위치시킵니다.
// @author You
// @match https://whooing.com/*
// @grant none
// @run-at document-start // document-start로 변경
// ==/UserScript==
(function() {
'use strict';
function focusInput() {
// 입력 필드를 찾습니다. (속성 기반 선택 - 더 안정적)
const inputElement = document.querySelector('input[name="item_disp"][placeholder="아이템"]');
if (inputElement) {
inputElement.focus(); // 찾았으면 포커스
} else {
console.warn("후잉 입력 요소를 찾을 수 없습니다."); // 못 찾으면 경고
}
}
// 페이지가 후잉 입력 페이지인지 확인하는 함수
function isInsertPage() {
return [removed].href.startsWith('https://whooing.com/#main/insert');
}
// MutationObserver를 사용하여 동적으로 로드되는 요소를 감지합니다.
const observer = new MutationObserver((mutations) => {
if (isInsertPage() && document.querySelector('input[name="item_disp"][placeholder="아이템"]')) {
focusInput();
observer.disconnect(); // 요소를 찾으면 감시 중단 (성능 향상)
}
});
// document-start에서 실행될 때, DOMContentLoaded를 기다리지 않고 바로 감시 시작.
observer.observe(document.documentElement, { childList: true, subtree: true });
})();
@zidell
Copy link

zidell commented Feb 15, 2025

간단하게 아래의 스크립트로도 동작이 될 듯합니다.

$(window).on('hashchange.custom', function() {
    if (location.hash === '#main/insert') {
        setTimeout(() => {
            $('input[name="item_disp"]').focus();
        }, 500);
    }
}).trigger('hashchange.custom');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment