Auto Check Share and Focus Tags plus CTRL + Enter Save and Close

Automatically checks Share checkbox, focuses Tags input and enable CTRL + Enter submit on linkding bookmarks page

当前为 2025-04-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto Check Share and Focus Tags plus CTRL + Enter Save and Close
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Automatically checks Share checkbox, focuses Tags input and enable CTRL + Enter submit on linkding bookmarks page
// @author       Webmaster
// @match        https://*/bookmarks/new*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to check the Share checkbox
    function checkShareBox() {
        const checkbox = document.getElementById('id_shared');
        if (checkbox) {
            checkbox.checked = true;
        }
    }

    // Function to focus the Tags input
    function focusTagsInput() {
        const tagsInput = document.getElementById('id_tag_string');
        if (tagsInput) {
            tagsInput.focus();
        }
    }

    // Function to handle form submission
    function setupFormSubmission() {
        document.addEventListener('keydown', function(event) {
            if (event.ctrlKey && event.key === 'Enter') {
                const submitButton = document.querySelector('input[type="submit"][value="Save and close"]');
                if (submitButton) {
                    event.preventDefault(); // Prevent default Ctrl+Enter behavior
                    submitButton.click();   // Trigger the form submission
                }
            }
        });
    }

    // Run when page loads
    window.addEventListener('load', function() {
        checkShareBox();
        focusTagsInput();
        setupFormSubmission();
    });

    // For cases where content might load dynamically
    const observer = new MutationObserver(function(mutations) {
        checkShareBox();
        focusTagsInput();
        setupFormSubmission();
    });

    // Start observing the document with the configured parameters
    observer.observe(document, { childList: true, subtree: true });
})();