Skip to content

Instantly share code, notes, and snippets.

@ozh
Last active March 11, 2024 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ozh/417758e8076b931be7aae56ab2324f62 to your computer and use it in GitHub Desktop.
Save ozh/417758e8076b931be7aae56ab2324f62 to your computer and use it in GitHub Desktop.
Torrent hash to magnet link bookmarklet

1) Bookmark this:

javascript:var magnetLink='magnet:?xt=urn:btih:'+document.getSelection();location.assign(magnetLink);

Highlight any torrent hash and click bookmarklet to generate and load magnet link

2) Bookmark this:

javascript:(function(){var omg='';$("div.trackers-infos").each(function(i,e){if($(e).find('div.tracker-sources').text()!='%E2%80%94'){omg=omg+($(e).find('div.tracker-nom').text())+"\n";}});alert(omg);})();

Will popup all active trackers for this torrent

3) All in one

Just trigger bookmarklet to launch torrent client with magnet link and trackers

Code:

(function() {
    var hash = $("div#hash-du-torrent > p").text();
    var magnet = 'magnet:?xt=urn:btih:'+hash;
    $("div.trackers-infos").each(function(i, e) {
        if ($(e).find('div.tracker-sources').text() != '%E2%80%94') {
            magnet = magnet + '&tr='+($(e).find('div.tracker-nom').text());
        }
    });
    location.assign(magnet);
})();

Bookmarklet format: javascript:(function()%7Bvar%20hash%20%3D%20%24(%22div%23hash-du-torrent%20%3E%20p%22).text()%3Bvar%20magnet%20%3D%20'magnet%3A%3Fxt%3Durn%3Abtih%3A'%2Bhash%3B%24(%22div.trackers-infos%22).each(function(i%2C%20e)%20%7Bif%20(%24(e).find('div.tracker-sources').text()%20!%3D%20'%25E2%2580%2594')%20%7Bmagnet%20%3D%20magnet%20%2B%20'%26tr%3D'%2B(%24(e).find('div.tracker-nom').text())%3B%7D%7D)%3Blocation.assign(magnet)%7D)()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment