Skip to content

Instantly share code, notes, and snippets.

@ideabrian
Created December 7, 2023 20:24
Show Gist options
  • Select an option

  • Save ideabrian/0e74625b54c9e7979b71aeb5f5af5ba7 to your computer and use it in GitHub Desktop.

Select an option

Save ideabrian/0e74625b54c9e7979b71aeb5f5af5ba7 to your computer and use it in GitHub Desktop.

Revisions

  1. ideabrian created this gist Dec 7, 2023.
    45 changes: 45 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    document.addEventListener('keydown', function(event) {
    // Define the key codes for navigation and activation
    const navigateKey = 'ArrowRight'; // Example: Right arrow key for navigation
    const activateKey = 'q'; // Use 'q' key for activation

    // Handle navigation
    if (event.key === navigateKey) {
    navigateToNextItem();
    }

    // Handle activation
    if (event.key === activateKey) {
    activateCurrentItem();
    }
    });

    let currentItemIndex = -1;
    const items = document.querySelectorAll('.cl-search-result');

    function navigateToNextItem() {
    if (items.length === 0) return;

    // Remove highlight from the current item
    if (currentItemIndex >= 0 && currentItemIndex < items.length) {
    items[currentItemIndex].style.backgroundColor = '';
    }

    // Move to the next item
    currentItemIndex = (currentItemIndex + 1) % items.length;

    // Highlight the new current item
    items[currentItemIndex].style.backgroundColor = 'yellow';
    }

    function activateCurrentItem() {
    if (items.length === 0 || currentItemIndex < 0 || currentItemIndex >= items.length) return;

    // Find and click the button within the current item
    const button = items[currentItemIndex].querySelector('button[title="hide posting"]');
    if (button) {
    button.click();
    }
    }

    // made by @brianball of buildstuff.ai with the help of chatgpt