Emergency update to show mirrors in library

This commit is contained in:
Jaifroid 2024-12-02 18:04:17 +00:00
parent 6b1f5b1c07
commit d2bbb195c1
6 changed files with 80 additions and 14 deletions

View File

@ -66,6 +66,9 @@ document.localeJson = {
"configure-display-apptheme-info": "[ Show article with applied theme ]",
"configure-language-selector-default": "Language",
"configure-language-selector-other": "More soon...",
"configure-library-mirrors": "Library Mirrors",
"configure-library-altlibrary": "The library at",
"configure-library-unreachable": "appears to be unreachable. Please try one of these mirrors:",
"configure-performance-settings-title": "Performance / compatibility",
"configure-performance-panel-header": "Caching and preview settings",
"configure-performance-cacheassets-description": "Kiwix JS can speed up the display of articles by caching assets:",

View File

@ -66,6 +66,9 @@ document.localeJson = {
"configure-display-apptheme-info": "[ Mostrar artículo con tema seleccionado ]",
"configure-language-selector-default": "Idioma",
"configure-language-selector-other": "Más pronto...",
"configure-library-mirrors": "Espejos de la biblioteca",
"configure-library-altlibrary": "La biblioteca en",
"configure-library-unreachable": "parece ser inalcanzable. Por favor, pruebe uno de estos espejos:",
"configure-performance-settings-title": "Rendimiento y compatibilidad",
"configure-performance-panel-header": "Ajustes de caché y vista previa",
"configure-performance-cacheassets-description": "Kiwix JS puede acelerar la visualización de artículos almacenando en caché los activos:",

View File

@ -66,6 +66,9 @@ document.localeJson = {
"configure-display-apptheme-info": "[ Afficher l'article avec le thème sélectionné ]",
"configure-language-selector-default": "Langue",
"configure-language-selector-other": "Bientôt plus...",
"configure-library-mirrors": "Miroirs de bibliothèque",
"configure-library-altlibrary": "La bibliothèque à",
"configure-library-unreachable": "semble être inaccessible. Veuillez essayer un de ces miroirs :",
"configure-performance-settings-title": "Performances et compatibilité",
"configure-performance-panel-header": "Mise en caché et prévisualisation",
"configure-performance-cacheassets-description": "Kiwix JS peut accélérer l'affichage des articles en mettant en cache les ressources :",

View File

@ -6,7 +6,7 @@
<title>Kiwix</title>
<meta name="description" content="Offline Wikipedia reader">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: file: blob: about: https://download.kiwix.org https://master.download.kiwix.org https://browser-extension.kiwix.org https://kiwix.github.io 'unsafe-inline' 'unsafe-eval'; frame-src 'self' moz-extension: chrome-extension:; object-src 'none';">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: file: blob: about: https://download.kiwix.org https://master.download.kiwix.org https://library.kiwix.org https://browser-extension.kiwix.org https://kiwix.github.io 'unsafe-inline' 'unsafe-eval'; frame-src 'self' moz-extension: chrome-extension:; object-src 'none';">
<meta name="referrer" content="none">
<!--
Kiwix (offline Wikipedia reader) - HTML5/Javascript version

View File

@ -1792,20 +1792,37 @@ async function handleFileDrop (packet) {
const btnLibrary = document.getElementById('btnLibrary');
btnLibrary.addEventListener('click', function (e) {
e.preventDefault();
const libraryContent = document.getElementById('libraryContent');
const iframe = libraryContent.contentWindow.document.getElementById('libraryIframe');
try {
// eslint-disable-next-line no-new-func
Function('try{}catch{}')();
iframe.setAttribute('src', params.libraryUrl);
uiUtil.tabTransitionToSection('library', params.showUIAnimations);
resizeIFrame();
} catch (error) {
window.open(params.altLibraryUrl, '_blank')
}
const libraryIframe = libraryContent.contentWindow.document.getElementById('libraryIframe');
libraryIframe.src = 'about:blank'; // Empty the iframe
const xhr = new XMLHttpRequest();
xhr.open('HEAD', params.libraryUrl, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300) {
try {
// eslint-disable-next-line no-new-func
Function('try{}catch{}')(); // Tests the browser can run code that will be used by the library
libraryIframe.setAttribute('src', params.libraryUrl);
uiUtil.tabTransitionToSection('library', params.showUIAnimations);
resizeIFrame();
} catch (error) {
console.warn('Browser cannot run code in the library iframe', error);
handleLibraryError(libraryIframe);
}
} else {
console.warn('Library server ' + params.libraryUrl + ' is unreachable...');
handleLibraryError(libraryIframe);
}
}
};
xhr.onerror = function () {
handleLibraryError(libraryIframe);
};
xhr.send();
uiUtil.tabTransitionToSection('library', params.showUIAnimations);
resizeIFrame();
});
// Add keyboard activation for library button
btnLibrary.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ' || e.keyCode === 32) {
@ -1813,7 +1830,44 @@ btnLibrary.addEventListener('keydown', function (e) {
btnLibrary.click();
}
});
// Error handler for library iframe
function handleLibraryError (iframe) {
iframe.onload = function () {
iframe.onload = null;
setTimeout(function () {
try {
if (!iframe.contentWindow || !iframe.contentWindow.document) {
console.warn('Library server ' + params.altLibraryUrl + ' is unreachable...');
throw new Error('Iframe content not accessible');
}
} catch (error) {
let htmlDoc = '<html><head><title>';
htmlDoc += translateUI.t('configure-library-mirrors') || 'Library Mirrors';
htmlDoc += '</title></head><body><h1>';
htmlDoc += translateUI.t('configure-library-mirrors') || 'Library Mirrors';
htmlDoc += '</h1><p style="font-size: large;">'
htmlDoc += translateUI.t('configure-library-altlibrary') || 'The library at';
htmlDoc += ' ' + params.altLibraryUrl + ' ';
htmlDoc += translateUI.t('configure-library-unreachable') || 'appears to be unreachable. Please try one of these mirrors:';
htmlDoc += '</p><ul>';
params.kiwixDownloadMirrors.forEach(function (mirror) {
htmlDoc += '<li style="font-size: large;" class="console"><a href="' + mirror + '" target="_blank">' + mirror.replace(/^([^/]+\/\/[^/]+).*/, '$1') + '</a></li>';
});
htmlDoc += '</ul></body></html>';
iframe.onload = function () {
iframe.onload = null;
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(htmlDoc);
iframe.contentWindow.document.close();
uiUtil.tabTransitionToSection('library', params.showUIAnimations);
resizeIFrame();
}
iframe.src = 'about:blank';
}
}, 500); // Adjust the timeout if too long
};
iframe.setAttribute('src', params.altLibraryUrl);
};
// Add event listener to link which allows user to show file selectors
document.getElementById('selectorsDisplayLink').addEventListener('click', function (e) {
e.preventDefault();

View File

@ -124,6 +124,9 @@ params['contentInjectionMode'] = getSetting('contentInjectionMode') ||
params['useCanvasElementsForWebpTranscoding'] = null; // Value is determined in uiUtil.determineCanvasElementsWorkaround(), called when setting the content injection mode
params['libraryUrl'] = 'https://library.kiwix.org/'; // Url for iframe that will be loaded to download new zim files
params['altLibraryUrl'] = 'https://download.kiwix.org/zim/'; // Alternative Url for iframe (for use with unsupported browsers) that will be loaded to download new zim files
params['kiwixDownloadMirrors'] = ['https://ftp.fau.de/kiwix/zim/', 'https://mirrors.dotsrc.org/kiwix/zim/',
'https://www.mirrorservice.org/sites/download.kiwix.org/zim/', 'https://md.mirrors.hacktegic.com/kiwix-md/zim/',
'https://laotzu.ftp.acc.umu.se/mirror/kiwix.org/zim/', 'https://saimei.ftp.acc.umu.se/mirror/kiwix.org/zim/'];
params['cacheAPI'] = 'kiwix-js'; // Sets name of the prefix used to identify the cache in Cache API
params['cacheIDB'] = 'kiwix-zim'; // Sets name of the Indexed DB database
params['isFileSystemApiSupported'] = typeof window.showOpenFilePicker === 'function'; // Sets a boolean indicating whether the FileSystem API is supported