Tweak Zimit reading for edge cases

Former-commit-id: e8951f95abdcb764be10fa4a440ed046c25bbc27 [formerly c33bfc329278471c7977c2223de80cc411075e76 [formerly 777c2b1b5057e2dd415d26be64901521bd051bab]]
Former-commit-id: 29cb9464fc40f52a715de11ea01ef662ac49ecee [formerly 5f702c9eaf2a9809245ef56a0d2533e5af90c4af]
Former-commit-id: 08cc92a36b3e723fb0e372b00db0e8258ce01509
This commit is contained in:
Jaifroid 2022-06-01 23:47:07 +01:00
parent aa0e5b44bb
commit a6c735d5ae

View File

@ -45,7 +45,8 @@ define([], function () {
*/
function filterReplayFiles(dirEntry) {
if (!(dirEntry && dirEntry.url)) return null;
if (/(?:chunk\.js|\bload\.js|\bsw\.js|analytics.*\.js|remote.loader\.js|survey\.js|yuiloader\.js)(?:[?#]|$)/i.test(dirEntry.url)) {
if (/(?:\bload\.js|\bsw\.js|analytics.*\.js|remote.loader\.js|survey\.js|yuiloader\.js|developer\.mozilla\.org\/static\/js\/main\..+\.js)(?:[?#]|$)/i.test(dirEntry.url)) {
// if (/(?:chunk\.js|\bload\.js|\bsw\.js|analytics.*\.js|remote.loader\.js|survey\.js|yuiloader\.js)(?:[?#]|$)/i.test(dirEntry.url)) {
dirEntry.nullify = true;
} else if (params.isLandingPage && /^index\.html(?:[?#]|$)/.test(dirEntry.url)) {
dirEntry.inspect = true;
@ -97,7 +98,8 @@ define([], function () {
* Note that some Zimit ZIMs have mimeteypes like 'text/html;raw=true', so we can't simply match 'text/html'
* Other ZIMs have a mimetype like 'html' (with no 'text/'), so we have to match as generically as possible
*/
if (/\bhtml\b/i.test(mimetype)) { //
var indexRoot = window.location.pathname.replace(/[^\/]+$/, '') + encodeURI(selectedArchive._file.name);
if (/\bhtml\b/i.test(mimetype)) {
var zimitPrefix = data.match(regexpGetZimitPrefix);
zimitPrefix = zimitPrefix ? zimitPrefix[2] : params.zimitPrefix;
// Remove lazyimgage system and noscript tags that comment out images
@ -105,7 +107,6 @@ define([], function () {
data = data.replace(/<noscript>\s*(<img\b[^>]+>)\s*<\/noscript>/ig, '$1');
data = data.replace(/<span\b[^>]+lazy-image-placeholder[^<]+<\/span>\s*/ig, '');
// Get stem for constructing an absolute URL
var indexRoot = window.location.pathname.replace(/[^\/]+$/, '') + encodeURI(selectedArchive._file.name);
data = data.replace(regexpZimitHtmlLinks, function(match, blockStart, equals, quote, relAssetUrl, blockClose) {
var newBlock = match;
var assetUrl = relAssetUrl;
@ -205,6 +206,7 @@ define([], function () {
*/
if (/\b(javascript|html)\b/i.test(mimetype)) {
data = data.replace(regexpZimitJavascriptLinks, function (match, url) {
if (/www\.w3\.org\/XML\//i.test(url)) return match;
var newBlock = match;
var assetUrl = url;
assetUrl = assetUrl.replace(/^\/\//, dirEntry.namespace + '/');
@ -218,8 +220,12 @@ define([], function () {
// console.debug('Transform: \n' + match + '\n -> ' + newBlock);
return newBlock;
});
data = data.replace(/(['"])(?:\/?)((?:static|api)\/)/ig, '$1' + window.location.origin + indexRoot + '/' + dirEntry.namespace + '/' + params.zimitPrefix + '/$2');
} // End of JavaScript transformations
// Add a base href
// data = data.replace(/(<head\b[^>]*>\s*)/i, '$1<base href="' + window.location.origin + indexRoot + '/' + '">');
return data;
}