Browse Source

Fandom data urls

MarkusRost 3 năm trước cách đây
mục cha
commit
4facbcecf6
1 tập tin đã thay đổi với 11 bổ sung12 xóa
  1. 11 12
      functions/parse_page.js

+ 11 - 12
functions/parse_page.js

@@ -345,23 +345,22 @@ function parse_page(lang, msg, content, embed, wiki, reaction, {title, contentmo
 						section.nextUntil(['h1','h2','h3','h4','h5','h6'].slice(0, sectionLevel).join(', '))
 						section.nextUntil(['h1','h2','h3','h4','h5','h6'].slice(0, sectionLevel).join(', '))
 					);
 					);
 					section.find('div, ' + removeClasses.join(', ')).remove();
 					section.find('div, ' + removeClasses.join(', ')).remove();
-					extraImages.push(
+					extraImages.push(...[
 						...sectionContent.find(infoboxList.join(', ')).find([
 						...sectionContent.find(infoboxList.join(', ')).find([
 							'tr:eq(1) img',
 							'tr:eq(1) img',
 							'div.images img',
 							'div.images img',
 							'figure.pi-image img',
 							'figure.pi-image img',
 							'div.infobox-imagearea img'
 							'div.infobox-imagearea img'
-						].join(', ')).toArray().filter( img => {
-							let imgURL = img.attribs.src;
-							if ( !imgURL ) return false;
-							return ( /^(?:https?:)?\/\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
-						} ).map( img => new URL(img.attribs.src.replace( /^(?:https?:)?\/\//, 'https://' ), wiki).href ),
-						...sectionContent.find('ul.gallery > li.gallerybox img').toArray().filter( img => {
-							let imgURL = img.attribs.src;
-							if ( !imgURL ) return false;
-							return ( /^(?:https?:)?\/\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
-						} ).map( img => new URL(img.attribs.src.replace( /^(?:https?:)?\/\//, 'https://' ), wiki).href )
-					);
+						].join(', ')).toArray(),
+						...sectionContent.find('ul.gallery > li.gallerybox img').toArray()
+					].filter( img => {
+						let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
+						if ( !imgURL ) return false;
+						return ( /^(?:https?:)?\/\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
+					} ).map( img => {
+						let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
+						return new URL(imgURL.replace( /^(?:https?:)?\/\//, 'https://' ), wiki).href;
+					} ));
 					sectionContent.find(infoboxList.join(', ')).remove();
 					sectionContent.find(infoboxList.join(', ')).remove();
 					sectionContent.find('div, ' + removeClasses.join(', ')).not(removeClassesExceptions.join(', ')).remove();
 					sectionContent.find('div, ' + removeClasses.join(', ')).not(removeClassesExceptions.join(', ')).remove();
 					var name = htmlToPlain(section).trim();
 					var name = htmlToPlain(section).trim();