Spaces:
Sleeping
Sleeping
Fix: JS ReferenceError for footer link, target 'Share via Link' too
Browse files
app.py
CHANGED
@@ -281,44 +281,37 @@ demo_interface = gr.Interface(
|
|
281 |
js_code_for_head = """
|
282 |
(function() {
|
283 |
console.log('[MCP Script] Initializing script to change API link text...');
|
|
|
|
|
284 |
function attemptChangeApiLinkText() {
|
285 |
const links = document.querySelectorAll('a');
|
286 |
-
|
287 |
-
// console.log('[MCP Script] Found ' + links.length + ' anchor tags on this attempt.'); // Can be too verbose for interval
|
288 |
for (let i = 0; i < links.length; i++) {
|
289 |
const linkText = links[i].textContent ? links[i].textContent.trim() : '';
|
290 |
-
if (linkText === 'Use via API') {
|
291 |
links[i].textContent = 'Use as an MCP or via API';
|
292 |
-
console.log('[MCP Script] Successfully changed
|
293 |
-
|
294 |
-
|
295 |
}
|
296 |
}
|
297 |
-
return
|
298 |
}
|
299 |
|
300 |
let attempts = 0;
|
301 |
const maxAttempts = 50; // Try for up to 5 seconds (50 * 100ms)
|
302 |
let initialScanDone = false;
|
|
|
303 |
const intervalId = setInterval(() => {
|
304 |
if (!initialScanDone && attempts === 0) {
|
305 |
console.log('[MCP Script] Performing initial scan for API link text.');
|
306 |
initialScanDone = true;
|
307 |
}
|
|
|
308 |
if (attemptChangeApiLinkText() || attempts >= maxAttempts) {
|
309 |
clearInterval(intervalId);
|
310 |
-
if (attempts >= maxAttempts && !
|
311 |
-
|
312 |
-
let stillNotFound = true;
|
313 |
-
const finalLinks = document.querySelectorAll('a');
|
314 |
-
for (let i = 0; i < finalLinks.length; i++) {
|
315 |
-
if (finalLinks[i].textContent && finalLinks[i].textContent.trim() === 'Use as an MCP or via API') {
|
316 |
-
stillNotFound = false; break;
|
317 |
-
}
|
318 |
-
}
|
319 |
-
if (stillNotFound) {
|
320 |
-
console.log('[MCP Script] Max attempts reached. \"Use via API\" link was not found or changed. It might not be rendered or has a different text.');
|
321 |
-
}
|
322 |
}
|
323 |
}
|
324 |
attempts++;
|
|
|
281 |
js_code_for_head = """
|
282 |
(function() {
|
283 |
console.log('[MCP Script] Initializing script to change API link text...');
|
284 |
+
let foundAndChangedGlobal = false; // Declare here to be accessible in setInterval
|
285 |
+
|
286 |
function attemptChangeApiLinkText() {
|
287 |
const links = document.querySelectorAll('a');
|
288 |
+
// console.log('[MCP Script] Found ' + links.length + ' anchor tags on this attempt.');
|
|
|
289 |
for (let i = 0; i < links.length; i++) {
|
290 |
const linkText = links[i].textContent ? links[i].textContent.trim() : '';
|
291 |
+
if (linkText === 'Use via API' || linkText === 'Share via Link') { // Target both possible texts
|
292 |
links[i].textContent = 'Use as an MCP or via API';
|
293 |
+
console.log('[MCP Script] Successfully changed link text from: ' + linkText);
|
294 |
+
foundAndChangedGlobal = true;
|
295 |
+
return true; // Indicate success
|
296 |
}
|
297 |
}
|
298 |
+
return false; // Indicate not found/changed in this attempt
|
299 |
}
|
300 |
|
301 |
let attempts = 0;
|
302 |
const maxAttempts = 50; // Try for up to 5 seconds (50 * 100ms)
|
303 |
let initialScanDone = false;
|
304 |
+
|
305 |
const intervalId = setInterval(() => {
|
306 |
if (!initialScanDone && attempts === 0) {
|
307 |
console.log('[MCP Script] Performing initial scan for API link text.');
|
308 |
initialScanDone = true;
|
309 |
}
|
310 |
+
|
311 |
if (attemptChangeApiLinkText() || attempts >= maxAttempts) {
|
312 |
clearInterval(intervalId);
|
313 |
+
if (attempts >= maxAttempts && !foundAndChangedGlobal) {
|
314 |
+
console.log('[MCP Script] Max attempts reached. Target link was not found or changed. It might not be rendered or has a different initial text.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
}
|
316 |
}
|
317 |
attempts++;
|