AutoRemoveReadonly

自动去除扫码输入框readonly属性并定位!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         AutoRemoveReadonly
// @namespace    http://tampermonkey.net/
// @version      2025-01-16 14:57
// @description  自动去除扫码输入框readonly属性并定位!
// @author       You
// @license      MIT
// @match        http://192.168.126.17/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 创建一个观察器实例并定义一个回调函数
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
                var targetDiv = mutation.target;
                if (targetDiv.classList.contains('panel') && targetDiv.classList.contains('window')) {
                    var displayStyle = targetDiv.style.display;
                    if (displayStyle === 'block') {
                        // 定期检查元素是否加载
                        const checkElement = setInterval(() => {
                            console.log("执行了");
                            const inputElement = document.querySelector('#div1042188 .ck-edit-border');
                            if (inputElement) {
                                // 取消readonly属性
                                if (inputElement.getAttribute("readonly") !== null) {
                                    inputElement.removeAttribute('readonly');
                                }
                                // 定位光标
                                inputElement.focus();
                                // 检测输入框,有内容,则全部选择
                                if (inputElement.value.trim() !== '') {
                                    inputElement.select();
                                }
                            }
                        }, 1000); // 每1000毫秒(1秒)检查一次
                    } else if (displayStyle === 'none') {
                        // 重置标志变量为false
                        hasShownAlert = false;
                    }
                }
            }
        });
    });

    // 提供一个被观察目标节点,以及观察选项(观察属性变化)
    var config = { attributes: true, subtree: true, attributeFilter: ['style'] };
    var targetNode = document.body; // 监测整个文档的body部分

    // 开始观察
    observer.observe(targetNode, config);

    // 你可以在适当的时候停止观察
    // observer.disconnect();

})();