机场密码管理器支持

修改机场网站的登录表单,使其能被密码管理器自动识别

当前为 2025-09-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         机场密码管理器支持
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  修改机场网站的登录表单,使其能被密码管理器自动识别
// @author       Seameee
// @match        https://www.anyway.best/*
// @match        https://dash.lyrebird.cloud/*
// @match        https://shenlong.wiki/*
// @match        https://xes.al/*
// @match        https://www.ctc.run/*
// @match        https://flybit.vip/*
// @match        https://www.ppofo.work/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 配置对象
    const config = {
        emailSelector: 'input[placeholder="邮箱"]',
        passwordSelector: 'input[placeholder="密码"]',
        maxAttempts: 50, // 最大尝试次数
        interval: 300    // 检查间隔(毫秒)
    };

    // 修改输入框属性以支持密码管理器
    function modifyInputFields() {
        const emailInput = document.querySelector(config.emailSelector);
        const passwordInput = document.querySelector(config.passwordSelector);

        if (emailInput && passwordInput) {
            console.log('找到登录表单,开始修改属性...');

            // 修改邮箱输入框
            if (emailInput.type === 'text') {
                emailInput.type = 'email';
                emailInput.setAttribute('autocomplete', 'username');
                emailInput.setAttribute('name', 'email');
                emailInput.setAttribute('id', 'email');
                console.log('✅ 邮箱输入框已修改');
            }

            // 修改密码输入框
            if (passwordInput.type === 'password') {
                passwordInput.setAttribute('autocomplete', 'current-password');
                passwordInput.setAttribute('name', 'password');
                passwordInput.setAttribute('id', 'password');
                console.log('✅ 密码输入框已修改');
            }

            // 为表单添加 autocomplete 属性
            const form = emailInput.closest('form') || passwordInput.closest('form');
            if (form) {
                form.setAttribute('autocomplete', 'on');
                console.log('✅ 表单已添加 autocomplete 属性');
            }

            return true; // 修改成功
        }
        return false; // 未找到元素
    }

    // 使用 MutationObserver 监控DOM变化
    function setupMutationObserver() {
        const observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes.length > 0) {
                    // 检查是否有新节点添加
                    modifyInputFields();
                }
            });
        });

        // 开始观察整个文档
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        console.log('🔍 DOM观察器已启动');
    }

    // 轮询检查元素是否存在
    function pollForElements() {
        let attempts = 0;

        const intervalId = setInterval(() => {
            attempts++;

            if (modifyInputFields()) {
                clearInterval(intervalId);
                console.log('🎉 脚本执行完成');
                return;
            }

            if (attempts >= config.maxAttempts) {
                clearInterval(intervalId);
                console.log('⚠️ 达到最大尝试次数,停止检查');
            }
        }, config.interval);
    }

    // 页面加载完成后执行
    function init() {
        console.log('🚀 Anyway.best 密码管理器支持脚本启动');

        // 立即尝试修改
        if (modifyInputFields()) {
            console.log('🎉 立即修改成功');
            return;
        }

        // 设置DOM观察器
        setupMutationObserver();

        // 开始轮询检查
        pollForElements();
    }

    // 等待页面加载完成
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // 监听路由变化(对于SPA应用)
    let lastUrl = location.href;
    new MutationObserver(() => {
        const url = location.href;
        if (url !== lastUrl) {
            lastUrl = url;
            console.log('🔄 检测到路由变化,重新检查表单');
            setTimeout(modifyInputFields, 1000);
        }
    }).observe(document, { subtree: true, childList: true });

})();