Greasy Fork

来自缓存

Greasy Fork is available in English.

HDBits Showing Free Leech Info

Let HDB torrent list show freeleech information.

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

// ==UserScript==
// @name         HDBits Showing Free Leech Info
// @namespace    http://tampermonkey.net/
// @version      0.2
// @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==

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() {
    'use strict';

    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)) {
            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);
        }
    }
})();