Skip to content

Instantly share code, notes, and snippets.

@Jimmy-Z
Last active August 5, 2023 19:39
Show Gist options
  • Save Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819 to your computer and use it in GitHub Desktop.
Save Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819 to your computer and use it in GitHub Desktop.
darken certain results on rarbg
// ==UserScript==
// @name rarbg
// @namespace https://github.com/Jimmy-Z/
// @version 0.2.0
// @description rarbg helper (for Movies/x264/1080 and TV HD Episodes)
// @author JimmyZ
// @match *://rarbg.to/torrent*
// @match *://proxyrarbg.org/torrent*
// @grant none
// @updateUrl https://gist.github.com/Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819/raw/rarbg.meta.js
// @downloadUrl https://gist.github.com/Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819/raw/rarbg.user.js
// ==/UserScript==
// ==UserScript==
// @name rarbg
// @namespace https://github.com/Jimmy-Z/
// @version 0.2.0
// @description highlight/darken certain results on rarbg (Movies/x264/1080 and TV HD Episodes)
// @author JimmyZ
// @match *://rarbg.to/torrent*
// @match *://proxyrarbg.org/torrent*
// @grant none
// @updateUrl https://gist.github.com/Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819/raw/rarbg.meta.js
// @downloadUrl https://gist.github.com/Jimmy-Z/f24d5a061ba0f7ad45641fd7ee53d819/raw/rarbg.user.js
// ==/UserScript==
(function() {
"use strict";
(()=>{
const e = document.createElement("style");
e.textContent = [
"td.lista {line-height: 1.7}",
"a.hl {color: lime; padding: 1px 1px 2px 2px; border: 1px solid red; text-decoration: none}",
"a.hla {background-color: black}",
"a.hlb {background-color: darkgray}",
"a.dark {color: darkgray}",
].join("\n");
document.head.append(e);
})();
const LIST = 1, INFO = 2;
const MOVIE = 1, TV = 2;
const CAT_MAP = {
"44": MOVIE,
"41": TV,
"Movies/x264/1080": MOVIE,
"Movies/TV-HD-episodes": TV
};
const RULES = {};
RULES[MOVIE] = [
{
re: /\.bluray\.x264(\.|\-)/i,
class: "hl hla"
},
{
re: /\.(amzn|nf)\.(webrip|web-dl)\./i,
class: "hl hlb"
},
{
re: /\.(bdrip|brrip|hdtv|hdrip|webrip|web-dl|web)\.|\.bluray\.h264\.aac-(rarbg|vxt)|\.bluray\.x265-vxt/i,
class: "dark"
}
];
RULES[TV] = [
{
re: /\.1080p\.(amzn|nf)\.(webrip|web-dl)\./i,
class: "hl hla"
}
];
function create_link(text, href, click){
const l = document.createElement("a");
l.appendChild(document.createTextNode(text));
l.style["text-decoration"] = "none";
if(href){
l.href = href;
}
if(click){
l.onclick = click;
}
return l;
}
function handle(node, rules, is_list){
const title = node.firstChild;
console.log(title.textContent);
for (let i in rules){
const rule = rules[i];
if(rule.re.test(title.textContent)){
rule.class.split(" ").forEach(c => title.classList.add(c));
break;
}
}
if (is_list !== true){
return;
}
// funny easylist has a rule to block td[style*="height:"] on rarbg so we can't do this
// node.style["line-height"] = "1.7";
// add link to imdb
let imdb;
for(let e = title.nextElementSibling; e !== null; e = e.nextElementSibling){
if(e.tagName.toLowerCase() === "a" && e.href !== undefined){
const m = /\?imdb=tt(\d+)$/.exec(e.href);
if (m !== undefined){
imdb = m[1];
break;
}
}
}
if (imdb !== undefined){
node.appendChild(create_link("imdb", `https://www.imdb.com/title/tt${imdb}/`));
node.appendChild(document.createTextNode(" "));
}
// add link to get links directly in list page
node.appendChild(create_link("Get", null, e => {
node.removeChild(e.target);
fetch(title.href).then(body => body.text()).then(b => {
const p = new DOMParser().parseFromString(b, "text/html");
const l = p.querySelector("td.lista a[id]");
node.appendChild(create_link("torrent", l.href));
node.appendChild(document.createTextNode(" "));
node.appendChild(create_link("magnet", l.nextElementSibling.href));
});
}));
// bigger cover image
// title.onmouseout = undefined;
const eh = title.attributes.onmouseover;
eh.value = eh.value.replace(/\/over_opt.jpg|_small\.jpg|\/static\/over\/([0-9a-f])/, (s, d) => {
switch(s){
case "/over_opt.jpg":
return "/poster_opt.jpg";
case "_small.jpg":
return "_banner_optimized.jpg";
default:
return `/posters2/${d}/${d}`;
}
});
// remove title attribute, useless and it obstructs the cover image
if(title.textContent === title.title){
title.removeAttribute("title");
}
}
let mode, cat;
if(window.location.pathname === "/torrents.php"){
mode = LIST;
let cat_set = {};
document.querySelectorAll("div#divadvsearch div.divadvscat input[type=checkbox].inputadvscat:checked").forEach(c => {
cat_set[CAT_MAP[c.value]] = true;
});
cat_set = Object.keys(cat_set);
if(cat_set.length === 1){
cat = cat_set[0];
}
}else if(window.location.pathname.slice(0, 9) === "/torrent/"){
mode = INFO;
document.querySelectorAll("table.lista tbody tr td.header2:first-child").forEach(td => {
if(td.textContent.trim() === "Category:"){
cat = CAT_MAP[td.nextSibling.textContent.trim()];
}
});
}else{
console.log("invalid page");
return;
}
console.log("rarbg " + mode + " " + cat);
// n for name, d for description
const rules = RULES[cat];
if(rules === undefined){
console.log(`no rules specified for category ${cat}`);
return;
}
if(mode === LIST){
// the results list
document.querySelectorAll("tr.lista2 td.lista:nth-child(2)").forEach(td => handle(td, rules, true));
// accommodate the larger image
const pop = document.getElementById("overlib");
const s = pop.style;
s.padding = "0";
s.outline = "1px solid black";
const offset = 10;
if(true){
document.onmousemove = m => {
const img = pop.firstChild;
const height = (img !== null && img.height > 0) ? img.height : (cat === TV ? 140 : 500)
const max_top = document.scrollingElement.scrollTop + document.scrollingElement.clientHeight - height - offset;
s.top = `${Math.min(m.pageY + offset, max_top)}px`;
s.left = `${m.pageX + offset}px`;
}
}else{
// alternative, always bottom right corner
s.position = "fixed";
s.bottom = "10px";
s.right = "10px";
// document.removeEventListener("mousemove", document.onmousemove);
document.onmousemove = undefined;
}
}else if(mode === INFO){
// the related list
document.querySelectorAll("tr.lista_related td.lista:nth-child(5)").forEach(td => handle(td, rules));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment