Content deleted Content added
Polygnotus (talk | contribs) No edit summary |
Polygnotus (talk | contribs) No edit summary |
||
(9 intermediate revisions by the same user not shown) | |||
Line 5:
'use strict';
//
if (mw.config.get('skin') === 'minerva' ) {
return;
}
// Only run on watchlist page
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Watchlist') {
return;
}
// Flag to prevent double initialization
let initialized = false;
// Create the archive checker section
Line 54 ⟶ 62:
checkUrl: (url) => `https://archive.ph/${encodeURIComponent(url)}`,
searchUrl: (url) => `https://archive.ph/${encodeURIComponent(url)}`,
apiCheck:
notFoundStrings: ['No results']
},
{
Line 66 ⟶ 75:
checkUrl: (url) => `https://web.archive.org/web/20250000000000*/${encodeURIComponent(url)}`,
searchUrl: (url) => `https://web.archive.org/web/*/${encodeURIComponent(url)}`,
apiUrl: (url) => `https://archive.org/wayback/available?url=${encodeURIComponent(
apiCheck: true,
notFoundStrings: ['Wayback Machine has not archived that URL.']
}
];
Line 93 ⟶ 91:
return;
}
console.log(`[Archive Checker] Starting check for URL: ${normalizedUrl}`);
const results = [];
for (const service of archiveServices) {
console.log(`[Archive Checker] Checking ${service.name}...`);
const result = {
name: service.name,
Line 104 ⟶ 106:
};
if (service.apiCheck
try {
const response = await fetch(checkUrl);
console.log(`[Archive Checker] ${service.name} API Response status: ${response.status}`);
const data = await response.json();
console.log(`[Archive Checker] ${service.name} API Response data:`, data);
// Check if archived_snapshots has any properties (indicating archives exist)
const hasArchives = data.archived_snapshots &&
Object.keys(data.archived_snapshots).length > 0 &&
data.archived_snapshots.closest;
result.available = !!hasArchives; // Ensure it's a boolean
if (hasArchives) {
result.url = data.archived_snapshots.closest.url;
console.log(`[Archive Checker] ${service.name} - Archive found: ${result.url}`);
} else {
console.log(`[Archive Checker] ${service.name} - No archive found (empty archived_snapshots)`);
}
} else {
// For other services, fetch the page content and check for "not found" strings
checkUrl = service.checkUrl(normalizedUrl);
console.log(`[Archive Checker] ${service.name} Check URL: ${checkUrl}`);
const response = await fetch(checkUrl, {
mode: 'cors',
credentials: 'omit'
});
console.log(`[Archive Checker] ${service.name} Response status: ${response.status}`);
if (response.ok) {
const text = await response.text();
console.log(`[Archive Checker] ${service.name} Response length: ${text.length} characters`);
// Check if any "not found" strings are present
const notFound = service.notFoundStrings &&
service.notFoundStrings.some(str => text.includes(str));
if (notFound) {
result.available = false;
console.log(`[Archive Checker] ${service.name} - Not found (detected: "${service.notFoundStrings.find(str => text.includes(str))}")`);
} else {
result.available = true;
console.log(`[Archive Checker] ${service.name} - Archive appears to be available`);
}
} else {
result.available = null;
result.error = `HTTP ${response.status}`;
console.log(`[Archive Checker] ${service.name} - HTTP error: ${response.status}`);
}
}
} catch (error) {
result.error = error.message;
result.available = null;
}
} else {
console.log(`[Archive Checker] ${service.name} - API check disabled, will show manual link`);
}
Line 122 ⟶ 177:
}
console.log(`[Archive Checker] Check completed. Results:`, results);
displayResults(results, normalizedUrl);
}
Line 128 ⟶ 184:
function displayResults(results, originalUrl) {
const resultsContainer = document.getElementById('results-container');
console.log(`[Archive Checker] Displaying results for ${originalUrl}:`, results);
let html = `<h4>Results for: ${originalUrl}</h4>`;
Line 133 ⟶ 191:
results.forEach(result => {
console.log(`[Archive Checker] Processing result for ${result.name}:`, {
available: result.available,
availableType: typeof result.available,
error: result.error
});
const statusText = result.available === true ? '✓ Available' :
result.available === false ? '✗ Not found' :
Line 139 ⟶ 203:
const statusColor = result.available === true ? '#006400' :
result.available === false ? '#8b0000' : '#666';
console.log(`[Archive Checker] ${result.name} - Status: ${statusText}, Color: ${statusColor}`);
html += `
Line 165 ⟶ 231:
}
//
function
//
if (initialized || document.getElementById('archive-checker-section')) {
return;
const watchlistContent = document.querySelector('.mw-changeslist, #mw-content-text');
if (!watchlistContent) {
}
initialized = true;
// Add our section to the top of the watchlist page
const archiveChecker =
watchlistContent.parentNode.insertBefore(archiveChecker, watchlistContent);
// Add event
const checkBtn =
const urlInput = document.getElementById('url-input');
const url =
});
}
});
}
// Initialize the checker
function init() {
// Try to add immediately if page is already loaded
addArchiveChecker();
//
const
obs.disconnect();
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Cleanup observer after reasonable time
setTimeout(() => {
observer.disconnect();
}, 5000);
}
}
|