Bookmarklet for Add Torrent by URL in 1.5x

Discussion of the Web Interface for Transmission, formerly known as Clutch. This applies to all version of Transmission

Moderator: Web Interface Developers

Bookmarklet for Add Torrent by URL in 1.5x

Postby shmuel » Sun Jan 25, 2009 1:35 pm

I would like to create a bookmarklet for the newly re-added torrent-by-url functionality. Can anyone point me in the right direction with regard to where to submit the form to? Is it possible to do this with a GET string or will I have to POST the data?
shmuel

 
Posts: 3
Joined: Sun Jan 25, 2009 1:29 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby danbt79 » Mon Jan 26, 2009 2:17 am

I'd love to see this too!
I've lost count of the number of times someone has mentioned a movie or song, and I've wanted to start downloading from the iPhone in my pocket. What a killer feature that would be!

Haven't tried bookmarklets on mobile Safari - I'm presuming they work, as to the best of my knowledge there's a full js stack on board. I'll see if I can get something working tomorrow! First step would be to see if bookmarketlets are supported, then see how the full interface adds via URL, then work up some .js.

Anyone point me to some resources before I hit google and this forum tomorrow? It's late here right now, and I'm logging shortly!
danbt79

 
Posts: 3
Joined: Mon Jan 26, 2009 2:10 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby shmuel » Mon Jan 26, 2009 2:30 am

Bookmarklets work great in Mobile Safari. Creating the bookmarklet shouldn't be too hard if I could only figure out where to send the data within the Transmission web app.
shmuel

 
Posts: 3
Joined: Sun Jan 25, 2009 1:29 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby kentyman » Mon Jan 26, 2009 4:12 am

I'm actually already looking into this. I made such a thing for uTorrent, but and going to modify it to work with Transmission.

Here's my original bookmarklet for uTorrent: http://forum.utorrent.com/viewtopic.php?id=38228
kentyman

 
Posts: 16
Joined: Mon Jan 26, 2009 4:08 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby kentyman » Mon Jan 26, 2009 5:16 am

OK, I got it working:

Code: Select all
javascript:(function()%20{%20var%20host%20=%20"http://<HOST>/transmission/";%20for%20(var%20i%20=%200;%20i%20<%20document.links.length;%20i++)%20{%20document.links[i].href%20=%20"javascript:(function()%20{%20var%20img%20=%20document.createElement('img');%20img.setAttribute('src',%20'"+%20host%20+%20"rpc?method=torrent-add&filename="%20+%20encodeURIComponent(document.links[i].href)%20+%20"');%20img.setAttribute('style',%20'visibility:hidden');%20document.body.appendChild(img);%20setTimeout('window.open(\""%20+%20host%20+%20"web/"%20+%20"\",%20\"_self\");',%204000);%20})();";%20}%20})();


All you have to do is replace the <HOST> part with your hostname or IP address and a port ("mydomain:9091" or "12.23.34.45:9091"). Optionally, you can include your username (and even password), so you don't have to type it each time ("myusername@mydomain:9091" or "myusername:mypassword@mydomain:9091").

To use it, simply browse to the page with the link to the torrent you want to add on your iPhone, then click the bookmarklet, then click the torrent link. After a few seconds, you will be redirected to your web interface.

I also made a web form to create these bookmarklets, but haven't put it up anywhere. If y'all want, I can pursue that more.
kentyman

 
Posts: 16
Joined: Mon Jan 26, 2009 4:08 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby danbt79 » Mon Jan 26, 2009 12:28 pm

Brilliant Kentyman!

I had a quick look through the Clutch source last night, and saw the rpc method required - just wasn't aware you could append it to the request in the way you did (it was late and I gave up at the first hurdle!) - so good work!
I've come back to have another crack at this and now I don't need to - just tried it out and it works a charm.

I'll sync my iPhone now and try it from a 3G connection.
Thanks!
danbt79

 
Posts: 3
Joined: Mon Jan 26, 2009 2:10 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby danbt79 » Mon Jan 26, 2009 12:35 pm

Just tried it from the iPhone - works perfectly!

Now does anyone know a good torrent site with an iPhone stylesheet? The Pirate Bay's a bit cumbersome on the small screen!
danbt79

 
Posts: 3
Joined: Mon Jan 26, 2009 2:10 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby shmuel » Mon Jan 26, 2009 12:57 pm

Thanks Kentyman,

Works great. I made a very small update to give some visual feedback when you first click the bookmarklet. I might add some visual feedback when you click the link as well so that you get the idea that the script is processing.

Thanks again,
SMB

Code: Select all
javascript:javascript:%20(function()%20{var%20host%20=%20%22http://<HOST>/transmission/%22,s,d%20=%20document,a%20=%20function(o)%20{d.body.appendChild(o)};for%20(var%20i%20=%200;%20i%20<%20document.links.length;%20i++)%20{document.links[i].href%20=%20%22javascript:(function()%20{%20var%20img%20=%20document.createElement(%27img%27);%20img.setAttribute(%27src%27,%20%27%22%20+%20host%20+%20%22rpc?method=torrent-add&filename=%22%20+%20encodeURIComponent(document.links[i].href)%20+%20%22%27);%20img.setAttribute(%27style%27,%20%27visibility:hidden%27);%20document.body.appendChild(img);%20setTimeout(%27window.open(\%22%22%20+%20host%20+%20%22web/%22%20+%20%22\%22,%20\%22_self\%22);%27,%204000);%20})();%22;}s%20=%20d.createElement(%27div%27);s.style.position%20=%20%27fixed%27;s.style.top%20=%20%270%27;s.style.width%20=%20%27100%%27;s.style.padding%20=%20%275px%27;s.style.zIndex%20=%20%271000%27;s.style.color=%20%27#fff%27;s.style.backgroundColor%20=%20%27#3fa5fc%27;s.style.borderBottom%20=%222px%20solid%20#75bfff%22;s.innerHTML%20=%20[%27<p>%27,%27<span%20style=%22text-shadow:%200px%200px%203px%20black;%20font-size:15px;%22>&diams;</span>%20&nbsp;%20All%20.torrent%20links%20on%20this%20page%20will%20now%20be%20uploaded%20to%20Transmission.%27,%27</p>%27].join(%27%27);a(s)})();
shmuel

 
Posts: 3
Joined: Sun Jan 25, 2009 1:29 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby godsyn » Wed Jan 28, 2009 11:02 am

Any chance of getting it to work in firefox?
godsyn

 
Posts: 36
Joined: Mon Mar 31, 2008 10:10 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby kentyman » Wed Jan 28, 2009 3:39 pm

It's basically the same bookmarklet as I made for uTorrent back in the day, which I successfully tested on Mobile Safari, Safari, Firefox, and Internet Explorer. And I think Google Chrome, but I can't remember exactly. Basically, it really should work anywhere.

Have you tried using it in Firefox?
kentyman

 
Posts: 16
Joined: Mon Jan 26, 2009 4:08 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby godsyn » Sat Jan 31, 2009 1:04 pm

yes, without success. The div pops up, but nothing happens. I've replaced <host> with my host.
godsyn

 
Posts: 36
Joined: Mon Mar 31, 2008 10:10 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby kentyman » Sat Jan 31, 2009 11:08 pm

I've had problems with it working with private trackers. Have you tried it with any of the big public trackers? I just tried it and it worked.
kentyman

 
Posts: 16
Joined: Mon Jan 26, 2009 4:08 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby godsyn » Sun Feb 01, 2009 1:42 pm

Note : this is outdated. Please see http://godsyn.com/bookmarklet/ for updated code, or use kentyman's above.

Perhaps noscript is messing with it. I'll play with it more later.

Silly me. After looking at the code and realizing I need to click the links after running the bookmarklet, everything works fine.

I've modded it a little to play nice on sites that define padding / etc on divs and p's.
Code: Select all
javascript:javascript:%20(function()%20{var%20host%20=%20"http://<HOST>/transmission/",s,d%20=%20document,a%20=%20function(o)%20{d.body.appendChild(o)};for%20(var%20i%20=%200;%20i%20<%20document.links.length;%20i++)%20{document.links[i].href%20=%20"javascript:(function()%20{%20var%20img%20=%20document.createElement('img');%20img.setAttribute('src',%20'"%20+%20host%20+%20"rpc?method=torrent-add&filename="%20+%20encodeURIComponent(document.links[i].href)%20+%20"');%20img.setAttribute('style',%20'visibility:hidden');%20document.body.appendChild(img);%20setTimeout('window.open(\""%20+%20host%20+%20"web/"%20+%20"\",%20\"_self\");',%204000);%20})();";}s%20=%20d.createElement('div');s.style.position%20=%20'fixed';s.style.top%20=%20'0';s.style.left%20=%20'0';s.style.width%20=%20'100%';s.style.zIndex%20=%20'1000';s.style.color=%20'#fff';s.style.backgroundColor%20=%20'#333';s.style.borderBottom%20="2px%20solid%20#000";s.innerHTML%20=%20['<p%20style="text-align:center;font-size:15px;">','&diams;&nbsp;Any%20clicked%20links%20on%20this%20page%20will%20now%20be%20sent%20to%20Transmission.','</p>'].join('');a(s)})();


Any chance of getting a close link, to remove the links and div? If so, this will replace my "add to clutch" firefox addon.

Edit: I've started working on this... Sadly my JS knowledge is limited. I have it displaying, but it doesn't close the div more than once or remove the JS links on the URLs.
Edit: done. Closing div removes links.
Code: Select all
javascript:javascript:%20(function(){var%20host%20=%20%22http:%2F%2F<HOST>%2Ftransmission%2F%22,s,d%20=%20document,a=function(o){d.body.appendChild(o)};for(var%20i=0;i<%20document.links.length;%20i++){document.links[i].href%20=%20%22javascript:(function(){var%20img=document.createElement('img');img.setAttribute('src','%22%20+%20host%20+%20%22rpc?method=torrent-add&filename=%22%20+%20encodeURIComponent(document.links[i].href)%20+%20%22');img.setAttribute('style','visibility:hidden');document.body.appendChild(img);%20setTimeout('window.open(\%22%22%20+%20host%20+%20%22web/%22%20+%20%22\%22,\%22_self\%22);',4000);})();%22;}s=d.createElement('div');s.style.position='fixed';s.style.top='0';s.style.left='0';s.style.width='100%';s.style.zIndex='1000';s.id='tordiv1';s.style.color='#fff';s.style.backgroundColor='#333';s.style.borderBottom%20=%222px%20solid%20#000%22;s.innerHTML=['<p%20style=%22text-align:center;font-size:15px;padding:0;margin:10px;%22>','%E2%99%A6%C2%A0All%20clicked%20links%20on%20this%20page%20will%20now%20be%20sent%20to%20Transmission.','</p>','<a%20href=%22%22%20style=%22padding:2px;margin:0;font-family:monospace;font-size:18px;position:absolute;top:0;right:0;font-weight:700;color:#f00;text-decoration:none;%22%20onclick=%22document.getElementById(\'tordiv1\').style.display=\'none\';%22>X</a>'].join('');a(s)})();
Last edited by godsyn on Mon Feb 16, 2009 7:36 am, edited 5 times in total.
godsyn

 
Posts: 36
Joined: Mon Mar 31, 2008 10:10 pm

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby kentyman » Tue Feb 03, 2009 4:14 am

I'm working on setting up a SourceForge project so we can more easily collaborate. I plan on supporting at least uTorrent (since that's the first bookmarklet I made) and Transmission, but possibly other clients as well. I'll get back to y'all when it's set up and ready to go.
kentyman

 
Posts: 16
Joined: Mon Jan 26, 2009 4:08 am

Re: Bookmarklet for Add Torrent by URL in 1.5x

Postby godsyn » Thu Feb 05, 2009 1:04 pm

link nudge
godsyn

 
Posts: 36
Joined: Mon Mar 31, 2008 10:10 pm

Next

Return to Web Interface

Who is online

Users browsing this forum: No registered users and 1 guest