Sixem

Userscript: MVGroup Downloads All Magnets Button (Forums)

Aug 13th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         MVGroup Magnets
  3. // @version      6.7.4
  4. // @author       emy
  5. // @match        http://forums.mvgroup.org/index.php?showtopic=*
  6. // @require      https://code.jquery.com/jquery-3.2.1.min.js
  7. // ==/UserScript==
  8.  
  9. $magnet_list = [];
  10.  
  11. function constructButton($torrent_list)
  12. {
  13.   $button_html = '<div id="magnet-dl-all">Download All Magnets (' + $magnet_list.length + ')</div>';
  14.  
  15.   $frame = '<iframe style="display:none" name="magnetframe"></iframe>';
  16.  
  17.   $(document).find('iframe').prev().after($frame + $button_html);
  18.  
  19.   $(document).find('#magnet-dl-all').css({
  20.     'display' : 'inline-block',
  21.     'background-color' : '#c93030',
  22.     'padding' : '5px',
  23.     'color' : 'white',
  24.     'border-radius' : '3px',
  25.     'cursor' : 'pointer',
  26.     'font-weight' : 'bold',
  27.   });
  28. }
  29.  
  30. function fetchMagnetUrls($torrent_list)
  31. {
  32.   $torrent_list.find(".magnetlink").each(function()
  33.   {
  34.     $magnet_url = $(this).attr('href');
  35.     $magnet_list[$magnet_list.length] = $magnet_url;
  36.   });
  37.  
  38.   if($magnet_list.length > 0)
  39.   {
  40.     constructButton($torrent_list);
  41.   }
  42. }
  43.  
  44. function waitForTorrentList()
  45. {
  46.   if($(document).find('iframe').contents().find('#torrentlist').length >= 1)
  47.   {
  48.     fetchMagnetUrls($(document).find('iframe').contents().find('#torrentlist'));
  49.   } else {
  50.     setTimeout(waitForTorrentList, 1000);
  51.   }
  52. }
  53.  
  54. $(document).ready(function()
  55. {
  56.   waitForTorrentList();
  57.  
  58.   $(document).on('click', '#magnet-dl-all', function()
  59.   {
  60.     jQuery.each($magnet_list, function(index, item)
  61.     {
  62.       window.open(item, 'magnetframe');
  63.     });
  64.   });
  65.  
  66.   $(document).on('mouseenter', '#magnet-dl-all', function()
  67.   {
  68.     $(this).css('background-color', 'rgb(221, 29, 29)');
  69.   });
  70.  
  71.   $(document).on('mouseleave', '#magnet-dl-all', function()
  72.   {
  73.     $(this).css('background-color', '#c93030');
  74.   });
  75. });
Add Comment
Please, Sign In to add comment