// ==UserScript==
// @name HDBits Showing Freeleech Info
// @namespace http://tampermonkey.net/
// @version 0.1
// @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
// @downloadURL 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').eq(1);
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('100% FREE');
} else if (title.startsWith(prefix50off)) {
td.prepend('50% OFF');
} else if (title.startsWith(prefix25off)) {
td.prepend('25% OFF');
} else if (title.startsWith(prefixNeutral)) {
td.prepend('Neutral');
} else if (title.startsWith(prefixNone)) {
// Do nothing.
} else {
console.log('Unknown discount: ' + title);
}
}
})();