This commit is contained in:
plebeius.eth
2023-09-16 21:40:23 +02:00
parent d963c90d26
commit 020e509b71
39 changed files with 1970 additions and 2035 deletions
+13 -14
View File
@@ -1,20 +1,19 @@
function countLinks(comment) {
let linkCount = 0;
let linkCount = 0;
if (comment.replyCount > 0) {
for (let reply of comment.replies.pages.topAll.comments) {
if (comment.replyCount > 0) {
for (let reply of comment.replies.pages.topAll.comments) {
if (reply.link) {
linkCount++;
}
if (reply.link) {
linkCount++;
}
if (reply.replyCount > 0) {
linkCount += countLinks(reply);
}
}
}
if (reply.replyCount > 0) {
linkCount += countLinks(reply);
}
}
}
return linkCount;
return linkCount;
}
export default countLinks;
export default countLinks;
+14 -14
View File
@@ -1,18 +1,18 @@
function findShortParentCid(parentCid, input) {
const feed = Array.isArray(input) ? input : [input];
const feed = Array.isArray(input) ? input : [input];
for (const thread of feed) {
if (thread.cid === parentCid) {
return thread.shortCid;
}
if (thread.replyCount > 0 && thread.replies.pages.topAll.comments) {
const shortCid = findShortParentCid(parentCid, thread.replies.pages.topAll.comments);
if (shortCid) {
return shortCid;
}
}
}
return null;
for (const thread of feed) {
if (thread.cid === parentCid) {
return thread.shortCid;
}
if (thread.replyCount > 0 && thread.replies.pages.topAll.comments) {
const shortCid = findShortParentCid(parentCid, thread.replies.pages.topAll.comments);
if (shortCid) {
return shortCid;
}
}
}
return null;
}
export default findShortParentCid;
export default findShortParentCid;
+63 -65
View File
@@ -2,79 +2,77 @@ import extName from 'ext-name';
import { canEmbed } from '../components/Embed';
const getCommentMediaInfo = (comment) => {
if (!comment?.thumbnailUrl && !comment?.link) {
return;
}
if (!comment?.thumbnailUrl && !comment?.link) {
return;
}
if (comment?.link) {
try {
const url = new URL(comment.link);
const host = url.hostname;
let scrapedThumbnailUrl;
if (comment?.link) {
try {
const url = new URL(comment.link);
const host = url.hostname;
let scrapedThumbnailUrl;
if (['youtube.com', 'www.youtube.com', 'youtu.be'].includes(host)) {
const videoId = host === 'youtu.be' ? url.pathname.slice(1) : url.searchParams.get('v');
scrapedThumbnailUrl = `https://img.youtube.com/vi/${videoId}/sddefault.jpg`;
if (['youtube.com', 'www.youtube.com', 'youtu.be'].includes(host)) {
const videoId = host === 'youtu.be' ? url.pathname.slice(1) : url.searchParams.get('v');
scrapedThumbnailUrl = `https://img.youtube.com/vi/${videoId}/sddefault.jpg`;
} else if (host.includes('bitchute.com')) {
const videoId = url.pathname.split('/')[2];
scrapedThumbnailUrl = `https://static-3.bitchute.com/live/cover_images/F61vWF4shy8s/${videoId}_640x360.jpg`;
} else if (host.includes('streamable.com')) {
const videoId = url.pathname.split('/')[1];
scrapedThumbnailUrl = `https://cdn-cf-east.streamable.com/image/${videoId}.jpg`;
}
} else if (host.includes('bitchute.com')) {
const videoId = url.pathname.split('/')[2];
scrapedThumbnailUrl = `https://static-3.bitchute.com/live/cover_images/F61vWF4shy8s/${videoId}_640x360.jpg`;
if (canEmbed(url)) {
return {
url: comment.link,
type: 'iframe',
thumbnail: comment.thumbnailUrl || scrapedThumbnailUrl,
};
}
} else if (host.includes('streamable.com')) {
const videoId = url.pathname.split('/')[1];
scrapedThumbnailUrl = `https://cdn-cf-east.streamable.com/image/${videoId}.jpg`;
}
const mime = extName(url.pathname.toLowerCase().replace('/', ''))[0]?.mime;
if (canEmbed(url)) {
return {
url: comment.link,
type: 'iframe',
thumbnail: comment.thumbnailUrl || scrapedThumbnailUrl,
};
}
if (mime?.startsWith('image')) {
return {
url: comment.link,
type: 'image',
};
}
const mime = extName(url.pathname.toLowerCase().replace('/', ''))[0]?.mime;
if (mime?.startsWith('video')) {
return {
url: comment.link,
type: 'video',
thumbnail: comment.thumbnailUrl,
};
}
if (mime?.startsWith('image')) {
return {
url: comment.link,
type: 'image',
};
}
if (mime?.startsWith('audio')) {
return {
url: comment.link,
type: 'audio',
};
}
} catch (error) {
return;
}
}
if (mime?.startsWith('video')) {
return {
url: comment.link,
type: 'video',
thumbnail: comment.thumbnailUrl,
};
}
if (comment?.thumbnailUrl && comment?.thumbnailUrl !== comment?.link) {
return {
url: comment.link,
type: 'webpage',
thumbnail: comment.thumbnailUrl,
};
}
if (mime?.startsWith('audio')) {
return {
url: comment.link,
type: 'audio',
};
}
} catch (error) {
return;
}
}
if (comment?.thumbnailUrl && comment?.thumbnailUrl !== comment?.link) {
return {
url: comment.link,
type: 'webpage',
thumbnail: comment.thumbnailUrl,
};
}
if (comment?.link) {
return {
url: comment.link,
type: 'webpage',
};
}
if (comment?.link) {
return {
url: comment.link,
type: 'webpage',
};
}
};
export default getCommentMediaInfo;
export default getCommentMediaInfo;
+33 -36
View File
@@ -1,38 +1,35 @@
const getDate = (commentTimestamp) => {
if (commentTimestamp === undefined || isNaN(commentTimestamp)) {
return "";
}
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
const string = new Intl.DateTimeFormat(locale, {
hour12: false,
year: '2-digit',
month: '2-digit',
day: '2-digit',
weekday: 'short',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
}).format(new Date(commentTimestamp * 1000));
if (locale.startsWith('ar')) {
return string
}
const items = string.split(/,* /)
if (items.length === 3) {
const itemIsNumber = [
items[0][0].match(/[0-9]/),
items[1][0].match(/[0-9]/)
]
if (itemIsNumber[0] && itemIsNumber[1]) {
return `${items[0]}(${items[2]})${items[1]}`
}
if (itemIsNumber[0] && !itemIsNumber[1]) {
return `${items[0]}(${items[1]})${items[2]}`
}
if (!itemIsNumber[0] && itemIsNumber[1]) {
return `${items[1]}(${items[0]})${items[2]}`
}
}
return string
}
if (commentTimestamp === undefined || isNaN(commentTimestamp)) {
return '';
}
const locale = Intl.DateTimeFormat().resolvedOptions().locale;
const string = new Intl.DateTimeFormat(locale, {
hour12: false,
year: '2-digit',
month: '2-digit',
day: '2-digit',
weekday: 'short',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}).format(new Date(commentTimestamp * 1000));
if (locale.startsWith('ar')) {
return string;
}
const items = string.split(/,* /);
if (items.length === 3) {
const itemIsNumber = [items[0][0].match(/[0-9]/), items[1][0].match(/[0-9]/)];
if (itemIsNumber[0] && itemIsNumber[1]) {
return `${items[0]}(${items[2]})${items[1]}`;
}
if (itemIsNumber[0] && !itemIsNumber[1]) {
return `${items[0]}(${items[1]})${items[2]}`;
}
if (!itemIsNumber[0] && itemIsNumber[1]) {
return `${items[1]}(${items[0]})${items[2]}`;
}
}
return string;
};
export default getDate;
export default getDate;
+36 -37
View File
@@ -1,45 +1,44 @@
const pluralize = (unit, value) => {
return `${value} ${unit}${value > 1 ? 's' : ''}`;
return `${value} ${unit}${value > 1 ? 's' : ''}`;
};
const getFormattedTime = (timestamp) => {
try {
const currentTime = new Date().getTime();
const differenceInMilliseconds = currentTime - (timestamp * 1000);
try {
const currentTime = new Date().getTime();
const differenceInMilliseconds = currentTime - timestamp * 1000;
const years = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 365.25));
const months = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 365.25)) / (1000 * 60 * 60 * 24 * 30));
const days = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 30)) / (1000 * 60 * 60 * 24));
const hours = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((differenceInMilliseconds % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((differenceInMilliseconds % (1000 * 60)) / 1000);
const years = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 365.25));
const months = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 365.25)) / (1000 * 60 * 60 * 24 * 30));
const days = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24 * 30)) / (1000 * 60 * 60 * 24));
const hours = Math.floor((differenceInMilliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((differenceInMilliseconds % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((differenceInMilliseconds % (1000 * 60)) / 1000);
if (years > 0) {
return months > 0 ? `${pluralize('year', years)} and ${pluralize('month', months)} ago` : `${pluralize('year', years)} ago`;
} else if (months > 0) {
return days > 0 ? `${pluralize('month', months)} and ${pluralize('day', days)} ago` : `${pluralize('month', months)} ago`;
} else if (days > 0) {
if (hours > 0) {
return `${pluralize('day', days)} and ${pluralize('hour', hours)} ago`;
} else if (minutes > 0) {
return `${pluralize('day', days)} and ${pluralize('minute', minutes)} ago`;
} else {
return `${pluralize('day', days)} ago`;
}
} else if (hours > 0) {
return minutes > 0 ? `${pluralize('hour', hours)} and ${pluralize('minute', minutes)} ago` : `${pluralize('hour', hours)} ago`;
} else if (minutes > 0) {
return seconds > 0 ? `${pluralize('minute', minutes)} and ${pluralize('second', seconds)} ago` : `${pluralize('minute', minutes)} ago`;
} else if (seconds > 30) {
return `${pluralize('second', seconds)} ago`;
} else {
return "just now";
}
}
catch (e) {
console.error("Error in getFormattedTime:", e);
return "[error]";
}
if (years > 0) {
return months > 0 ? `${pluralize('year', years)} and ${pluralize('month', months)} ago` : `${pluralize('year', years)} ago`;
} else if (months > 0) {
return days > 0 ? `${pluralize('month', months)} and ${pluralize('day', days)} ago` : `${pluralize('month', months)} ago`;
} else if (days > 0) {
if (hours > 0) {
return `${pluralize('day', days)} and ${pluralize('hour', hours)} ago`;
} else if (minutes > 0) {
return `${pluralize('day', days)} and ${pluralize('minute', minutes)} ago`;
} else {
return `${pluralize('day', days)} ago`;
}
} else if (hours > 0) {
return minutes > 0 ? `${pluralize('hour', hours)} and ${pluralize('minute', minutes)} ago` : `${pluralize('hour', hours)} ago`;
} else if (minutes > 0) {
return seconds > 0 ? `${pluralize('minute', minutes)} and ${pluralize('second', seconds)} ago` : `${pluralize('minute', minutes)} ago`;
} else if (seconds > 30) {
return `${pluralize('second', seconds)} ago`;
} else {
return 'just now';
}
} catch (e) {
console.error('Error in getFormattedTime:', e);
return '[error]';
}
};
export default getFormattedTime;
export default getFormattedTime;
+29 -29
View File
@@ -1,38 +1,38 @@
function handleAddressClick(shortAddress) {
const isMobile = window.innerWidth <= 480;
const addressSelector = isMobile ? '.address-mobile' : '.address-desktop';
const postReplySelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
const opSelector = isMobile ? '.op-mobile' : '.op-desktop';
const isMobile = window.innerWidth <= 480;
const addressSelector = isMobile ? '.address-mobile' : '.address-desktop';
const postReplySelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
const opSelector = isMobile ? '.op-mobile' : '.op-desktop';
const matchingElements = [...document.querySelectorAll(postReplySelector + ',' + opSelector)].filter(el => {
const addressElement = el.querySelector(addressSelector);
return addressElement && addressElement.textContent.includes(shortAddress);
});
const matchingElements = [...document.querySelectorAll(postReplySelector + ',' + opSelector)].filter((el) => {
const addressElement = el.querySelector(addressSelector);
return addressElement && addressElement.textContent.includes(shortAddress);
});
if (matchingElements.length === 0) {
return;
}
if (matchingElements.length === 0) {
return;
}
const highlightedElements = document.querySelectorAll('.highlighted-address');
const highlightedElements = document.querySelectorAll('.highlighted-address');
let allHighlighted = true;
matchingElements.forEach(el => {
if (!el.classList.contains('highlighted-address')) {
allHighlighted = false;
}
});
let allHighlighted = true;
matchingElements.forEach((el) => {
if (!el.classList.contains('highlighted-address')) {
allHighlighted = false;
}
});
highlightedElements.forEach(el => {
el.classList.remove('highlighted-address');
});
highlightedElements.forEach((el) => {
el.classList.remove('highlighted-address');
});
if (!allHighlighted) {
matchingElements.forEach(el => {
if (!el.classList.contains('op-mobile') && !el.classList.contains('op-desktop')) {
el.classList.add('highlighted-address');
}
});
}
if (!allHighlighted) {
matchingElements.forEach((el) => {
if (!el.classList.contains('op-mobile') && !el.classList.contains('op-desktop')) {
el.classList.add('highlighted-address');
}
});
}
}
export default handleAddressClick;
export default handleAddressClick;
+7 -7
View File
@@ -1,12 +1,12 @@
const handleImageClick = (e) => {
const image = e.target;
const container = image.closest('.img-container');
const image = e.target;
const container = image.closest('.img-container');
image.classList.toggle('enlarged');
image.classList.toggle('enlarged');
if (container) {
container.classList.toggle('expanded-container');
}
if (container) {
container.classList.toggle('expanded-container');
}
};
export default handleImageClick;
export default handleImageClick;
+43 -45
View File
@@ -1,55 +1,53 @@
function handleQuoteClick(reply, parentCid, threadCid) {
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
highlightedElements.forEach((el) => {
el.classList.remove('highlighted');
});
const opElementSelector = isMobile ? '.op-mobile' : '.op-desktop';
const opElement = [...document.querySelectorAll(opElementSelector)]
.find(el => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(threadCid);
});
const opElementSelector = isMobile ? '.op-mobile' : '.op-desktop';
if (opElement) {
opElement.scrollIntoView({ behavior: "auto", block: "start" });
} else {
return;
}
const opElement = [...document.querySelectorAll(opElementSelector)].find((el) => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(threadCid);
});
return;
}
if (opElement) {
opElement.scrollIntoView({ behavior: 'auto', block: 'start' });
} else {
return;
}
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
return;
}
const targetElement = [...document.querySelectorAll(targetElementSelector)]
.find(el => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
if (targetElement) {
const highlightedElements = document.querySelectorAll('.highlighted-click');
highlightedElements.forEach(el => {
el.classList.remove('highlighted-click');
});
targetElement.scrollIntoView({ behavior: "auto", block: "start" });
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted-click');
}
} else {
return;
}
};
const targetElement = [...document.querySelectorAll(targetElementSelector)].find((el) => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
export default handleQuoteClick;
if (targetElement) {
const highlightedElements = document.querySelectorAll('.highlighted-click');
highlightedElements.forEach((el) => {
el.classList.remove('highlighted-click');
});
targetElement.scrollIntoView({ behavior: 'auto', block: 'start' });
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted-click');
}
} else {
return;
}
}
export default handleQuoteClick;
+34 -35
View File
@@ -1,43 +1,42 @@
function handleQuoteHover(reply, parentCid, onElementOutOfView) {
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
const targetElement = [...document.querySelectorAll(targetElementSelector)]
.find(el => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
const targetElement = [...document.querySelectorAll(targetElementSelector)].find((el) => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
if (targetElement) {
const isInViewport = (element) => {
const bounding = element.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
if (targetElement) {
const isInViewport = (element) => {
const bounding = element.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
if (isInViewport(targetElement)) {
const highlightedElements = document.querySelectorAll('.highlighted');
if (isInViewport(targetElement)) {
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
highlightedElements.forEach((el) => {
el.classList.remove('highlighted');
});
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted');
}
} else {
onElementOutOfView();
}
} else {
onElementOutOfView();
}
};
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted');
}
} else {
onElementOutOfView();
}
} else {
onElementOutOfView();
}
}
export default handleQuoteHover;
export default handleQuoteHover;
+25 -22
View File
@@ -1,28 +1,31 @@
function handleShareClick(selectedAddress, cid) {
let shareLink;
let shareLink;
if (cid === "rules" || cid === "description") {
shareLink = `https://plebchan.eth.limo/#/p/${selectedAddress}`;
} else {
const plebBzBaseURL = "https://pleb.bz/p/";
shareLink = `${plebBzBaseURL}${selectedAddress}/`;
if (cid !== "rules" && cid !== "description") {
shareLink += `c/${cid}`;
}
if (cid === 'rules' || cid === 'description') {
shareLink = `https://plebchan.eth.limo/#/p/${selectedAddress}`;
} else {
const plebBzBaseURL = 'https://pleb.bz/p/';
shareLink = `${plebBzBaseURL}${selectedAddress}/`;
shareLink += `?redirect=plebchan.eth.limo`;
}
if (cid !== 'rules' && cid !== 'description') {
shareLink += `c/${cid}`;
}
if (navigator.clipboard) {
navigator.clipboard.writeText(shareLink).then(() => {
console.log("Link copied to clipboard!");
}).catch(err => {
console.error('Could not copy text: ', err);
});
} else {
return;
}
shareLink += `?redirect=plebchan.eth.limo`;
}
if (navigator.clipboard) {
navigator.clipboard
.writeText(shareLink)
.then(() => {
console.log('Link copied to clipboard!');
})
.catch((err) => {
console.error('Could not copy text: ', err);
});
} else {
return;
}
}
export default handleShareClick;
export default handleShareClick;
+82 -84
View File
@@ -1,94 +1,92 @@
import useGeneralStore from "../hooks/stores/useGeneralStore";
import useGeneralStore from '../hooks/stores/useGeneralStore';
const handleStyleChange = (event) => {
const {
setBodyStyle, setSelectedStyle
} = useGeneralStore.getState();
const { setBodyStyle, setSelectedStyle } = useGeneralStore.getState();
switch (event.target.value) {
case "Yotsuba":
const yotsubaBodyStyle = {
background: "#ffe url(assets/fade.png) top repeat-x",
color: "maroon",
fontFamily: "Arial, Helvetica, sans-serif"
};
setBodyStyle(yotsubaBodyStyle);
setSelectedStyle("Yotsuba");
localStorage.setItem("selectedStyle", "Yotsuba");
localStorage.setItem("bodyStyle", JSON.stringify(yotsubaBodyStyle));
break;
switch (event.target.value) {
case 'Yotsuba':
const yotsubaBodyStyle = {
background: '#ffe url(assets/fade.png) top repeat-x',
color: 'maroon',
fontFamily: 'Arial, Helvetica, sans-serif',
};
setBodyStyle(yotsubaBodyStyle);
setSelectedStyle('Yotsuba');
localStorage.setItem('selectedStyle', 'Yotsuba');
localStorage.setItem('bodyStyle', JSON.stringify(yotsubaBodyStyle));
break;
case "Yotsuba-B":
const yotsubaBBodyStyle = {
background: "#eef2ff url(assets/fade-blue.png) top center repeat-x",
color: "#000",
fontFamily: "Arial, Helvetica, sans-serif"
};
setBodyStyle(yotsubaBBodyStyle);
setSelectedStyle("Yotsuba-B");
localStorage.setItem("selectedStyle", "Yotsuba-B");
localStorage.setItem("bodyStyle", JSON.stringify(yotsubaBBodyStyle));
break;
case 'Yotsuba-B':
const yotsubaBBodyStyle = {
background: '#eef2ff url(assets/fade-blue.png) top center repeat-x',
color: '#000',
fontFamily: 'Arial, Helvetica, sans-serif',
};
setBodyStyle(yotsubaBBodyStyle);
setSelectedStyle('Yotsuba-B');
localStorage.setItem('selectedStyle', 'Yotsuba-B');
localStorage.setItem('bodyStyle', JSON.stringify(yotsubaBBodyStyle));
break;
case "Futaba":
const futabaBodyStyle = {
background: "#ffe",
color: "maroon",
fontFamily: "times new roman, serif"
};
setBodyStyle(futabaBodyStyle);
setSelectedStyle("Futaba");
localStorage.setItem("selectedStyle", "Futaba");
localStorage.setItem("bodyStyle", JSON.stringify(futabaBodyStyle));
break;
case 'Futaba':
const futabaBodyStyle = {
background: '#ffe',
color: 'maroon',
fontFamily: 'times new roman, serif',
};
setBodyStyle(futabaBodyStyle);
setSelectedStyle('Futaba');
localStorage.setItem('selectedStyle', 'Futaba');
localStorage.setItem('bodyStyle', JSON.stringify(futabaBodyStyle));
break;
case "Burichan":
const burichanBodyStyle = {
background: "#eef2ff",
color: "#000",
fontFamily: "times new roman, serif"
};
setBodyStyle(burichanBodyStyle);
setSelectedStyle("Burichan");
localStorage.setItem("selectedStyle", "Burichan");
localStorage.setItem("bodyStyle", JSON.stringify(burichanBodyStyle));
break;
case 'Burichan':
const burichanBodyStyle = {
background: '#eef2ff',
color: '#000',
fontFamily: 'times new roman, serif',
};
setBodyStyle(burichanBodyStyle);
setSelectedStyle('Burichan');
localStorage.setItem('selectedStyle', 'Burichan');
localStorage.setItem('bodyStyle', JSON.stringify(burichanBodyStyle));
break;
case "Tomorrow":
const tomorrowBodyStyle = {
background: "#1d1f21 none",
color: "#c5c8c6",
fontFamily: "Arial, Helvetica, sans-serif"
};
setBodyStyle(tomorrowBodyStyle);
setSelectedStyle("Tomorrow");
localStorage.setItem("selectedStyle", "Tomorrow");
localStorage.setItem("bodyStyle", JSON.stringify(tomorrowBodyStyle));
break;
case 'Tomorrow':
const tomorrowBodyStyle = {
background: '#1d1f21 none',
color: '#c5c8c6',
fontFamily: 'Arial, Helvetica, sans-serif',
};
setBodyStyle(tomorrowBodyStyle);
setSelectedStyle('Tomorrow');
localStorage.setItem('selectedStyle', 'Tomorrow');
localStorage.setItem('bodyStyle', JSON.stringify(tomorrowBodyStyle));
break;
case "Photon":
const photonBodyStyle = {
background: "#eee none",
color: "#333",
fontFamily: "Arial, Helvetica, sans-serif"
};
setBodyStyle(photonBodyStyle);
setSelectedStyle("Photon");
localStorage.setItem("selectedStyle", "Photon");
localStorage.setItem("bodyStyle", JSON.stringify(photonBodyStyle));
break;
case 'Photon':
const photonBodyStyle = {
background: '#eee none',
color: '#333',
fontFamily: 'Arial, Helvetica, sans-serif',
};
setBodyStyle(photonBodyStyle);
setSelectedStyle('Photon');
localStorage.setItem('selectedStyle', 'Photon');
localStorage.setItem('bodyStyle', JSON.stringify(photonBodyStyle));
break;
default:
const defaultBodyStyle = {
background: "#ffe url(assets/fade.png) top repeat-x",
color: "maroon",
fontFamily: "Arial, Helvetica, sans-serif"
};
setBodyStyle(defaultBodyStyle);
setSelectedStyle("Yotsuba");
localStorage.setItem("selectedStyle", "Yotsuba");
localStorage.setItem("bodyStyle", JSON.stringify(defaultBodyStyle));
}
}
default:
const defaultBodyStyle = {
background: '#ffe url(assets/fade.png) top repeat-x',
color: 'maroon',
fontFamily: 'Arial, Helvetica, sans-serif',
};
setBodyStyle(defaultBodyStyle);
setSelectedStyle('Yotsuba');
localStorage.setItem('selectedStyle', 'Yotsuba');
localStorage.setItem('bodyStyle', JSON.stringify(defaultBodyStyle));
}
};
export default handleStyleChange;
export default handleStyleChange;
+7 -7
View File
@@ -1,10 +1,10 @@
const isValidUrl = (url) => {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
try {
new URL(url);
return true;
} catch (e) {
return false;
}
};
export default isValidUrl;
export default isValidUrl;
+5 -5
View File
@@ -1,8 +1,8 @@
const preloadImages = (imageUrls) => {
imageUrls.forEach((imageUrl) => {
const img = new Image();
img.src = imageUrl;
});
imageUrls.forEach((imageUrl) => {
const img = new Image();
img.src = imageUrl;
});
};
export default preloadImages;
export default preloadImages;
+6 -6
View File
@@ -1,9 +1,9 @@
function removeHighlight() {
const highlightedElements = document.querySelectorAll('.highlighted');
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
};
highlightedElements.forEach((el) => {
el.classList.remove('highlighted');
});
}
export default removeHighlight;
export default removeHighlight;