Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
PIRATE BAY
*/
pirateCatCodes = {
'AUDIO' : '100',
'VIDEO' : '200',
'SOFTWARE' : '300',
'GAMES' : '400',
'OTHER' : '600'
};
pirateSortCodes = {
'TYPE' : '13',
'NAME' : '1',
'UPLOADED' : '3',
'SIZE' : '5',
'SEEDS' : '7'
};
aPirateCats = [
'Audio',
'Video',
'Software',
'Games',
'Other'
];
aPirateSorts = [
'Type',
'Name',
'Uploaded',
'Size',
'Seeds'
];
noun_type_pirate_cats = new CmdUtils.NounType("category", aPirateCats);
noun_type_pirate_sort = new CmdUtils.NounType("sort type", aPirateSorts);
oPirateCats = {};
for (var i = 1; i <= aPirateCats.length; i++) {
oPirateCats[aPirateCats[i-1]] = ''+i+'';
}
//
CmdUtils.CreateCommand({
name: 'piratebay',
author: {
name: "BLUDGEON",
email: "no@no.no"
},
icon: "http://www.google.com/s2/favicons?domain=www.thepiratebay.org",
description: 'Search The Pirate Bay for a torrent.',
help:
'Search for a torrent, with the option of specifying a category (Audio/Video/Software/Games/Other) and/or a sort (Type/Name/Uploaded/Size/Seeds). Note: Results will be sorted by seeds by default.' +
' eg. <i>"pira Diablo in games by size"</i>',
releaseinfo: {1:"(Feb 14 2009) Most code stolen from James Furey, some from Gary Hodgson." },
takes: {"query": noun_arb_text},
modifiers: {"in": noun_type_pirate_cats, "by": noun_type_pirate_sort},
pretty: function (s, a) {
for (var i=0; i<a.length; i++) {
if (a[i].toLowerCase() == s.toLowerCase()) {
return a[i];
}
}
},
preview: function(div, oQuery, oMods) {
/*
QUERY...
*/
var sQuery = jQuery.trim(oQuery.text);
sQuery.length < 1 ? sQuery = "..." : null;
var sPreviewTemplate = 'Searches <b>The Pirate Bay</b> for "${query}"</i>';
var oPreviewData = {query: sQuery};
/*
MODIFIERS...
*/
var sCat = jQuery.trim(oMods["in"].text);
if (sCat.length > 0) {
sPreviewTemplate += ", in ${cat}";
oPreviewData['cat'] = this.pretty(sCat, aPirateCats);
}
var sSort = jQuery.trim(oMods["by"].text);
if (sSort.length > 0) {
sPreviewTemplate += ", sorted by ${sort}";
var s = this.pretty(sSort, aPirateSorts);
s == 'Cat' ? s = "Category" : null;
oPreviewData['sort'] = s;
delete s;
}
/*
PREVIEW...
*/
div.innerHTML = CmdUtils.renderTemplate(sPreviewTemplate, oPreviewData);
},
execute: function(oQuery, oMods) {
var sQuery = jQuery.trim(oQuery.text);
if (sQuery.length < 1) {
Utils.openUrlInBrowser("http://www.thepiratebay.org/");
return;
}
/*
MODIFIERS...
*/
var sCat = jQuery.trim(oMods["in"].text);
var sSort = jQuery.trim(oMods["by"].text);
/*
COMPOSE THE URL TEMPLATE...
*/
var sURL = 'http://thepiratebay.org/search/' + sQuery + '/0/';
var sortby = pirateSortCodes['SEEDS'];
var category = '/0';
if (sSort.length > 0)
sortby = pirateSortCodes[sSort.toUpperCase()];
if (sCat.length > 0)
category = '/' + pirateCatCodes[sCat.toUpperCase()];
//Open the site!
Utils.openUrlInBrowser(sURL + sortby + category);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.