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

Update public/script.js

Browse files
Files changed (1) hide show
  1. public/script.js +16 -12
public/script.js CHANGED
@@ -126,12 +126,14 @@ async function fetchVideoDataById(videoId) {
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,14 +537,16 @@ activityCheck = setInterval(() => {
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) {
 
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/get?url=${encodeURIComponent(targetUrl)}`;
131
 
132
+ const response = await fetch(proxyUrl);
133
  if (!response.ok) return null;
134
+
135
+ const data = await response.json();
136
+ return JSON.parse(data.contents);
137
  }
138
 
139
  function videoIsValid(video) {
 
537
  }, 250);
538
 
539
  async function getTags() {
540
+ // AllOrigins uses a different format: hex/json wrapping
541
+ const targetUrl = "https://www.sakugabooru.com/tag.json?limit=1500&order=count";
542
+ const proxyUrl = `https://api.allorigins.win/get?url=${encodeURIComponent(targetUrl)}`;
543
+
544
+ const response = await fetch(proxyUrl);
545
+ if (!response.ok) return [];
546
+
547
+ const data = await response.json();
548
+ // AllOrigins wraps the result in a .contents string, so we must parse it
549
+ return JSON.parse(data.contents);
550
  }
551
 
552
  function putTagsInForm(tags) {