Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script that allows to download HorribleSubs shows using Seedr.cc service just by clicking on Magnet/Torrent links.
// ==UserScript==
// @name HorribleSubs to Seedr Linker
// @description A script that allows to download HorribleSubs shows using Seedr.cc service just by clicking on Magnet/Torrent links.
// @author Manciuszz
// @version 0.2
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.slim.min.js
// @match https://horriblesubs.info/shows/*
// @match https://www.seedr.cc/files*
// @grant GM_notification
// @grant GM_getTabs
// @grant GM_openInTab
// @grant GM_saveTab
// @grant GM_addValueChangeListener
// @grant GM_deleteValue
// @grant GM_setValue
// ==/UserScript==
var inline_src = (<><![CDATA[
"use strict";
(function() {
let waitForEl = function(selector, callback) {
if (jQuery(selector).length) {
callback();
} else {
setTimeout(function() {
waitForEl(selector, callback);
}, 100);
}
};
let horribleSubsFunc = function() {
GM_saveTab({tab: "horriblesubs.info"});
let bindTriggersToLinks = function() {
jQuery('a[title="Magnet Link"], a[title="Torrent Link"]').on('click', function(evt) {
evt.preventDefault();
let link = this.href;
checkForTabs(function(tabStatus) {
if (tabStatus == "closed") {
GM_openInTab("https://www.seedr.cc/files", { active: false });
let dropTorrentsId = setInterval(function() {
checkForTabs(function(tabStatus) {
if (tabStatus === "opened") {
GM_setValue("droppedTorrent", link);
clearInterval(dropTorrentsId);
}
});
}, 250);
}
});
GM_setValue("droppedTorrent", link);
});
};
let checkForTabs = function(callbackFn) {
GM_getTabs(function(tabObjects) {
if (!Object.values(tabObjects).map( (val, index) => val.tab).includes("seedr.cc")) {
if (typeof callbackFn === "function")
callbackFn("closed");
else
GM_notification({title: 'Linking HorribleSubs to Seedr.', text: 'Please login to Seedr.cc service.'});
} else {
if (typeof callbackFn === "function")
callbackFn("opened");
else
GM_notification({title: 'Linked HorribleSubs to Seedr', text: 'Click on magnet or torrent links to start uploading...'});
}
});
};
waitForEl('a[title="Magnet Link"]', function() {
bindTriggersToLinks();
checkForTabs();
});
};
let seedrFunc = function() {
GM_deleteValue("droppedTorrent");
GM_saveTab({tab: "seedr.cc"});
let startUploading = function() {
jQuery("#upload-button").click();
};
let inputSeedr = function(link) {
jQuery('input[type=text]',"#link-upload-text").val(link);
setTimeout(startUploading, 0);
};
!function bindListener() {
GM_addValueChangeListener("droppedTorrent", function(name, old_value, new_value, remote) { // Updates only on a NEW VALUE
if (new_value)
inputSeedr(new_value);
GM_deleteValue("droppedTorrent");
});
GM_notification({title: 'Seedr Listening to HorribleSubs...', text: 'Waiting for torrents...'});
}();
};
let main = ({"www.seedr.cc": seedrFunc, "horriblesubs.info": horribleSubsFunc})[location.host]();
})();
]]></>).toString();
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment