Greasy Fork

Greasy Fork is available in English.

HDBits Showing Free Leech Info

Let HDB torrent list show freeleech information.

当前为 2022-02-13 提交的版本,查看 最新版本

// ==UserScript==
// @name         HDBits Showing Free Leech Info
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Let HDB torrent list show freeleech information.
// @author       MewX
// @match        https://hdbits.org/browse.php*
// @icon         https://www.google.com/s2/favicons?domain=hdbits.org
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// @grant        none
// ==/UserScript==

// Global switches.
const mewxShowDownloadURL = false;
const mewxDownloadToServer = false;

const mewxTagsToSkip = ['LEECHING', 'SEEDING'];
function checkSeen(elem) {
    let t = elem.text().toLowerCase();
    for (let i = 0; i < mewxTagsToSkip.length; i ++) {
        if (t.indexOf(mewxTagsToSkip[i].toLowerCase()) !== -1) {
            return true; // Seen.
        }
    }
    return false;
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}
addGlobalStyle('.tag.tag_mewx_free { background-color: #d50000; margin-left: 0px; margin-right: 5px; }');
addGlobalStyle('.tag.tag_mewx_50 { background-color: #6200ea; margin-left: 0px; margin-right: 5px; }');
addGlobalStyle('.tag.tag_mewx_25 { background-color: #5d4037; margin-left: 0px; margin-right: 5px; }');
addGlobalStyle('.tag.tag_mewx_neutral { background-color: #616161; margin-left: 0px; margin-right: 5px; }');

(function ($, undefined) {
  $(function () {
      const prefix100off = '100% FL';
      const prefix50off = '50% Free Leech';
      const prefix25off = '25% Free Leech';
      const prefixNeutral = 'Neutral Leech';
      const prefixNone = 'All download counts';

      let tbody = $('table[id="torrent-list"]').find('tbody').eq(0);
      let cells = tbody.find('tr');
      for (let i = 0; i < cells.length; i ++) {
          let td = cells.eq(i).find('td:not([class="catcell"])').eq(0);
          let link = td.find('a').eq(0);
          // console.log(link.text());

          let title = link.attr('title');
          if (title == null) {
              continue;
          } else if (title.startsWith(prefix100off)) {
              let dl = td.find('img[title="Download"]').eq(0).parents(".js-download");
              let dlURL = "https://hdbits.org" + dl.attr('href');
              let torrentId = /id=(\d+)/g.exec(dlURL)[1];
              let seen = checkSeen(td);
              console.log((seen ? "Seen" : "NEW") + " - Torrent " + torrentId + " is FREE.");
              if (mewxShowDownloadURL && !seen) {
                  console.log(dlURL.replaceAll(" ", "%20"));
              }
              td.prepend('<span class="tag tag_mewx_free">100% FREE</span>');
          } else if (title.startsWith(prefix50off)) {
              td.prepend('<span class="tag tag_mewx_50">50% OFF</span>');
          } else if (title.startsWith(prefix25off)) {
              td.prepend('<span class="tag tag_mewx_25">25% OFF</span>');
          } else if (title.startsWith(prefixNeutral)) {
              td.prepend('<span class="tag tag_mewx_neutral">Neutral</span>');
          } else if (title.startsWith(prefixNone)) {
              // Do nothing.
          } else {
              console.log('Unknown discount: ' + title);
          }
      }
  });
})(window.jQuery.noConflict(true));