Display preview

master
masterhc 1 year ago
parent 8ccc1db550
commit ab1384e491

@ -407,7 +407,17 @@ exports.isValidID = (id) =>
{ {
return mongoose.Types.ObjectId.isValid(id); return mongoose.Types.ObjectId.isValid(id);
} }
/**
*
* @param {String} cookie
* @param {String} name
* @returns
*/
exports.cookieParser = (cookie, name)=>
{
if(!cookie.includes(name)) return null
return cookie.split(name+'=')[1].split(';')[0];
}
/** /**
* @argument {Response} res - Response: express response object. * @argument {Response} res - Response: express response object.
* @argument {String} name - Name of the cookie. * @argument {String} name - Name of the cookie.
@ -466,13 +476,3 @@ exports.Crypto = class Crypto
return Math.floor(Math.random() * (max - min)) + min; return Math.floor(Math.random() * (max - min)) + min;
} }
} }
/**
*
* @param {String} cookie
* @param {String} name
* @returns
*/
exports.cookieParser = (cookie, name)=>
{
return cookie.split(name+'=')[1].split(';')[0];
}

@ -438,7 +438,7 @@ button:hover
} }
.chapterNavButton .chapterNavButton
{ {
background-color: var(--purple-heart-400-50); background-color: var(--purple-heart-500-25);
width: 100px; width: 100px;
height: 30px; height: 30px;
border: 2px solid var(--accent); border: 2px solid var(--accent);
@ -840,7 +840,7 @@ button:hover
} }
.spacer .spacer
{ {
width: 25%; width: 0%;
} }
.chapterOverview .chapterOverview
{ {
@ -896,4 +896,10 @@ button:hover
height: auto; height: auto;
border: 0 solid transparent; border: 0 solid transparent;
border-radius: 5px; border-radius: 5px;
box-sizing: border-box;
cursor: pointer;
}
.flexBox > .inView
{
border: 3px solid var(--accent);
} }

@ -1,12 +1,12 @@
<div class="chapterOverview" id="chapterOverview"> <div class="chapterOverview" id="chapterOverview">
<div class="flexBox" id="flexBox"> <div class="flexBox" id="flexBox">
<% for(var img of data.List){ %> <% for(var [index, img] of data.List.entries()){ %>
<img class="overview" src=<%= img.replaceAll(' ','%20') %> /> <img class="overview" id="img<%= index %>" src=<%= img.replaceAll(' ','%20') %> onclick="_scrollTo('<%= '_img'+index%>')" />
<% } %> <% } %>
</div> </div>
<div class="expand" onclick="toggle()"> <div class="expand" onclick="toggle()">
<span class="material-symbols-outlined" id="expandChevron">chevron_left</span> <span class="material-symbols-outlined" id="expandChevron">chevron_right</span>
</div> </div>
</div> </div>
<div class="wrapperReaderBox"> <div class="wrapperReaderBox">
@ -23,8 +23,8 @@
</div> </div>
<button class="pullBackUp" onclick="pullUp()"> <span class="material-symbols-outlined chevronUp">expand_less</span></button> <button class="pullBackUp" onclick="pullUp()"> <span class="material-symbols-outlined chevronUp">expand_less</span></button>
<div id="display"> <div id="display">
<% for(var img of data.List){ %> <% for(var [index, img] of data.List.entries()){ %>
<img src=<%= img.replaceAll(' ','%20') %> /> <img id="_img<%= index %>" src=<%= img.replaceAll(' ','%20') %> alt="img<%= index %>"/>
<% } %> <% } %>
<div id="last-image" <div id="last-image"
hx-post="/chapterRead/<%= data.scanlator %>/<%= encodeURIComponent(data.mangaLink)%>/<%= data.title %>/<%= data.chapterNum %>" hx-post="/chapterRead/<%= data.scanlator %>/<%= encodeURIComponent(data.mangaLink)%>/<%= data.title %>/<%= data.chapterNum %>"
@ -44,29 +44,59 @@
</div> </div>
<script> <script>
clearVariables(); clearVariables();
handleInView();
function clearVariables()
{
[ 'lastImage',
'observer',
'flexBox',
'chapterOverview',
'chevron',
'spacer',
'preview',
'elements',
'windowHeight',
'bounding',
'element',
'elementId'
].forEach((variable) =>
{
if (window.hasOwnProperty(variable))
{
delete window[variable];
}
});
}
function pullUp() function pullUp()
{ {
window.scrollTo({ top: 0, behavior: 'smooth' }) window.scrollTo({ top: 0, behavior: 'smooth' })
} }
window.addEventListener('scroll', function() { function _scrollTo(elementId)
var elements = document.querySelectorAll('.your-element-class'); // Replace '.your-element-class' with the class of the elements you want to check {
var windowHeight = window.innerHeight; document.getElementById(elementId).scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
elements.forEach(function(element) { window.addEventListener('scroll', handleInView);
function handleInView()
{
var elements = document.querySelectorAll('#display img'); // Replace '.your-element-class' with the class of the elements you want to check
var windowHeight = window.innerHeight;
elements.forEach((element)=>
{
var bounding = element.getBoundingClientRect(); var bounding = element.getBoundingClientRect();
if ( if (bounding.top<windowHeight && (bounding.top + bounding.height) > windowHeight)
bounding.top >= 0 && {
bounding.bottom <= windowHeight if(document.querySelector('.inView')) document.querySelector('.inView').classList.remove('inView');
) { document.getElementById(element.alt).classList.add('inView');
// Element is in view
console.log(element.textContent + ' is in view.');
} else {
// Element is not in view
console.log(element.textContent + ' is not in view.');
} }
}); });
}); };
function toggle() function toggle()
{ {
let flexBox = document.getElementById('flexBox'); let flexBox = document.getElementById('flexBox');
@ -114,23 +144,7 @@
if(!document.cookie) return ''; if(!document.cookie) return '';
return document.cookie.split(name+'=')[1].split(';')[0]; return document.cookie.split(name+'=')[1].split(';')[0];
} }
function clearVariables()
{
[ 'lastImage',
'observer',
'flexBox',
'chapterOverview',
'chevron',
'spacer',
'preview',
].forEach((variable) =>
{
if (window.hasOwnProperty(variable))
{
delete window[variable];
}
});
}
function hasFinished() function hasFinished()
{ {
const lastImage = document.getElementById('last-image'); const lastImage = document.getElementById('last-image');
@ -147,23 +161,15 @@
function checkPreview() function checkPreview()
{ {
let preview = getCookie('preview'); let preview = getCookie('preview');
console.log(preview, preview == 'preview')
if(preview=='preview') return openPreview(); if(preview=='preview') return openPreview();
return closePreview(); return closePreview();
} }
function imageInView()
{
}
try { try {
hasFinished(); hasFinished();
imageInView();
checkPreview(); checkPreview();
} catch (error) { } catch (error) {
clearVariables(); clearVariables();
hasFinished(); hasFinished();
imageInView();
checkPreview(); checkPreview();
} }
</script> </script>
Loading…
Cancel
Save