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

  1. // ==UserScript==
  2. // @name Auto Check Share and Focus Tags plus CTRL + Enter Save and Close
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Automatically checks Share checkbox, focuses Tags input and enable CTRL + Enter submit on linkding bookmarks page
  6. // @author Webmaster
  7. // @match https://*/bookmarks/new*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to check the Share checkbox
  15. function checkShareBox() {
  16. const checkbox = document.getElementById('id_shared');
  17. if (checkbox) {
  18. checkbox.checked = true;
  19. }
  20. }
  21.  
  22. // Function to focus the Tags input
  23. function focusTagsInput() {
  24. const tagsInput = document.getElementById('id_tag_string');
  25. if (tagsInput) {
  26. tagsInput.focus();
  27. }
  28. }
  29.  
  30. // Function to handle form submission
  31. function setupFormSubmission() {
  32. document.addEventListener('keydown', function(event) {
  33. if (event.ctrlKey && event.key === 'Enter') {
  34. const submitButton = document.querySelector('input[type="submit"][value="Save and close"]');
  35. if (submitButton) {
  36. event.preventDefault(); // Prevent default Ctrl+Enter behavior
  37. submitButton.click(); // Trigger the form submission
  38. }
  39. }
  40. });
  41. }
  42.  
  43. // Run when page loads
  44. window.addEventListener('load', function() {
  45. checkShareBox();
  46. focusTagsInput();
  47. setupFormSubmission();
  48. });
  49.  
  50. // For cases where content might load dynamically
  51. const observer = new MutationObserver(function(mutations) {
  52. checkShareBox();
  53. focusTagsInput();
  54. setupFormSubmission();
  55. });
  56.  
  57. // Start observing the document with the configured parameters
  58. observer.observe(document, { childList: true, subtree: true });
  59. })();