Focus on First Task in Vikunja Table view

Focus on First Task in Vikunja Table view. Focuses on the first <a> element in the first <td> of the specified table when it becomes available. You have to change the match parameter below to your website URL.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Focus on First Task in Vikunja Table view
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Focus on First Task in Vikunja Table view. Focuses on the first <a> element in the first <td> of the specified table when it becomes available. You have to change the match parameter below to your website URL.
// @author       Grok
// @match        https://try.vikunja.io/*
// @grant        none
// @license MIT
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function focusFirstLink() {
        const table = document.querySelector('table.table.has-actions.is-hoverable.is-fullwidth');

        if (table) {
            const firstRow = table.querySelector('tbody tr');
            if (firstRow) {
                const firstTd = firstRow.querySelector('td');
                if (firstTd) {
                    const firstA = firstTd.querySelector('a');
                    if (firstA) {
                        firstA.focus();
                        console.debug('ViolentMonkey: Focused on the first task link.');
                        return true;
                    } else {
                        console.debug('ViolentMonkey: No <a> found in the first <td>.');
                    }
                } else {
                    console.debug('ViolentMonkey: No <td> found in the first row.');
                }
            } else {
                console.debug('ViolentMonkey: No rows found in the table body.');
            }
        } else {
            console.debug('ViolentMonkey: Table not found yet.');
        }
        return false;
    }

    // Initial check
    if (!focusFirstLink()) {
        // Set up MutationObserver to watch for DOM changes
        const observer = new MutationObserver(() => {
            if (focusFirstLink()) {
                observer.disconnect();
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }
})();