Fix misplaced hatnote in ActionParse ZIMs

Fixes #723.
This commit is contained in:
Jaifroid 2025-06-10 11:28:29 +01:00
parent f078afede7
commit 84271c65f3

View File

@ -2647,7 +2647,6 @@ function removePageMaxWidth () {
if (!appstate.wikimediaZimLoaded) return; if (!appstate.wikimediaZimLoaded) return;
// Note that the UWP app has no access to the content of opened windows, so we can't access the DOM of the articleWindow // Note that the UWP app has no access to the content of opened windows, so we can't access the DOM of the articleWindow
if (/UWP/.test(params.appType) && appstate.target !== 'iframe') return; if (/UWP/.test(params.appType) && appstate.target !== 'iframe') return;
var zimType;
var cssSource; var cssSource;
var contentElement; var contentElement;
var docStyle; var docStyle;
@ -2657,8 +2656,8 @@ function removePageMaxWidth () {
var body = doc.body; var body = doc.body;
// Remove max-width: 100ex; from the element's style attribute (in new ZIMs from mobile html enpoint) // Remove max-width: 100ex; from the element's style attribute (in new ZIMs from mobile html enpoint)
if (body.style) body.style.maxWidth = ''; if (body.style) body.style.maxWidth = '';
zimType = /<link\b[^>]+(?:minerva|mobile)/i.test(doc.head.innerHTML) ? 'mobile' : 'desktop'; appstate.zimThemeType = /<link\b[^>]+(?:minerva|mobile)/i.test(doc.head.innerHTML) ? 'mobile' : 'desktop';
cssSource = params.cssSource === 'auto' ? zimType : params.cssSource; cssSource = params.cssSource === 'auto' ? appstate.zimThemeType : params.cssSource;
var idArray = ['content', 'bodyContent']; var idArray = ['content', 'bodyContent'];
for (var i = 0; i < idArray.length; i++) { for (var i = 0; i < idArray.length; i++) {
contentElement = doc.getElementById(idArray[i]); contentElement = doc.getElementById(idArray[i]);
@ -2680,7 +2679,7 @@ function removePageMaxWidth () {
updatedCssText = params.removePageMaxWidth ? '100%' : '55.8em'; updatedCssText = params.removePageMaxWidth ? '100%' : '55.8em';
docStyle.maxWidth = updatedCssText; docStyle.maxWidth = updatedCssText;
docStyle.cssText = docStyle.cssText.replace(/max-width:[^;]+/i, 'max-width: ' + updatedCssText + ' !important'); docStyle.cssText = docStyle.cssText.replace(/max-width:[^;]+/i, 'max-width: ' + updatedCssText + ' !important');
if (params.removePageMaxWidth || zimType == 'mobile') docStyle.border = '0'; if (params.removePageMaxWidth || appstate.zimThemeType == 'mobile') docStyle.border = '0';
} }
docStyle.margin = '0 auto'; docStyle.margin = '0 auto';
} }
@ -4336,6 +4335,7 @@ function archiveReadyCallback (archive) {
// (this only affects Restricted mode) // (this only affects Restricted mode)
appstate.target = 'iframe'; appstate.target = 'iframe';
appstate.wikimediaZimLoaded = /wikipedia|wikivoyage|mdwiki|wiktionary/i.test(archive.file.name); appstate.wikimediaZimLoaded = /wikipedia|wikivoyage|mdwiki|wiktionary/i.test(archive.file.name);
appstate.zimThemeType = 'desktop';
appstate.pureMode = false; appstate.pureMode = false;
// Reset params.assetsCache in case it was changed below // Reset params.assetsCache in case it was changed below
params.assetsCache = settingsStore.getItem('assetsCache') !== 'false'; params.assetsCache = settingsStore.getItem('assetsCache') !== 'false';
@ -6291,6 +6291,7 @@ function displayArticleContentInContainer (dirEntry, htmlArticle) {
htmlArticle = htmlArticle.replace(noexcerpt[1], ''); htmlArticle = htmlArticle.replace(noexcerpt[1], '');
htmlArticle = htmlArticle.replace(/(<\/h1>\s*)/i, '$1' + noexcerpt[1]); htmlArticle = htmlArticle.replace(/(<\/h1>\s*)/i, '$1' + noexcerpt[1]);
} }
if (appstate.zimThemeType === 'mobile') {
// Put misplaced hatnote headers inside <h1> block back in correct position @TODO remove this when fixed in mw-offliner // Put misplaced hatnote headers inside <h1> block back in correct position @TODO remove this when fixed in mw-offliner
var hatnote; var hatnote;
var hatnotes = []; var hatnotes = [];
@ -6310,7 +6311,7 @@ function displayArticleContentInContainer (dirEntry, htmlArticle) {
for (i = hatnotes.length; i--;) { for (i = hatnotes.length; i--;) {
htmlArticle = htmlArticle.replace(/(<\/h1>\s*)/i, '$1' + hatnotes[i].replace(/(<div\s+)/i, '$1style="padding-top:10px;" ')); htmlArticle = htmlArticle.replace(/(<\/h1>\s*)/i, '$1' + hatnotes[i].replace(/(<div\s+)/i, '$1style="padding-top:10px;" '));
} }
}
// Remove white background colour (causes flashes in dark mode) // Remove white background colour (causes flashes in dark mode)
htmlArticle = htmlArticle.replace(/(<body\b[^>]+style=["'][^"']*)background-color\s*:\s*[^;]+;\s*/i, '$1'); htmlArticle = htmlArticle.replace(/(<body\b[^>]+style=["'][^"']*)background-color\s*:\s*[^;]+;\s*/i, '$1');
htmlArticle = htmlArticle.replace(/(<div\b(?=[^>]+class=\s*["'][^"']*mw-body)[^>]+style=["'][^"']*)background-color\s*:\s*[^;]+;\s*/i, '$1'); htmlArticle = htmlArticle.replace(/(<div\b(?=[^>]+class=\s*["'][^"']*mw-body)[^>]+style=["'][^"']*)background-color\s*:\s*[^;]+;\s*/i, '$1');