KiritoAxinity commited on
Commit
32d910e
·
verified ·
1 Parent(s): 18d1fff

Update public/script.js

Browse files
Files changed (1) hide show
  1. public/script.js +18 -16
public/script.js CHANGED
@@ -125,19 +125,6 @@ async function fetchVideoDataById(videoId) {
125
  return fetchNextValidVideoData(url, 1, 1);
126
  }
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) {
142
  return (
143
  video &&
@@ -546,13 +533,13 @@ activityCheck = setInterval(() => {
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...");
@@ -560,6 +547,21 @@ async function getTags() {
560
  }
561
  }
562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  function putTagsInForm(tags) {
564
  var innerString = "";
565
  for (tag of tags) {
 
125
  return fetchNextValidVideoData(url, 1, 1);
126
  }
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  function videoIsValid(video) {
129
  return (
130
  video &&
 
533
  }, 250);
534
 
535
  async function getTags() {
 
536
  const targetUrl = "https://www.sakugabooru.com/tag.json?limit=1500&order=count";
537
+ // corsproxy.io is usually more stable for large JSON sets
538
+ const proxyUrl = `https://corsproxy.io/?${encodeURIComponent(targetUrl)}`;
539
 
540
  try {
541
  const response = await fetch(proxyUrl);
542
+ if (!response.ok) throw new Error('Network error');
543
  return await response.json();
544
  } catch (error) {
545
  console.error("Fetch failed, trying cache...");
 
547
  }
548
  }
549
 
550
+ async function fetchNextValidVideoData(tags, page) {
551
+ // FIX: Ensure 'tags' doesn't contain a path by accident
552
+ const cleanTags = tags.replace('/api/', '');
553
+ const targetUrl = `https://www.sakugabooru.com/post.json?limit=1&page=${page}&tags=${cleanTags}`;
554
+ const proxyUrl = `https://corsproxy.io/?${encodeURIComponent(targetUrl)}`;
555
+
556
+ try {
557
+ const response = await fetch(proxyUrl);
558
+ if (!response.ok) return null;
559
+ return await response.json();
560
+ } catch (error) {
561
+ return null;
562
+ }
563
+ }
564
+
565
  function putTagsInForm(tags) {
566
  var innerString = "";
567
  for (tag of tags) {