Skip to content

Add the function - Enter - to submit #138

@PushkaCom

Description

@PushkaCom

I love the theme - I'm not sure if vanilla yourls allows enter to submit , but it dosen't work with the theme enabled, and you can add it in with this JS. I have it in a plugin, but you can add it to your theme to make it better:

https://pastebin.com/S8yuxLtc


<script> /*Enter to submit*/
(function () {
  function onEnter(e) {
    if (e.key !== 'Enter' || e.isComposing) return;

    // Only when typing in the YOURLS fields
    const t = e.target;
    const inShortenerField =
      t &&
      (t.id === 'add-url' ||
       t.id === 'add-keyword' ||
       t.name === 'url' ||
       t.name === 'keyword');

    if (!inShortenerField) return;

    e.preventDefault();

    // Prefer the existing button; otherwise call the function
    const btn = document.getElementById('add-button');
    if (btn) {
      btn.focus();
      btn.click();
    } else if (typeof window.add_link === 'function') {
      window.add_link();
    }
  }

  // Delegated listener works even if inputs are added later
  document.addEventListener('keydown', onEnter, true);
})();

</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions