userscripts/tvcaltorrentz.js

29 lines
939 B
JavaScript

// ==UserScript==
// @name TV Calendar Torrentz
// @description Make torrent search links
// @version 1.0
// @namespace http://www.adrian.kousz.ch/
// @require https://git.adrian.kousz.ch/adrian/userscripts/raw/master/lib.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @match http://www.pogdesign.co.uk/cat/*
// @grant none
// ==/UserScript==
AdiUserscriptLib.addButton('Search Torrentz', function () {
var regex = new RegExp('/cat/([^/]+)/Season-([0-9]+)/Episode-([0-9]+)')
var url = 'https://torrentz.eu/search?q={name}+S{season}E{episode}'
var X = AdiUserscriptLib
$('a').each(function () {
var matches = regex.exec(this.href)
if (matches) {
var replacements = {
name: matches[1].replace('-','+')
, season: X.pad(matches[2], 2, '0')
, episode: X.pad(matches[3], 2, '0')
}
this.href = X.interpolate(url, replacements)
}
})
})