From a4150f41ce06bc9b30c6155a0591c484f345d930 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sun, 23 May 2021 22:47:14 +0300 Subject: [PATCH] code dump --- autoindex.js | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/autoindex.js b/autoindex.js index f9a019a..e1ef450 100644 --- a/autoindex.js +++ b/autoindex.js @@ -5,16 +5,16 @@ const infoRegex = /(-thumb)?\.(jpg|nfo|srt)$/; const arrow = ` + viewBox="0 0 492 492" style="enable-background:new 0 0 492 492;" xml:space="preserve"> - - - + + + ` @@ -45,7 +45,7 @@ function deduplicateJointEpisode(textContent) { result.push(line); } resolve(result.join('\n')); - }) + }); } const parser = new window.DOMParser(); @@ -76,6 +76,7 @@ function createOrImproveMovieMeta(original, thumbnail, nfo) { original.classList.add('movie'); original.innerHTML = imgTag + '
' + movieTitle + movieDescription + '
'; original.parentElement.classList.add('enhanced'); + // quick innerHTML hack to create elements here lol imgTag = original.querySelector('.thumbnail'); movieTitle = original.querySelector('.movie-title'); movieDescription = original.querySelector('.movie-description'); @@ -91,15 +92,16 @@ function createOrImproveMovieMeta(original, thumbnail, nfo) { const titleEl = content.querySelector('title'); const plotEl = content.querySelector('plot'); const airedEl = content.querySelector('aired'); + const premieredEl = content.querySelector('premiered'); if (!titleEl || !plotEl) { return; } - if (airedEl) { + if (airedEl || premieredEl) { const timestamp = original.parentElement.parentElement.querySelector('.timestamp'); if (timestamp) { - timestamp.innerText = airedEl.textContent; + timestamp.innerText = (airedEl || premieredEl).textContent; } } @@ -117,7 +119,6 @@ function createOrImproveMovieMeta(original, thumbnail, nfo) { } let tvShow; - function accountForMetadata() { allLinks.forEach((link) => { const url = link.getAttribute('href'); @@ -125,8 +126,8 @@ function accountForMetadata() { link.parentElement.parentElement.style.display = 'none'; let findOriginal if (url === 'tvshow.nfo' || url === 'poster.jpg') { - // dirty hack - if (url === 'poster.jpg' && window.location.pathname.includes('/movies/')) { + const isTVShow = allLinks.find((found) => found.getAttribute('href') === 'tvshow.nfo'); + if (url === 'poster.jpg' && !isTVShow) { findOriginal = document.querySelector('a:not([href=".."])'); } else { if (tvShow) { @@ -145,13 +146,13 @@ function accountForMetadata() { const sn = url.match(/season(\d+)/); if (sn) { const number = parseInt(sn[1], 10); - const findByNumber = allLinks.filter((url) => url.innerText.includes(number)); - if (findByNumber.length) { - findOriginal = findByNumber[0]; + const findByNumber = allLinks.find((allurl) => allurl.innerText.includes(number)); + if (findByNumber) { + findOriginal = findByNumber; } } } else { - findOriginal = findByInfoFile(encodeURIComponent(decodeURIComponent(url))); + findOriginal = findByInfoFile(url); } if (findOriginal) { createOrImproveMovieMeta(findOriginal, @@ -200,8 +201,3 @@ if ('localStorage' in window) { } else { accountForMetadata(); } -/* -const loc = 'Index of ' + decodeURIComponent(document.location.pathname); -document.getElementById('dirname').innerHTML = loc; -document.title = loc; -*/