Last active
January 4, 2018 10:25
-
-
Save danikaze/4b7c2d7f4c914c1207ab97fc89a769e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Just execute this after searching for a package in xdcc.horriblesubs.info to get all the | |
* XDCC commands to get files in IRC, based on the current search | |
*/ | |
(function() { | |
const ALTERNATE_BOTS = true; | |
const hasOwnProperty = Object.prototype.hasOwnProperty; | |
function xdcc(showFileName) { | |
const info = retrieveInfo(); | |
const msgs = showInfo(info, showFileName); | |
return `${info.length}/${msgs}`; | |
} | |
function retrieveInfo() { | |
const trs = document.getElementById('listtable') | |
.querySelectorAll('tr:not(.animeColumn)'); | |
const info = []; | |
let bot; | |
let packId; | |
let size; | |
let filename; | |
trs.forEach((tr) => { | |
const tds = tr.querySelectorAll('td'); | |
const row = { | |
bot: tds[0].innerHTML, | |
packId: tds[1].innerHTML, | |
size: tds[2].innerHTML, | |
filename: tds[3].innerHTML, | |
} | |
info.push(row); | |
}); | |
return info; | |
} | |
function arrangeByBot(data) { | |
} | |
function arrangeByFile(data) { | |
const files = {}; | |
data.forEach((row) => { | |
if (!files[row.filename]) { | |
files[row.filename] = []; | |
} | |
files[row.filename].push(row); | |
}); | |
return files; | |
} | |
function showInfo(data, showFileName) { | |
let msgs = []; | |
const files = ALTERNATE_BOTS ? alternate(arrangeByFile(data)) | |
: arrangeByBot(data); | |
files.forEach((row) => { | |
if (showFileName) { | |
msgs.push(row.filename); | |
} | |
msgs.push(getOneCommand(row)); | |
}); | |
console.log(msgs.join("\n")); | |
return msgs.length; | |
} | |
function alternate(data) { | |
const res = []; | |
let count = 0; | |
for (let i in data) { | |
if (hasOwnProperty.call(data, i)) { | |
const file = data[i]; | |
const index = count % file.length; | |
res.push(file[index]); | |
count++; | |
} | |
} | |
return res; | |
} | |
function getOneCommand(row) { | |
return `/msg ${row.bot} xdcc send #${row.packId}`; | |
} | |
function objectToArray(obj) { | |
const res = []; | |
for (let i in obj) { | |
if (hasOwnProperty.call(obj, i)) { | |
res.push(obj[i]); | |
} | |
} | |
return res; | |
} | |
window.xdcc = xdcc; | |
}()); | |
// true to show the filename before each command | |
xdcc(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment