KiritoAxinity commited on
Commit
47533dd
·
verified ·
1 Parent(s): b698533

Update public/script.js

Browse files
Files changed (1) hide show
  1. public/script.js +13 -18
public/script.js CHANGED
@@ -125,16 +125,13 @@ async function fetchVideoDataById(videoId) {
125
  return fetchNextValidVideoData(url, 1, 1);
126
  }
127
 
128
- async function fetchNextValidVideoData(url, index, direction) {
129
- const response = await fetch(url);
130
- const videos = await response.json();
131
- const video = videos[0];
132
-
133
- if (videoIsValid(video)) {
134
- return { video: video, index: index };
135
- } else {
136
- return fetchVideoData(shiftIndex(index, direction), direction);
137
- }
138
  }
139
 
140
  function videoIsValid(video) {
@@ -538,16 +535,14 @@ activityCheck = setInterval(() => {
538
  }, 250);
539
 
540
  async function getTags() {
541
- const response = await fetch("/api/tag.json?limit=1500&order=count");
542
-
543
- // ADD THIS: If the server blocks us, don't try to parse JSON
544
  if (!response.ok) {
545
- console.error("API Blocked or Failed:", response.status);
546
- return []; // Return empty list instead of crashing
547
  }
548
-
549
- const tags = await response.json();
550
- return tags;
551
  }
552
 
553
  function putTagsInForm(tags) {
 
125
  return fetchNextValidVideoData(url, 1, 1);
126
  }
127
 
128
+ async function fetchNextValidVideoData(tags, page) {
129
+ const baseUrl = `https://www.sakugabooru.com/post.json?limit=1&page=${page}&tags=${tags}`;
130
+ const url = "https://corsproxy.io/?" + encodeURIComponent(baseUrl);
131
+
132
+ const response = await fetch(url);
133
+ if (!response.ok) return null;
134
+ return await response.json();
 
 
 
135
  }
136
 
137
  function videoIsValid(video) {
 
535
  }, 250);
536
 
537
  async function getTags() {
538
+ // We use a public cors-anywhere proxy to bypass the block
539
+ const url = "https://corsproxy.io/?https://www.sakugabooru.com/tag.json?limit=1500&order=count";
540
+ const response = await fetch(url);
541
  if (!response.ok) {
542
+ console.error("API Blocked even through proxy:", response.status);
543
+ return [];
544
  }
545
+ return await response.json();
 
 
546
  }
547
 
548
  function putTagsInForm(tags) {