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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 });
})();