Gelbooru Favorite Shortcut

Adds a keybind shortcut for adding images to favorites on Gelbooru.com

  1. // ==UserScript==
  2. // @name Gelbooru Favorite Shortcut
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.1
  6. // @description Adds a keybind shortcut for adding images to favorites on Gelbooru.com
  7. // @author YourName
  8. // @match https://gelbooru.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Define the keybind shortcut (you can change this to your preference)
  16. const shortcutKey = 'f';
  17.  
  18. // Function to add an image to favorites
  19. function addToFavorites() {
  20. // Identify the anchor element that corresponds to "Add to favorites" and trigger a click event
  21. const addToFavoritesButton = document.querySelector("a[onclick*='addFav']");
  22. if (addToFavoritesButton) {
  23. addToFavoritesButton.click();
  24. }
  25. }
  26.  
  27. // Listen for keydown events
  28. document.addEventListener('keydown', function(event) {
  29. // Check if the pressed key matches the shortcut key and if an input field is not focused
  30. if (event.key === shortcutKey && document.activeElement.tagName !== 'INPUT') {
  31. // Prevent default browser behavior for this key
  32. event.preventDefault();
  33. // Add the image to favorites
  34. addToFavorites();
  35. }
  36. });
  37. })();