Spaces:
Sleeping
Sleeping
Update public/script.js
Browse files- public/script.js +39 -28
public/script.js
CHANGED
|
@@ -127,13 +127,15 @@ async function fetchVideoDataById(videoId) {
|
|
| 127 |
|
| 128 |
async function fetchNextValidVideoData(tags, page) {
|
| 129 |
const targetUrl = `https://www.sakugabooru.com/post.json?limit=1&page=${page}&tags=${tags}`;
|
| 130 |
-
const proxyUrl = `https://api.allorigins.win/
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
function videoIsValid(video) {
|
|
@@ -297,20 +299,27 @@ function preloadVideo(video, index) {
|
|
| 297 |
videoPlayers[index].src = video.file_url;
|
| 298 |
}
|
| 299 |
|
| 300 |
-
function playVideo() {
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
|
| 316 |
function showTitleAfterDelay(tags) {
|
|
@@ -537,16 +546,18 @@ activityCheck = setInterval(() => {
|
|
| 537 |
}, 250);
|
| 538 |
|
| 539 |
async function getTags() {
|
| 540 |
-
//
|
| 541 |
const targetUrl = "https://www.sakugabooru.com/tag.json?limit=1500&order=count";
|
| 542 |
-
const proxyUrl = `https://api.allorigins.win/
|
| 543 |
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
|
|
|
|
|
|
| 550 |
}
|
| 551 |
|
| 552 |
function putTagsInForm(tags) {
|
|
|
|
| 127 |
|
| 128 |
async function fetchNextValidVideoData(tags, page) {
|
| 129 |
const targetUrl = `https://www.sakugabooru.com/post.json?limit=1&page=${page}&tags=${tags}`;
|
| 130 |
+
const proxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(targetUrl)}`;
|
| 131 |
|
| 132 |
+
try {
|
| 133 |
+
const response = await fetch(proxyUrl);
|
| 134 |
+
if (!response.ok) return null;
|
| 135 |
+
return await response.json();
|
| 136 |
+
} catch (error) {
|
| 137 |
+
return null;
|
| 138 |
+
}
|
| 139 |
}
|
| 140 |
|
| 141 |
function videoIsValid(video) {
|
|
|
|
| 299 |
videoPlayers[index].src = video.file_url;
|
| 300 |
}
|
| 301 |
|
| 302 |
+
async function playVideo() {
|
| 303 |
+
const video = videoPlayers[CURRENT];
|
| 304 |
+
|
| 305 |
+
// 1. Reset tags/UI first
|
| 306 |
+
var tags = videoData[CURRENT].tags.split(" ").map(makeReadable);
|
| 307 |
+
hideTitle();
|
| 308 |
+
showTitleAfterDelay(tags);
|
| 309 |
+
addVideoTagsToUi(tags);
|
| 310 |
+
saveVideoIdToUrl(videoData[CURRENT]);
|
| 311 |
+
|
| 312 |
+
// 2. Play with a safety catch
|
| 313 |
+
try {
|
| 314 |
+
// Ensure video is unmuted if you want sound, or stay muted for autoplay
|
| 315 |
+
video.muted = true;
|
| 316 |
+
await video.play();
|
| 317 |
+
} catch (err) {
|
| 318 |
+
if (err.name !== "AbortError") {
|
| 319 |
+
console.error("Playback error:", err);
|
| 320 |
+
}
|
| 321 |
+
// AbortErrors are ignored because they just mean the video switched quickly
|
| 322 |
+
}
|
| 323 |
}
|
| 324 |
|
| 325 |
function showTitleAfterDelay(tags) {
|
|
|
|
| 546 |
}, 250);
|
| 547 |
|
| 548 |
async function getTags() {
|
| 549 |
+
// Switching to a more stable format for AllOrigins
|
| 550 |
const targetUrl = "https://www.sakugabooru.com/tag.json?limit=1500&order=count";
|
| 551 |
+
const proxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(targetUrl)}`;
|
| 552 |
|
| 553 |
+
try {
|
| 554 |
+
const response = await fetch(proxyUrl);
|
| 555 |
+
if (!response.ok) throw new Error('Network response was not ok');
|
| 556 |
+
return await response.json();
|
| 557 |
+
} catch (error) {
|
| 558 |
+
console.error("Fetch failed, trying cache...");
|
| 559 |
+
return JSON.parse(localStorage.getItem("tags")) || [];
|
| 560 |
+
}
|
| 561 |
}
|
| 562 |
|
| 563 |
function putTagsInForm(tags) {
|