plinkl / Empornium Download Warned Link

// ==UserScript==
// @license MIT
// @name        Empornium Download Warned Link
// @namespace   plinkl
// @description Adds a Download link for Warned/Marked for deletion torrents
// @include     http://www.empornium.me/torrents.php?id*
// @include     https://www.empornium.me/torrents.php?id*
// @include     http://www.empornium.sx/torrents.php?id*
// @include     https://www.empornium.sx/torrents.php?id*
// @version     1.1.0
// @grant       none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==

function init () {
  var download = window.jQuery('span.torrent_buttons').eq(1);
  var dl_re = new RegExp('DOWNLOAD TORRENT');
  if (download.text().match(dl_re) === null) {
    var id_re = new RegExp('id=(\\d+)');
    var id = download.html().match(id_re) [1];
    var keys = findKeysB(download)
    if (keys !== false) {
      download = download.html('\n                            <a href="torrents.php?action=download&amp;id=' + id + '&amp;authkey=' + keys[0] + '&amp;torrent_pass=' + keys[1] + '" class="button redButton" title="Download">DOWNLOAD WARNED TORRENT</a>' + download.html())
    }
  }
}


function findKeysB(links) {
  var auth_re = new RegExp(/authkey=([\da-f]*)/);
  var pass_re = new RegExp(/torrent_pass=([\da-f]*)/);
  var authkey = '';
  var passkey = '';
  if (links.html().match(auth_re)) {
    authkey = links.html().match(auth_re)[1];
  }
  if (links.html().match(pass_re)) {
    passkey = links.html().match(pass_re)[1];
  }
  if (authkey !== '' && passkey != '') {
    return [authkey, passkey];
  }
  return false;
}



setTimeout(function() {
	init();
}, 250);