mirror of
https://github.com/NohamR/BetterYGG.git
synced 2026-01-10 08:18:19 +00:00
[1.2.8] new domain name and stuff
This commit is contained in:
@@ -10,18 +10,18 @@ var path = window.location.pathname;
|
||||
var tableLines = document.querySelectorAll('table.infos-torrent tbody tr');
|
||||
var downloadLine = tableLines[0];
|
||||
var torrentInfo = downloadLine.cloneNode(true);
|
||||
torrentInfo.style = "display: none";
|
||||
torrentInfo.style.display = 'none';
|
||||
downloadLine.insertAdjacentElement('afterend', torrentInfo);
|
||||
|
||||
/* Add third party download button */
|
||||
var downloadButton = downloadLine.querySelector('a.butt');
|
||||
var flexButton = document.createElement('a');
|
||||
flexButton.appendChild(document.createTextNode("Télécharger via discord "));
|
||||
flexButton.appendChild(document.createTextNode('Télécharger via discord '));
|
||||
var span = document.createElement('span');
|
||||
span.className = "ico_download";
|
||||
span.classList.add('ico_download');
|
||||
flexButton.appendChild(span);
|
||||
flexButton.className = "butt discord";
|
||||
flexButton.style = "display: none";
|
||||
flexButton.classList.add('butt', 'discord');
|
||||
flexButton.style.display = 'none';
|
||||
flexButton.addEventListener('click', addToDiscord);
|
||||
downloadButton.parentElement.appendChild(flexButton);
|
||||
|
||||
@@ -30,7 +30,7 @@ var torrentId = (/.*\/torrent\/.*\/.*\/(\d+)-/g).exec(window.location.pathname);
|
||||
if (torrentId) {
|
||||
torrentId = torrentId[1];
|
||||
}
|
||||
var torrentTitle = document.querySelector('div#title h1').textContent.trim().split(".").join(" ");
|
||||
var torrentTitle = document.querySelector('div#title h1').textContent.trim().split('.').join(' ');
|
||||
var torrentYear = (/(19\d{2}|2\d{3})/g).exec(torrentTitle);
|
||||
if (torrentYear) {
|
||||
torrentYear = torrentYear[1];
|
||||
@@ -48,10 +48,10 @@ if (torrentTitle.includes('1080')) {
|
||||
var discordWebhookUrl, discordUserName, categories;
|
||||
chrome.storage.sync.get(['yggToken', 'discordWebhookUrl', 'discordUserName', 'displayDiscord', 'displayAddCategories', 'categories', 'defaultCategories'], function (value) {
|
||||
if (value.yggToken) {
|
||||
downloadButton.setAttribute('href', "https://" + window.location.host + "/rss/download?id=" + torrentId + "&passkey=" + value.yggToken);
|
||||
downloadButton.setAttribute('href', `https://${window.location.host}/rss/download?id=${torrentId}&passkey=${value.yggToken}`);
|
||||
} else {
|
||||
var alertYggToken = '<div id="error_ygg_button_alert" class="alert alert-danger" role="alert" style="margin-bottom:0;">Une erreur est survenue, Vérifiez que votre token Ygg soit chargé !</div>';
|
||||
if (document.readyState !== "complete") {
|
||||
if (document.readyState !== 'complete') {
|
||||
document.addEventListener('readystatechange', function () {
|
||||
downloadLine.childNodes[3].innerHTML = alertYggToken;
|
||||
}, false);
|
||||
@@ -115,13 +115,13 @@ chrome.storage.sync.get(['yggToken', 'discordWebhookUrl', 'discordUserName', 'di
|
||||
|
||||
/* Creation of form */
|
||||
var formNode = document.createElement('form');
|
||||
formNode.name = "form_info";
|
||||
formNode.className = "form-horizontal";
|
||||
formNode.name = 'form_info';
|
||||
formNode.classList.add('form-horizontal');
|
||||
right.appendChild(formNode);
|
||||
|
||||
var row = document.createElement('div');
|
||||
row.className = "row";
|
||||
row.appendChild(getInputCol("Titre", "title", ["error"], "text", torrentTitle,
|
||||
row.classList.add('row');
|
||||
row.appendChild(getInputCol("Titre", 'title', ['error'], 'text', torrentTitle,
|
||||
{
|
||||
onInput: function () {
|
||||
this.classList.remove('error');
|
||||
@@ -131,8 +131,8 @@ chrome.storage.sync.get(['yggToken', 'discordWebhookUrl', 'discordUserName', 'di
|
||||
formNode.appendChild(row);
|
||||
|
||||
formNode.appendChild(getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, torrentYear, torrentQuality, categories));
|
||||
torrentInfo.style.display = "";
|
||||
flexButton.style.display = "";
|
||||
torrentInfo.style.display = '';
|
||||
flexButton.style.display = '';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -142,13 +142,13 @@ chrome.storage.sync.get(['yggToken', 'discordWebhookUrl', 'discordUserName', 'di
|
||||
|
||||
function alert(id) {
|
||||
document.querySelectorAll('.alert').forEach(function (elem) {
|
||||
elem.style.display = "none";
|
||||
elem.style.display = 'none';
|
||||
});
|
||||
document.getElementById(id).style.display = "block";
|
||||
document.getElementById(id).style.display = 'block';
|
||||
}
|
||||
|
||||
function showAlert(id) {
|
||||
if (document.readyState !== "complete") {
|
||||
if (document.readyState !== 'complete') {
|
||||
document.addEventListener('readystatechange', function () {
|
||||
alert(id);
|
||||
}, false);
|
||||
@@ -171,7 +171,7 @@ function addToDiscord() {
|
||||
if (!input) {
|
||||
continue;
|
||||
}
|
||||
if (input.className.includes('error')) {
|
||||
if (input.classList.contains('error')) {
|
||||
showAlert('error_form_alert');
|
||||
return;
|
||||
}
|
||||
@@ -203,8 +203,8 @@ function addToDiscord() {
|
||||
function getInput(name, classes, type, value, attrs = {}) {
|
||||
var inputNode = document.createElement('input');
|
||||
inputNode.name = name;
|
||||
inputNode.className = "form-control " + classes.join(" ");
|
||||
inputNode.setAttribute("type", type);
|
||||
inputNode.classList.add('form-control', ...classes);
|
||||
inputNode.setAttribute('type', type);
|
||||
for (var key in attrs) {
|
||||
inputNode.setAttribute(key, attrs[key]);
|
||||
}
|
||||
@@ -215,17 +215,17 @@ function getInput(name, classes, type, value, attrs = {}) {
|
||||
function getSelect(name, classes, options, selected, attrs = {}) {
|
||||
var selectNode = document.createElement('select');
|
||||
selectNode.name = name;
|
||||
selectNode.className = "form-control " + classes.join(" ");
|
||||
selectNode.classList.add('form-control', ...classes);
|
||||
for (var key in attrs) {
|
||||
selectNode.setAttribute(key, attrs[key]);
|
||||
}
|
||||
for (var index in options) {
|
||||
var type = options[index];
|
||||
var option = document.createElement("option");
|
||||
var option = document.createElement('option');
|
||||
option.value = type;
|
||||
option.text = type;
|
||||
if (type === selected) {
|
||||
option.setAttribute("selected", "selected");
|
||||
option.setAttribute('selected', 'selected');
|
||||
}
|
||||
selectNode.appendChild(option);
|
||||
}
|
||||
@@ -234,12 +234,12 @@ function getSelect(name, classes, options, selected, attrs = {}) {
|
||||
|
||||
function getFormGroup(input, label, name, size) {
|
||||
var labelNode = document.createElement('label');
|
||||
labelNode.className = "control-label";
|
||||
labelNode.setAttribute("for", name);
|
||||
labelNode.classList.add('control-label');
|
||||
labelNode.setAttribute('for', name);
|
||||
labelNode.appendChild(document.createTextNode(label));
|
||||
|
||||
var div = document.createElement('div');
|
||||
div.className = "form-group col-" + size;
|
||||
div.classList.add('form-group', `col-${size}`);
|
||||
div.appendChild(labelNode);
|
||||
div.appendChild(input);
|
||||
return div;
|
||||
@@ -248,7 +248,7 @@ function getFormGroup(input, label, name, size) {
|
||||
function getInputCol(label, name, classes, type, value, {size = 12, attrs = {}, onInput = false}) {
|
||||
var input = getInput(name, classes, type, value, attrs);
|
||||
if (onInput) {
|
||||
input.addEventListener("input", onInput);
|
||||
input.addEventListener('input', onInput);
|
||||
}
|
||||
return getFormGroup(input, label, name, size);
|
||||
}
|
||||
@@ -256,7 +256,7 @@ function getInputCol(label, name, classes, type, value, {size = 12, attrs = {},
|
||||
function getSelectCol(label, name, classes, options, selected, {size = 12, attrs = {}, onInput = false}) {
|
||||
var select = getSelect(name, classes, options, selected, attrs);
|
||||
if (onInput) {
|
||||
select.addEventListener("input", onInput);
|
||||
select.addEventListener('input', onInput);
|
||||
}
|
||||
return getFormGroup(select, label, name, size);
|
||||
}
|
||||
@@ -266,22 +266,34 @@ function getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, tor
|
||||
var classes = [];
|
||||
var onInput = false;
|
||||
var row = document.createElement('div');
|
||||
row.className = "row";
|
||||
row.classList.add('row');
|
||||
if (torrentType.season) {
|
||||
size = 2;
|
||||
if (torrentSeason === '') {
|
||||
classes = ['error'];
|
||||
if (torrentEpisode !== '') {
|
||||
classes = ['error'];
|
||||
} else {
|
||||
classes = ['warning'];
|
||||
}
|
||||
}
|
||||
onInput = function () {
|
||||
torrentSeason = formatEpisodeSeason(this.value);
|
||||
const torrentSeason = formatEpisodeSeason(this.value);
|
||||
const torrentEpisode = formatEpisodeSeason(document.querySelector('form[name="form_info"] input[name="episode"]').value);
|
||||
this.value = torrentSeason;
|
||||
if (torrentSeason === "") {
|
||||
this.className += ' error';
|
||||
if (torrentSeason === '') {
|
||||
if (torrentEpisode !== '') {
|
||||
this.classList.add('error');
|
||||
this.classList.remove('warning');
|
||||
} else {
|
||||
this.classList.add('warning');
|
||||
this.classList.remove('error');
|
||||
}
|
||||
} else {
|
||||
this.classList.remove('warning');
|
||||
this.classList.remove('error');
|
||||
}
|
||||
};
|
||||
row.appendChild(getInputCol("Saison", "season", classes, "number", torrentSeason, {size: size, attrs: {"min": "0"}, onInput: onInput}));
|
||||
row.appendChild(getInputCol("Saison", 'season', classes, 'number', torrentSeason, {size: size, attrs: {'min': '0'}, onInput: onInput}));
|
||||
classes = [];
|
||||
onInput = false;
|
||||
|
||||
@@ -289,26 +301,30 @@ function getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, tor
|
||||
classes = ['warning'];
|
||||
}
|
||||
onInput = function () {
|
||||
torrentEpisode = formatEpisodeSeason(this.value);
|
||||
const torrentEpisode = formatEpisodeSeason(this.value);
|
||||
this.value = torrentEpisode;
|
||||
if (torrentEpisode === "") {
|
||||
this.className += ' warning';
|
||||
if (torrentEpisode === '') {
|
||||
this.classList.add('warning');
|
||||
} else {
|
||||
this.classList.remove('warning');
|
||||
}
|
||||
document.querySelector('form[name="form_info"] input[name="season"]').dispatchEvent(new Event('input', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}));
|
||||
};
|
||||
row.appendChild(getInputCol("Episode", "episode", classes, "number", torrentEpisode, {size: size, attrs: {"min": "0"}, onInput: onInput}));
|
||||
row.appendChild(getInputCol("Episode", 'episode', classes, 'number', torrentEpisode, {size: size, attrs: {'min': '0'}, onInput: onInput}));
|
||||
classes = [];
|
||||
onInput = false;
|
||||
|
||||
var space = document.createElement('div');
|
||||
space.className = 'col-1';
|
||||
space.classList.add('col-1');
|
||||
row.appendChild(space);
|
||||
row.appendChild(getInputCol("ID", "id", [], "text", torrentId, {size: size}));
|
||||
row.appendChild(getInputCol("ID", 'id', [], 'text', torrentId, {size: size}));
|
||||
row.appendChild(space.cloneNode());
|
||||
} else {
|
||||
row.appendChild(getInputCol("ID", "id", [], "text", torrentId, {size: size}));
|
||||
row.appendChild(getInputCol("Year", "year", ['warning'], "text", torrentYear, {size: size,
|
||||
row.appendChild(getInputCol("ID", 'id', [], 'text', torrentId, {size: size}));
|
||||
row.appendChild(getInputCol("Year", 'year', ['warning'], 'text', torrentYear, {size: size,
|
||||
onInput: function () {
|
||||
if (this.value.length !== 4) {
|
||||
this.classList.remove('warning');
|
||||
@@ -322,12 +338,12 @@ function getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, tor
|
||||
);
|
||||
}
|
||||
|
||||
row.appendChild(getInputCol("Quality", "quality", [], "text", torrentQuality, {size: size}));
|
||||
row.appendChild(getInputCol("Quality", 'quality', [], 'text', torrentQuality, {size: size}));
|
||||
|
||||
onInput = function () {
|
||||
torrentType = getTypeFromName(categories, this.options[this.selectedIndex].value);
|
||||
const torrentType = getTypeFromName(categories, this.options[this.selectedIndex].value);
|
||||
if (torrentType.name === 'unknown') {
|
||||
this.className += ' error';
|
||||
this.classList.add('error');
|
||||
} else {
|
||||
this.classList.remove('error');
|
||||
row.replaceWith(getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, torrentYear, torrentQuality, categories));
|
||||
@@ -353,12 +369,12 @@ function getSecondRow(torrentType, torrentSeason, torrentEpisode, torrentId, tor
|
||||
/* Ensure the episode and season number is nice */
|
||||
function formatEpisodeSeason(value) {
|
||||
if (value > 0 && value <= 9) {
|
||||
if (value.includes("0")) {
|
||||
value = "" + parseInt(value);
|
||||
if (value.includes('0')) {
|
||||
value = `${parseInt(value)}`;
|
||||
}
|
||||
value = "0" + value;
|
||||
value = `0${value}`;
|
||||
} else {
|
||||
while (value.substring(0, 1) === "0") {
|
||||
while (value.substring(0, 1) === '0') {
|
||||
value = value.substring(1, value.length);
|
||||
}
|
||||
}
|
||||
@@ -375,9 +391,9 @@ function getTypeFromUrl(categories) {
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "unknown",
|
||||
name: 'unknown',
|
||||
season: false,
|
||||
urls: ["/"]
|
||||
urls: ['/']
|
||||
};
|
||||
}
|
||||
|
||||
@@ -388,8 +404,8 @@ function getTypeFromName(categories, name) {
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "unknown",
|
||||
name: 'unknown',
|
||||
season: false,
|
||||
urls: ["/"]
|
||||
urls: ['/']
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user