Skip to content

Instantly share code, notes, and snippets.

@Karmalakas
Last active February 4, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Karmalakas/e2ea12e3b3f1b62cec95d48e35f25705 to your computer and use it in GitHub Desktop.
Save Karmalakas/e2ea12e3b3f1b62cec95d48e35f25705 to your computer and use it in GitHub Desktop.
Linkomanija.net list modifications UserScript
// ==UserScript==
// @name Linkomanija.net list modifications
// @description Show poster if present and apply some styles
// @namespace http://karmalakas.lt/
// @version 1.0.1
// @author Karmalakas
// @updateURL https://gist.github.com/Karmalakas/e2ea12e3b3f1b62cec95d48e35f25705/raw/LM_list_modifications.user.js
// @downloadURL https://gist.github.com/Karmalakas/e2ea12e3b3f1b62cec95d48e35f25705/raw/LM_list_modifications.user.js
// @supportURL https://www.linkomanija.net/forums.php?action=viewtopic&topicid=85185
// @include https://www.linkomanija.net/browse.php*
// @require https://code.jquery.com/jquery-2.1.4.min.js
// @grant GM_addStyle
// ==/UserScript==
(function($) {
'use strict';
var isLight = function() {
var hex_digits = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
//Function to convert rgb color to hex format
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
function hex(x) {
return isNaN(x) ? '00' : hex_digits[(x - x % 16) / 16] + hex_digits[x % 16];
}
return rgb2hex($('body').css('background-color')) == '#fbfcfe';
};
GM_addStyle('.pos-rel{position:relative}');
GM_addStyle('.poster_holder{position: relative}.poster_holder a img{width:44px}.poster_holder span img{width:300px}.poster{position:absolute;bottom:-100px;right:-310px;display:none}');
GM_addStyle('.new_torrent{position:absolute;top:0;bottom:0;left:-3px;width:3px;background-color:red}');
if (isLight()) {
GM_addStyle('.free_leech{background-color:#e7ffe7}');
GM_addStyle('.huge_size{background-color:#ffd7d3}');
} else {
GM_addStyle('.free_leech{background-color:#254025}');
GM_addStyle('.huge_size{background-color:#711b1b}');
}
var unhumanize = function(text) {
var powers = {'k': 1, 'm': 2, 'g': 3, 't': 4},
regex = /(\d+(?:\.\d+)?)\s?(k|m|g|t)?b?/i,
res = regex.exec(text);
return res[1] * Math.pow(1024, powers[res[2].toLowerCase()]);
};
var size_limit = 20, // in GB
list = $('#content > form > table:last > tbody');
$.each(list.find('tr'), function(idx) {
var row = $(this),
main_cell = row.find('td:nth-child(2)');
var rearrangeCounterCells = function(merge_links = true) {
var seeders,
last_cell = row.find('td:last'),
second_cell = last_cell.prev(),
first_cell = second_cell.prev();
if (merge_links) {
var html = $(second_cell.html()),
last_href = $(last_cell.html()).find('a');
html.find('a').append('/' + (last_href.length ? last_href.html() : '0'));
seeders = html.html();
} else {
seeders = second_cell.html().trim() + '/' + last_cell.html().trim();
}
first_cell.html(seeders + ' (' + first_cell.html().trim() + ')');
second_cell.remove();
last_cell.remove();
};
if (main_cell.hasClass('colhead')) {
rearrangeCounterCells(false);
return;
}
rearrangeCounterCells();
var genres = main_cell.find('> span').text(),
link = main_cell.find('> a:first'),
title = link.find('> b').text(),
cat_icon_cell = row.find('td:first')
;
// Poster stuff
link = link.attr('href');
$.get(link).done(function (data) {
var regex = new RegExp('class="descr_text.+src="(.+?[^"])".+', "gim"),
poster = regex.exec(data);
if (poster && poster[1]) {
var image = $('<a href="' + link + '" target="_blank"><img src="' + poster[1] + '" alt="" /></a><span class="poster"><img src="' + poster[1] + '" alt="" /></span>');
cat_icon_cell.addClass('poster_holder').find('> a').replaceWith(image);
var poster_big = cat_icon_cell.find('span');
cat_icon_cell.find('a').on('mouseenter mouseleave', function() {
poster_big.toggle();
});
}
});
// Free leech
var free_leech_flag = main_cell.find('img[src="//static.linkomanija.net/images/flag_green.gif"]');
if (free_leech_flag.length > 0) {
main_cell.addClass('free_leech');
free_leech_flag.remove();
}
// Oversized
var size_cell = row.find('td:nth-child(6)');
if (unhumanize(size_cell.text().replace('<br>', '')) > 1024 * 1024 * 1024 * size_limit) {
size_cell.addClass('huge_size');
}
// New torrent
var new_torrent = main_cell.find('> b');
if (new_torrent. length) {
new_torrent.remove();
cat_icon_cell.addClass('pos-rel').append('<div class="new_torrent"></div>');
}
});
})(jQuery);
@Karmalakas
Copy link
Author

Šiek tiek pakeičiama sąrašų išvaizda.

Tamsi tema:
Tamsi tema

Šviesi tema:
Šviesi tema

Seeders/Leechers apjungimas:
Seeders/Leechers apjungimas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment