Add pretty table formatting
This commit is contained in:
parent
cac182dfab
commit
c1a9cf3ad3
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name AnimeBytes Mediainfo Improvements
|
||||
// @author WeebDataHoarder
|
||||
// @version 1.8.6
|
||||
// @version 1.9.0
|
||||
// @downloadURL https://git.gammaspectra.live/WeebDataHoarder/userscripts/raw/branch/master/AnimeBytes/ab-mediainfo.user.js
|
||||
// @updateURL https://git.gammaspectra.live/WeebDataHoarder/userscripts/raw/branch/master/AnimeBytes/ab-mediainfo.user.js
|
||||
// @description AnimeBytes Mediainfo Improvements. Adds several listing and matching releases against mediainfo utilities. MIT license
|
||||
|
@ -58,7 +58,11 @@ function parseMediaInfo(text){
|
|||
return ob;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param v
|
||||
* @param legacy
|
||||
* @returns String
|
||||
*/
|
||||
function getLineTagEntry(v, legacy){
|
||||
if(typeof v === 'object'){
|
||||
return legacy ? v.legacy : (v.name/* + ("lossless" in v ? " (Lossless)" : "")*/);
|
||||
|
@ -91,7 +95,9 @@ function getComparisonLine(tags){
|
|||
entries.push(tags.aspectRatio);
|
||||
}
|
||||
|
||||
if("videoCodec" in tags){
|
||||
if("videoCodec" in tags && !(
|
||||
getLineTagEntry(tags.source, true).match(/^DVD[59]$/) !== null
|
||||
)){
|
||||
entries.push(getLineTagEntry(tags.videoCodec, true));
|
||||
}
|
||||
entries.push(tags.resolution);
|
||||
|
@ -104,31 +110,39 @@ function getComparisonLine(tags){
|
|||
return entries.join(" | ");
|
||||
}
|
||||
|
||||
function getEntryLine(tags){
|
||||
function getEntryLine(tags, infoCount, warningCount, dangerCount){
|
||||
// Source + container + remux | Codec / Resolution / HDR | Audio + Dual + commentary | Text | OtherTags | icons
|
||||
let entries = {
|
||||
source: [],
|
||||
video: [],
|
||||
audio: [],
|
||||
text: [],
|
||||
other: [],
|
||||
icons: []
|
||||
};
|
||||
entries.source.push(getLineTagEntry(tags.source, false) + ("sourceName" in tags ? " (" + tags.sourceName + ")" : ""));
|
||||
entries.source.push(getLineTagEntry(tags.container, false) + ("region" in tags ? " (" + tags.region + ")" : ""));
|
||||
|
||||
let entries = [];
|
||||
entries.push(getLineTagEntry(tags.source, false) + ("sourceName" in tags ? " (" + tags.sourceName + ")" : ""));
|
||||
entries.push(getLineTagEntry(tags.container, false) + ("region" in tags ? " (" + tags.region + ")" : ""));
|
||||
entries.push(getLineTagEntry(tags.videoCodec, false) + ("videoEncoder" in tags ? " (" + tags.videoEncoder + ("videoCRF" in tags ? " " + tags.videoCRF : "") + ")" : ""));
|
||||
entries.video.push(getLineTagEntry(tags.videoCodec, false) + ("videoEncoder" in tags ? " (" + tags.videoEncoder + ("videoCRF" in tags ? " " + tags.videoCRF : "") + ")" : ""));
|
||||
entries.video.push(tags.resolution + ("aspectRatio" in tags ? " " + tags.aspectRatio : "") /* + ("videoFrameRate" in tags ? " @ " + tags.videoFrameRate : "")*/);
|
||||
if("videoHDR" in tags){
|
||||
entries.push(getLineTagEntry(tags.videoHDR, false));
|
||||
entries.video.push(getLineTagEntry(tags.videoHDR, false));
|
||||
}
|
||||
entries.push(tags.resolution + ("aspectRatio" in tags ? " " + tags.aspectRatio : "") /* + ("videoFrameRate" in tags ? " @ " + tags.videoFrameRate : "")*/);
|
||||
|
||||
entries.push(getLineTagEntry(tags.audioCodec, false) + " " + getAudioChannels(tags.audioChannels));
|
||||
entries.audio.push(getLineTagEntry(tags.audioCodec, false) + " " + getAudioChannels(tags.audioChannels));
|
||||
if(tags.audioCount > 1){
|
||||
entries.push("Dual Audio");
|
||||
entries.audio.push("Dual");
|
||||
}
|
||||
|
||||
if("audioCommentary" in tags && tags.audioCommentary){
|
||||
entries.push("Commentary");
|
||||
entries.audio.push("Commentary");
|
||||
}
|
||||
|
||||
if("remux" in tags){
|
||||
if(tags.remux === true){
|
||||
entries.push("REMUX");
|
||||
entries.source.push("REMUX");
|
||||
}else if(tags.remux === "probably"){
|
||||
entries.push("REMUX*");
|
||||
entries.source.push("REMUX*");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,10 +151,10 @@ function getEntryLine(tags){
|
|||
img.src = "/static/common/rmstr.png";
|
||||
img.alt = "Remastered";
|
||||
img.title = "This torrent is from a remastered source!";
|
||||
entries.push(img);
|
||||
entries.other.push(img);
|
||||
}
|
||||
|
||||
entries.push(("subtitleCodec" in tags ? tags.subtitleCodec + " " : "") + ("subtitleType" in tags ? getLineTagEntry(tags.subtitleType, false) : "RAW") + ("group" in tags ? " (" + tags.group + ")" : ""));
|
||||
entries.text.push(("subtitleCodec" in tags ? tags.subtitleCodec + " " : "") + ("subtitleType" in tags ? getLineTagEntry(tags.subtitleType, false) : "RAW") + ("group" in tags ? " (" + tags.group + ")" : ""));
|
||||
|
||||
|
||||
|
||||
|
@ -149,9 +163,38 @@ function getEntryLine(tags){
|
|||
img.src = "/static/common/flicon.png";
|
||||
img.alt = "Freeleech!";
|
||||
img.title = "This torrent is freeleech. Remember to seed!";
|
||||
entries.push(img);
|
||||
entries.other.push(img);
|
||||
}
|
||||
|
||||
if("chapters" in tags){
|
||||
entries.other.push(tags.chapters === "ordered" ? "Ordered Chapters" : "Chapters");
|
||||
}
|
||||
|
||||
if(tags.snatched){
|
||||
entries.other.push("Snatched");
|
||||
}
|
||||
|
||||
if(infoCount > 0 || warningCount > 0 || dangerCount > 0){
|
||||
|
||||
let span = document.createElement("span");
|
||||
|
||||
for(let i = 0; i < infoCount; ++i){
|
||||
span.append("★");
|
||||
}
|
||||
for(let i = 0; i < warningCount; ++i){
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "/static/common/symbols/warned.png";
|
||||
span.append(icon);
|
||||
}
|
||||
for(let i = 0; i < dangerCount; ++i){
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "/static/common/symbols/disabled.png";
|
||||
span.append(icon);
|
||||
}
|
||||
entries.icons.unshift(span);
|
||||
}
|
||||
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
@ -467,6 +510,14 @@ const videoCodecs = [
|
|||
},
|
||||
legacy: "MPEG-1/2"
|
||||
},
|
||||
{
|
||||
name: "MPEG-$version",
|
||||
match: {
|
||||
format: "MPEG Video",
|
||||
format_version: /^Version (?<version>[12])$/,
|
||||
},
|
||||
legacy: "MPEG-1/2"
|
||||
},
|
||||
|
||||
{
|
||||
name: "h264",
|
||||
|
@ -559,8 +610,14 @@ const videoCodecs = [
|
|||
];
|
||||
|
||||
const torrentType = document.querySelector("a.scaledImg > img").getAttribute("title");
|
||||
|
||||
const torrentTableColspan = 6;
|
||||
if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
||||
|
||||
//Make page wider
|
||||
let contentStyle = document.getElementById("content").style;
|
||||
contentStyle["max-width"] = "1400px";
|
||||
contentStyle["width"] = "calc(100% - 50px)";
|
||||
|
||||
let episodeCount = 0;
|
||||
document.querySelectorAll("ul.stats > li").forEach((item) => {
|
||||
let strongItem = item.querySelector("strong");
|
||||
|
@ -644,6 +701,7 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
|
||||
const dataSection = document.getElementById("torrent_" + torrentId);
|
||||
if(dataSection !== null){
|
||||
torrent.elements.data = dataSection;
|
||||
const descriptionSection = document.getElementById(torrentId + "_description");
|
||||
const filelistSection = document.getElementById(torrentId + "_filelist");
|
||||
const mediaInfoSection = document.getElementById(torrentId + "_mediainfo");
|
||||
|
@ -716,11 +774,101 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
}
|
||||
});
|
||||
|
||||
{
|
||||
{
|
||||
let parentTd = document.querySelector("table.torrent_table tr > td");
|
||||
parentTd.insertAdjacentElement("beforebegin", document.createElement("td"));
|
||||
// Source + container + remux | Codec / Resolution / HDR | Audio + Dual + commentary | Text | OtherTags | Icons
|
||||
parentTd.setAttribute("colspan", torrentTableColspan.toString());
|
||||
|
||||
document.querySelectorAll("table.torrent_table tr.edition_info > td").forEach((e) => {
|
||||
e.setAttribute("colspan", (torrentTableColspan + 1 + 4).toString());
|
||||
});
|
||||
}
|
||||
|
||||
torrentListing.forEach((torrent) => {
|
||||
let parent = torrent.elements.link.parentElement;
|
||||
let td = document.createElement("td");
|
||||
|
||||
torrent.elements.data.querySelector("td").setAttribute("colspan", (torrentTableColspan + 1 + 4).toString());
|
||||
|
||||
parent.parentElement.insertAdjacentElement("beforebegin", td);
|
||||
parent.style["white-space"] = "nowrap";
|
||||
td.append(parent);
|
||||
|
||||
Array.from(parent.childNodes).forEach((e) => {
|
||||
if(e.nodeType === Node.TEXT_NODE && ["[", "]"].includes(e.textContent.trim())){
|
||||
e.remove();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
console.log(torrentListing);
|
||||
|
||||
torrentListing.forEach((torrent) => {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
let infoCount = 0;
|
||||
let warningCount = 0;
|
||||
let dangerCount = 0;
|
||||
|
||||
|
||||
let tags = {
|
||||
|
||||
};
|
||||
|
||||
let warnings = {
|
||||
general: [],
|
||||
audio: [],
|
||||
video: [],
|
||||
text: []
|
||||
}
|
||||
|
||||
let fileName = null;
|
||||
|
||||
if("mediainfo" in torrent && torrent.mediainfo.length > 0 && "mediainfo.general.complete_name" in torrent.mediainfo[0].general){
|
||||
[fileName] = torrent.mediainfo[0].general.complete_name.split("/").slice(-1);
|
||||
}else{
|
||||
fileName = torrent.filelist[0].path;
|
||||
}
|
||||
|
||||
//handle file tags
|
||||
fileName.split(".").forEach((p) => {
|
||||
if(p.toUpperCase() === "NF"){
|
||||
tags.sourceName = "Netflix";
|
||||
}else if(p.toUpperCase() === "ATVP"){
|
||||
tags.sourceName = "Apple TV+";
|
||||
}else if(p.toUpperCase() === "AMZN"){
|
||||
tags.sourceName = "Amazon Video";
|
||||
}else if(p === "HDR"){
|
||||
tags.videoHDR = "HDR";
|
||||
}else if(p === "HDR10"){
|
||||
tags.videoHDR = "HDR10";
|
||||
}else if(p === "DV"){
|
||||
tags.videoHDR = "HDR DV";
|
||||
}else if(p.toUpperCase() === "REMUX"){
|
||||
tags.remux = true;
|
||||
}
|
||||
});
|
||||
|
||||
fileName.split(/[ _\[\]]/).forEach((p) => {
|
||||
if(p.toUpperCase() === "NETFLIX"){
|
||||
tags.sourceName = "Netflix";
|
||||
}else if(p === "HDR"){
|
||||
tags.videoHDR = "HDR";
|
||||
}else if(p === "HDR10"){
|
||||
tags.videoHDR = "HDR10";
|
||||
}else if(p === "DV"){
|
||||
tags.videoHDR = "HDR DV";
|
||||
}else if(p.toUpperCase().indexOf("REMUX") !== -1){
|
||||
tags.remux = true;
|
||||
}
|
||||
});
|
||||
|
||||
if("mediainfo" in torrent && torrent.mediainfo.length > 0){
|
||||
let mediainfo = torrent.mediainfo[0];
|
||||
|
||||
|
@ -731,18 +879,6 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
let englishSubs = null;
|
||||
let defaultSubs = null;
|
||||
|
||||
|
||||
let tags = {
|
||||
|
||||
};
|
||||
|
||||
let warnings = {
|
||||
general: [],
|
||||
audio: [],
|
||||
video: [],
|
||||
text: []
|
||||
}
|
||||
|
||||
switch(mediainfo.general.format){
|
||||
case "Matroska":
|
||||
tags.container = "MKV";
|
||||
|
@ -752,53 +888,10 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
break;
|
||||
}
|
||||
|
||||
let fileName = null;
|
||||
|
||||
if("mediainfo.general.complete_name" in mediainfo.general){
|
||||
[fileName] = mediainfo.general.complete_name.split("/").slice(-1);
|
||||
}else{
|
||||
fileName = torrent.filelist[0].path;
|
||||
}
|
||||
|
||||
if(torrent.mediainfoSource !== "mediainfo"){
|
||||
warnings.general.push(["danger", "Mediainfo sourced from " + torrent.mediainfoSource + ". Consider reporting the torrent and providing it."])
|
||||
}
|
||||
|
||||
//handle file tags
|
||||
fileName.split(".").forEach((p) => {
|
||||
if(p.toUpperCase() === "NF"){
|
||||
tags.sourceName = "Netflix";
|
||||
}else if(p.toUpperCase() === "ATVP"){
|
||||
tags.sourceName = "Apple TV+";
|
||||
}else if(p.toUpperCase() === "AMZN"){
|
||||
tags.sourceName = "Amazon Video";
|
||||
}else if(p === "HDR"){
|
||||
tags.videoHDR = "HDR";
|
||||
}else if(p === "HDR10"){
|
||||
tags.videoHDR = "HDR10";
|
||||
}else if(p === "DV"){
|
||||
tags.videoHDR = "HDR DV";
|
||||
}else if(p.toUpperCase() === "REMUX"){
|
||||
tags.remux = true;
|
||||
}
|
||||
});
|
||||
|
||||
[" ", "_"].forEach((c) => {
|
||||
fileName.split(c).forEach((p) => {
|
||||
if(p.toUpperCase() === "NETFLIX"){
|
||||
tags.sourceName = "Netflix";
|
||||
}else if(p === "HDR"){
|
||||
tags.videoHDR = "HDR";
|
||||
}else if(p === "HDR10"){
|
||||
tags.videoHDR = "HDR10";
|
||||
}else if(p === "DV"){
|
||||
tags.videoHDR = "HDR DV";
|
||||
}else if(p.toUpperCase().indexOf("REMUX") !== -1){
|
||||
tags.remux = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
let video = mediainfo.video[0];
|
||||
if(video !== null){
|
||||
|
@ -1120,7 +1213,7 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
tags.subtitleType = "Softsubs";
|
||||
}
|
||||
}
|
||||
if(tags.subtitleType === "Softsubs" && (text === null || englishSubs === null)){
|
||||
if((tags.subtitleType === "Softsubs" || torrent.tags.subtitleType === "Softsubs") && (text === null || englishSubs === null)){
|
||||
if(isTrackExternal){
|
||||
tags.subtitleType = "Softsubs";
|
||||
tags.subtitleCodec = "External " + externalTrackFormat;
|
||||
|
@ -1131,7 +1224,9 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
}
|
||||
|
||||
if("menu" in mediainfo){
|
||||
//Check for ordered chapters
|
||||
//Check for chapters and ordered chapters
|
||||
|
||||
let chapterCount = 0;
|
||||
for(const [key, value] of Object.entries(mediainfo.menu)){
|
||||
let entryCount = 0;
|
||||
value.split(" / ").forEach((i) => {
|
||||
|
@ -1141,162 +1236,156 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
|
|||
}
|
||||
});
|
||||
|
||||
if(entryCount > 1){
|
||||
tags.orderedChapters = true;
|
||||
if(entryCount > 1 && !("chapters" in tags)){
|
||||
tags.chapters = "ordered";
|
||||
warnings.general.push(["danger", "Found Ordered Chapters"]);
|
||||
}
|
||||
++chapterCount;
|
||||
}
|
||||
|
||||
if(!("chapters" in tags) && chapterCount > 1){
|
||||
tags.chapters = chapterCount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for(const [key, value] of Object.entries(torrent.tags)){
|
||||
if(!(key in tags)){
|
||||
tags[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if(!("aspectRatio" in torrent.tags)){
|
||||
torrent.tags.aspectRatio = tags.aspectRatio;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let oldTagLine = getComparisonLine(torrent.tags);
|
||||
let newTagLine = getComparisonLine(tags);
|
||||
|
||||
if(newTagLine !== oldTagLine){
|
||||
warnings.general.push(["danger", "Tag mismatch:\nold: " + oldTagLine + " !=\nnew: " + newTagLine]);
|
||||
}
|
||||
|
||||
while(torrent.elements.entry.firstChild){
|
||||
torrent.elements.entry.firstChild.remove();
|
||||
}
|
||||
|
||||
getEntryLine(tags).forEach((e) => {
|
||||
if(torrent.elements.entry.firstChild){
|
||||
torrent.elements.entry.append(" | ");
|
||||
}
|
||||
torrent.elements.entry.append(e);
|
||||
});
|
||||
|
||||
if(tags.snatched){
|
||||
torrent.elements.entry.append(" - Snatched");
|
||||
}
|
||||
|
||||
|
||||
|
||||
let infoCount = 0;
|
||||
let warningCount = 0;
|
||||
let dangerCount = 0;
|
||||
|
||||
|
||||
let messages = document.createElement("div");
|
||||
messages.append(document.createElement("br"));
|
||||
let h2 = document.createElement("h2");
|
||||
h2.textContent = "Warning Messages";
|
||||
messages.append(h2);
|
||||
|
||||
for(const [key, value] of Object.entries(warnings)){
|
||||
if(value.length > 0){
|
||||
|
||||
let h3 = document.createElement("h3");
|
||||
h3.textContent = key.toUpperCase();
|
||||
messages.append(h3);
|
||||
|
||||
let messageList = document.createElement("ul");
|
||||
|
||||
for(let v of value){
|
||||
let li = document.createElement("li");
|
||||
li.style.float = "inherit";
|
||||
let value = "";
|
||||
if(Array.isArray(v)){
|
||||
|
||||
switch (v[0]){
|
||||
case "info":
|
||||
infoCount++;
|
||||
value = "info: " + v[1];
|
||||
break;
|
||||
case "warning":
|
||||
warningCount++;
|
||||
value = "warning: " + v[1];
|
||||
break;
|
||||
case "danger":
|
||||
dangerCount++;
|
||||
value = "danger: " + v[1];
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
++warningCount;
|
||||
value = v;
|
||||
}
|
||||
|
||||
if(value.includes("\n")){
|
||||
let pre = document.createElement("pre");
|
||||
pre.textContent = value;
|
||||
li.append(pre);
|
||||
}else{
|
||||
li.textContent = value;
|
||||
}
|
||||
|
||||
messageList.append(li);
|
||||
}
|
||||
|
||||
messages.append(messageList);
|
||||
messages.append(document.createElement("br"));
|
||||
}
|
||||
}
|
||||
messages.append(document.createElement("hr"));
|
||||
|
||||
if(infoCount > 0 || warningCount > 0 || dangerCount > 0){
|
||||
torrent.elements.item.style["font-style"] = "italic";
|
||||
if("description" in torrent.elements){
|
||||
torrent.elements.description.prepend(messages);
|
||||
}
|
||||
|
||||
torrent.elements.entry.prepend(" - ");
|
||||
for(let i = 0; i < infoCount; ++i){
|
||||
torrent.elements.entry.prepend("★");
|
||||
}
|
||||
for(let i = 0; i < warningCount; ++i){
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "/static/common/symbols/warned.png";
|
||||
torrent.elements.entry.prepend(icon);
|
||||
}
|
||||
for(let i = 0; i < dangerCount; ++i){
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "/static/common/symbols/disabled.png";
|
||||
torrent.elements.entry.prepend(icon);
|
||||
}
|
||||
}
|
||||
|
||||
torrent.elements.entry.prepend("» ")
|
||||
//torrent.elements.entry.prepend("» ");
|
||||
|
||||
}else{
|
||||
torrent.elements.item.style["font-style"] = "italic";
|
||||
torrent.elements.item.style["text-decoration"] = "line-through";
|
||||
let pre = document.createElement("pre");
|
||||
pre.textContent = "== WARNINGS ==\n\nwarning: No valid mediainfo section found. Maybe check Description?\n\n";
|
||||
if("description" in torrent.elements){
|
||||
torrent.elements.description.prepend(pre);
|
||||
}
|
||||
//torrent.elements.item.style["text-decoration"] = "line-through";
|
||||
|
||||
torrent.elements.entry.prepend(" - ");
|
||||
for(let i = 0; i < 1; ++i){
|
||||
let icon = document.createElement("img");
|
||||
icon.src = "/static/common/symbols/disabled.png";
|
||||
torrent.elements.entry.prepend(icon);
|
||||
|
||||
warnings.text.push(["danger", "No valid mediainfo section found. Report torrent with MediaInfo."]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(const [key, value] of Object.entries(torrent.tags)){
|
||||
if(!(key in tags)){
|
||||
tags[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
if(!("aspectRatio" in torrent.tags) && "aspectRatio" in tags){
|
||||
torrent.tags.aspectRatio = tags.aspectRatio;
|
||||
}
|
||||
|
||||
let oldTagLine = getComparisonLine(torrent.tags);
|
||||
let newTagLine = getComparisonLine(tags);
|
||||
|
||||
if(newTagLine !== oldTagLine){
|
||||
warnings.general.push(["danger", "Tag mismatch:\nold: " + oldTagLine + " !=\nnew: " + newTagLine]);
|
||||
}
|
||||
|
||||
|
||||
let messages = document.createElement("div");
|
||||
messages.append(document.createElement("br"));
|
||||
let h2 = document.createElement("h2");
|
||||
h2.textContent = "Warning Messages";
|
||||
messages.append(h2);
|
||||
|
||||
for(const [key, value] of Object.entries(warnings)){
|
||||
if(value.length > 0){
|
||||
|
||||
let h3 = document.createElement("h3");
|
||||
h3.textContent = key.toUpperCase();
|
||||
messages.append(h3);
|
||||
|
||||
let messageList = document.createElement("ul");
|
||||
|
||||
for(let v of value){
|
||||
let li = document.createElement("li");
|
||||
li.style.float = "inherit";
|
||||
let value = "";
|
||||
if(Array.isArray(v)){
|
||||
|
||||
switch (v[0]){
|
||||
case "info":
|
||||
infoCount++;
|
||||
value = "info: " + v[1];
|
||||
break;
|
||||
case "warning":
|
||||
warningCount++;
|
||||
value = "warning: " + v[1];
|
||||
break;
|
||||
case "danger":
|
||||
dangerCount++;
|
||||
value = "danger: " + v[1];
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
++warningCount;
|
||||
value = v;
|
||||
}
|
||||
|
||||
if(value.includes("\n")){
|
||||
let pre = document.createElement("pre");
|
||||
pre.textContent = value;
|
||||
li.append(pre);
|
||||
}else{
|
||||
li.textContent = value;
|
||||
}
|
||||
|
||||
messageList.append(li);
|
||||
}
|
||||
|
||||
messages.append(messageList);
|
||||
messages.append(document.createElement("br"));
|
||||
}
|
||||
}
|
||||
messages.append(document.createElement("hr"));
|
||||
|
||||
if(infoCount > 0 || warningCount > 0 || dangerCount > 0){
|
||||
if("description" in torrent.elements){
|
||||
torrent.elements.description.prepend(messages);
|
||||
}
|
||||
}
|
||||
|
||||
/*while(torrent.elements.entry.firstChild){
|
||||
torrent.elements.entry.firstChild.remove();
|
||||
}*/
|
||||
torrent.elements.entry.parentElement.remove();
|
||||
|
||||
|
||||
let entries = getEntryLine(tags, infoCount, warningCount, dangerCount);
|
||||
|
||||
let lastTd = torrent.elements.item.querySelector("td");
|
||||
|
||||
let onclickFn = (e) => {
|
||||
torrent.elements.data.classList.toggle("hide");
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
["icons", "source", "video", "audio", "text", "other"].forEach((k) => {
|
||||
let td = document.createElement("td");
|
||||
td.style["white-space"] = "nowrap";
|
||||
if(k !== "other"){
|
||||
td.style["width"] = "1%";
|
||||
}
|
||||
td.style["cursor"] = "pointer";
|
||||
|
||||
let a = document.createElement("a");
|
||||
if(tags.snatched){
|
||||
a.classList.add("snatched-torrent");
|
||||
}
|
||||
a.setAttribute("href", torrent.elements.entry.href);
|
||||
|
||||
a.addEventListener("click", (e) => e.preventDefault());
|
||||
td.addEventListener("click", onclickFn);
|
||||
|
||||
entries[k].forEach((e) => {
|
||||
if(a.firstChild){
|
||||
a.append(" / ");
|
||||
}
|
||||
a.append(e);
|
||||
});
|
||||
|
||||
td.append(a);
|
||||
|
||||
lastTd.insertAdjacentElement("afterend", td)
|
||||
lastTd = td;
|
||||
});
|
||||
|
||||
|
||||
}catch (e){
|
||||
console.log("Error:", e);
|
||||
|
|
Loading…
Reference in a new issue