HOWTO: Press ENTER on URL field to add torrent

Discussion of the Web Interface for Transmission, formerly known as Clutch. This applies to all version of Transmission
jb0x2d1
Posts: 2
Joined: Sun Jan 17, 2016 5:15 pm

HOWTO: Press ENTER on URL field to add torrent

Postby jb0x2d1 » Sun Jan 17, 2016 6:04 pm

I'm using version 2.84. When adding a torrent in the web interface by pasting a magnet link in the URL field, you have to click the Upload button to make it go. Pressing the ENTER key does nothing. The following modifications to transmission.js make pressing the ENTER key while the cursor is in the URL field behave the same as clicking the Upload button.

** Warning ** Make a backup copy of any files before you change them so that you can put them back if you make a mistake!

As root, edit transmission.js with your favorite text editor. On my system, transmission.js is located in /usr/share/transmission/web/javascript

Near the top of transmission.js (under the heading "// Set up user events") add the following line:

Code: Select all

$('#torrent_upload_url').keypress($.proxy(this.confirmUploadEnter,this));


Next, find the section that looks like this (on my system it starts around line number 565):

Code: Select all

confirmUploadClicked: function() {
                this.uploadTorrentFile(true);
                this.hideUploadDialog();
        },


Add the following below it:

Code: Select all

        confirmUploadEnter: function (e) {
                if (e.which == 13) {
                        this.uploadTorrentFile(true);
                        this.hideUploadDialog();
                }
        },


The finished product should look like this:

Code: Select all

...
       confirmUploadClicked: function() {
                this.uploadTorrentFile(true);
                this.hideUploadDialog();
        },

        confirmUploadEnter: function (e) {
                if (e.which == 13) {
                        this.uploadTorrentFile(true);
                        this.hideUploadDialog();
                }
        },

        hideMoveDialog: function() {
...


Save the file. Refresh the transmission web interface page and enjoy.

I would love for this tiny feature to be available in future releases.

** Disclaimer ** This worked for me but might not for you. I'm not a web developer. I can use Google and be dangerous with what I find. There may be a better/cleaner way to accomplish this. If you can clean up or streamline this code, please do. Remember to make a backup copy of any files before you modify them! I take no responsibility if you break your stuff. But seriously it worked for me


pietrod
Posts: 3
Joined: Fri Jan 06, 2017 3:30 am

Re: HOWTO: Press ENTER on URL field to add torrent

Postby pietrod » Fri Jan 06, 2017 3:56 am

viewtopic.php?f=8&t=9248&p=74676#p74676
maybe this would be a faster approach: just add an handler to let magnet links open directly in web interface (and start automatically would be even more awesome)...

pietrod
Posts: 3
Joined: Fri Jan 06, 2017 3:30 am

Re: HOWTO: Press ENTER on URL field to add torrent

Postby pietrod » Sat Jan 07, 2017 11:49 pm

Or maybe a ctrl+v that automatically start the magnet would be equally good and similar to do I think, can you do that?

btw I add the enter option and it's already a lot better!

jb0x2d1
Posts: 2
Joined: Sun Jan 17, 2016 5:15 pm

Re: HOWTO: Press ENTER on URL field to add torrent

Postby jb0x2d1 » Sat Sep 02, 2017 12:04 am

Just updated to 2.92, and since neither
https://trac.transmissionbt.com/ticket/5504
https://trac.transmissionbt.com/ticket/5857
appear to be included :| , I'm at it again.

From what I've seen, capturing the paste event only really works if a text field has the input focus, however if you want to add CTRL+O to open the upload dialog, do that by making a backup copy first, then changing transmission.js from this (around line 465 for me)

Code: Select all

      else if (shift)
      {
         this._shift_index = this.indexOfLastTorrent();
      }

      return !handled;

to this
(Note: you can change 'o' to a letter of your choosing)

Code: Select all

      else if (shift)
      {
         this._shift_index = this.indexOfLastTorrent();
      }
      else if (ev.ctrlKey || ev.metaKey) {
         if (String.fromCharCode(ev.which).toLowerCase() == 'o') {
            ev.preventDefault();
            this.openTorrentClicked(ev);
            handled = true;
         }
      }

      return !handled;

Refresh the UI web page for change to take effect. I had to view page source, find the reference to transmission.js, click that, and refresh that source for it to update. Clearing your browser's cache would likely work too. Don't forget to backup files before you change them. This mod plus the previous one lets you press CTRL+O, CTRL+V, ENTER to add a magnet link that you have on the clipboard. These mods worked for me on both versions 2.84 and 2.92. Maybe we'll see keyboard shortcuts in a future release :roll:


Return to “Web Interface”