Skip to content

Commit

Permalink
added some test for crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
u-Kuro committed Sep 14, 2024
1 parent 5fa9bb9 commit a4455e0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/build/bundle.js.map

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
initMediaLoader
} from "./js/workerUtils.js";
import {
encodeText,
getLocalStorage,
removeLocalStorage,
requestImmediate,
Expand Down Expand Up @@ -133,7 +134,23 @@
(async () => {
const shouldGetMediaEntries = await getIDBdata("mediaEntriesIsEmpty");
if (shouldGetMediaEntries === true) {
try { console.error(window?.navigator?.userAgent || window?.navigator?.vendor || window?.opera) } catch { }
// Dev Test
try {
const divEl = document.createElement("div");
try {
divEl.textContent = encodeText(window?.navigator?.userAgent || window?.navigator?.vendor || window?.opera) || "";
} catch (ex) {
const error = ex?.toString?.()
if (error) {
divEl.textContent = error
} else {
divEl.textContent = ex
divEl.textContent += " | Unexpected Error..."
}
}
document.querySelector("body > .dialog-web-info").appendChild(divEl);
} catch { }
// Dev Test
if ($webCrawler && $initList !== false) {
try {
loadYoutube();
Expand Down
4 changes: 2 additions & 2 deletions src/components/Media/Fixed/MediaPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@
{@const mediaList = $loadedMediaLists[$selectedCategory]?.mediaList}
{#each mediaList || [] as media, mediaIndex ((media?.id != null ? media.id + " " + mediaIndex : {}) ?? {})}
<div class="popup-content">
{#if $webCrawler || (mediaIndex <= currentHeaderIdx + bottomPopupVisibleCount && mediaIndex >= currentHeaderIdx - topPopupVisibleCount)}
{#if ($webCrawler && $initList !== false) || (mediaIndex <= currentHeaderIdx + bottomPopupVisibleCount && mediaIndex >= currentHeaderIdx - topPopupVisibleCount)}
{@const format = media.format}
{@const isManga = format === "Manga" || format === "One Shot"}
{@const isNovel = format === "Novel"}
Expand Down Expand Up @@ -1858,7 +1858,7 @@
</a>
{:else}
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
{#if $webCrawler && media.trailerID}
{#if $webCrawler && $initList !== false && media.trailerID}
<a class="trailer-link" href="{`https://www.youtube.com/watch?v=${media.trailerID}`}">Trailer</a>
{/if}
{#if media.bannerImageUrl || media.trailerThumbnailUrl}
Expand Down
25 changes: 19 additions & 6 deletions src/js/others/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,24 @@ const isWebCrawler = () => {
.join('')
), 'i').test(navigator.userAgent);
} catch { }
// const encodeRegex = (regex) => {
// return btoa(regex.source)
// .split('')
// .map(char => char.charCodeAt(0).toString(16).padStart(2, '0'))
// .join('');
// }
}
const encodeText = (s) => {
try {
return btoa(s)
.split('')
.map(char => char.charCodeAt(0).toString(16).padStart(2, '0'))
.join('');
} catch { }
}
// const decodeText = (s) => {
// try {
// return atob(
// s.match(/.{1,2}/g)
// .map(hex => String.fromCharCode(parseInt(hex, 16)))
// .join('')
// )
// } catch { }
// }

const android = isAndroid()
const checkConnection = async () => {
Expand Down Expand Up @@ -765,6 +776,8 @@ export {
// hasValidOrigin,
isMobile,
isWebCrawler,
encodeText,
// decodeText,
formatYear,
formatMonth,
formatDay,
Expand Down

0 comments on commit a4455e0

Please sign in to comment.