// ==UserScript==
// @name SC Display Languages
// @version 0.1
// @description Displays movies audio and text languages in SC
// @author risq
// @match http*://secret-cinema.pw/torrents.php?id=*
// @namespace https://greasyfork.org/users/157340
// @downloadURL none
// ==/UserScript==
var torrents = unsafeWindow.jQuery('.torrent_table .torrent_row').each(function (i, el) {
var $el = unsafeWindow.jQuery(el);
var languages = parseText($el.next().find('> td > blockquote').text());
var text = void 0;
if (languages.audio.length) {
text = 'Audio: ' + languages.audio.join(', ') + '';
if (languages.text.length) {
text += ' / Text: ' + languages.text.join(', ') + '';
}
} else if (languages.text.length) {
text = 'Text: ' + languages.text.join(', ') + '';
}
if (text) {
$el.find('> td:first-child').append('
' + text + '
');
}
});
function parseText(text) {
var res = {
audio: [],
text: []
};
var dataFound = false;
var blocks = text.split(/\s*\n\s*\n\s*/g).forEach(function (block) {
var title = block.split('\n')[0].toLowerCase();
if (title.indexOf('audio') > -1) {
var language = /language\s*:\s*(.*)/gi.exec(block);
if (language) {
dataFound = true;
res.audio.push(language[1]);
}
}
if (title.indexOf('text') > -1) {
var _language = /language\s*:\s*(.*)/gi.exec(block);
if (_language) {
dataFound = true;
res.text.push(_language[1]);
}
}
});
if (!dataFound) {
var lines = text.split(/\n/g);
lines.forEach(function (line) {
var audio = /.*(audio).*:(.*)/gi.exec(line);
if (audio && isResultValid(audio[2])) {
res.audio.push(audio[2]);
return;
}
var text = /.*(subtitle|text).*:(.*)/gi.exec(line);
if (text && isResultValid(text[2])) {
res.text.push(text[2]);
return;
}
});
}
return res;
}
function isResultValid(result) {
var invalidWords = ['untouched', 'none', 'no'];
var regexp = new RegExp('(\\b' + invalidWords.join('\\b|\\b') + '\\b)', 'gi');
return !regexp.test(result);
}