Skip to content

Commit ad3e4af

Browse files
committed
include webp files
1 parent dcf28d3 commit ad3e4af

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎cmds/wiki/general.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export default function mw_check_wiki(lang, msg, title, wiki, cmd, reaction, spo
444444
try {
445445
if ( querypage.ns === 6 ) {
446446
var pageimage = ( querypage?.original?.source || wiki.toLink('Special:FilePath/' + querypage.title, {version:Date.now()}) );
447-
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
447+
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif|webp)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
448448
else if ( !noEmbed && querypage.title.toLowerCase().endsWith( '.svg' ) && querypage?.original?.width ) {
449449
embed.setImage( wiki.toLink('Special:FilePath/' + querypage.title, {width:querypage.original.width,version:Date.now()}) );
450450
}
@@ -508,7 +508,7 @@ export default function mw_check_wiki(lang, msg, title, wiki, cmd, reaction, spo
508508
var embed = null;
509509
if ( !noEmbed ) {
510510
embed = new EmbedBuilder().setAuthor( {name: body.query.general.sitename} ).setTitle( escapeFormatting(querypage.title) ).setURL( pagelink ).setDescription( '[' + lang.get('search.media') + '](<' + wiki.toLink(querypage.title, '', '', true) + '>)' );
511-
if ( /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pagelink );
511+
if ( /\.(?:png|jpg|jpeg|gif|webp)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pagelink );
512512
}
513513
return {message: {
514514
content: spoiler + '<' + pagelink + '>' + spoiler,
@@ -533,7 +533,7 @@ export default function mw_check_wiki(lang, msg, title, wiki, cmd, reaction, spo
533533
try {
534534
if ( querypage.ns === 6 ) {
535535
var pageimage = ( querypage?.original?.source || wiki.toLink('Special:FilePath/' + querypage.title, {version:Date.now()}) );
536-
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
536+
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif|webp)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
537537
else if ( !noEmbed && querypage.title.toLowerCase().endsWith( '.svg' ) && querypage?.original?.width ) {
538538
embed.setImage( wiki.toLink('Special:FilePath/' + querypage.title, {width:querypage.original.width,version:Date.now()}) );
539539
}

‎cmds/wiki/random.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default function mw_random(lang, msg, wiki, reaction, spoiler, noEmbed, n
9595
try {
9696
if ( querypage.ns === 6 ) {
9797
var pageimage = ( querypage?.original?.source || wiki.toLink('Special:FilePath/' + querypage.title, {version:Date.now()}) );
98-
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
98+
if ( !noEmbed && /\.(?:png|jpg|jpeg|gif|webp)$/.test(querypage.title.toLowerCase()) ) embed.setImage( pageimage );
9999
else if ( !noEmbed && querypage.title.toLowerCase().endsWith( '.svg' ) && querypage?.original?.width ) {
100100
embed.setImage( wiki.toLink('Special:FilePath/' + querypage.title, {width:querypage.original.width,version:Date.now()}) );
101101
}

‎functions/parse_page.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default function parse_page(lang, msg, content, embed, wiki, reaction, {n
267267
}
268268
}
269269
let extraImages = [];
270-
if ( thumbnail && embed.data.thumbnail?.url && !/\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(embed.data.thumbnail?.url) ) embed.setThumbnail( thumbnail );
270+
if ( thumbnail && embed.data.thumbnail?.url && !/\.(?:png|jpg|jpeg|gif|webp)(?:\/|\?|$)/i.test(embed.data.thumbnail?.url) ) embed.setThumbnail( thumbnail );
271271
return got.get( wiki + 'api.php?uselang=' + uselang + '&action=parse' + ( noRedirect ? '' : '&redirects=true' ) + '&prop=text|images|displaytitle&disablelimitreport=true&disableeditsection=true&disabletoc=true&page=' + encodeURIComponent( title ) + '&format=json', {
272272
timeout: {
273273
request: 10_000
@@ -333,7 +333,7 @@ export default function parse_page(lang, msg, content, embed, wiki, reaction, {n
333333
let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
334334
if ( !imgURL ) return false;
335335
if ( img.attribs['data-image-name']?.toLowerCase().endsWith( '.gif' ) ) return true;
336-
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
336+
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif|webp)(?:\/|\?|$)/i.test(imgURL) );
337337
} );
338338
if ( image ) {
339339
let imgURL = ( image.attribs.src?.startsWith?.( 'data:' ) ? image.attribs['data-src'] : image.attribs.src );
@@ -469,19 +469,19 @@ export default function parse_page(lang, msg, content, embed, wiki, reaction, {n
469469
}
470470
else if ( embed.data.thumbnail?.url === thumbnail ) {
471471
try {
472-
response.body.parse.images = response.body.parse.images.map( pageimage => pageimage.toString() ).filter( pageimage => /\.(?:png|jpg|jpeg|gif)$/.test(pageimage.toLowerCase()) );
473-
let image = response.body.parse.images.find( pageimage => pageimage.toLowerCase().replace( /\.(?:png|jpg|jpeg|gif)$/, '' ) === title.toLowerCase().replaceAll( ' ', wiki.spaceReplacement ?? '_' ) );
472+
response.body.parse.images = response.body.parse.images.map( pageimage => pageimage.toString() ).filter( pageimage => /\.(?:png|jpg|jpeg|gif|webp)$/.test(pageimage.toLowerCase()) );
473+
let image = response.body.parse.images.find( pageimage => pageimage.toLowerCase().replace( /\.(?:png|jpg|jpeg|gif|webp)$/, '' ) === title.toLowerCase().replaceAll( ' ', wiki.spaceReplacement ?? '_' ) );
474474
if ( !image ) image = response.body.parse.images.find( pageimage => pageimage.toLowerCase().includes( title.toLowerCase().replaceAll( ' ', wiki.spaceReplacement ?? '_' ) ) );
475475
if ( !image ) {
476476
let first = $(infoboxList.join(', ')).find('img').filter( (i, img) => {
477477
let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
478478
if ( img.attribs['data-image-name']?.toLowerCase().endsWith( '.gif' ) ) return true;
479-
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
479+
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif|webp)(?:\/|\?|$)/i.test(imgURL) );
480480
} ).first();
481481
if ( !first.length ) first = $('img').filter( (i, img) => {
482482
let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
483483
if ( img.attribs['data-image-name']?.toLowerCase().endsWith( '.gif' ) ) return true;
484-
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
484+
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif|webp)(?:\/|\?|$)/i.test(imgURL) );
485485
} ).first();
486486
if ( first.length ) {
487487
if ( first.attr('data-image-name')?.toLowerCase().endsWith( '.gif' ) ) image = first.attr('data-image-name');
@@ -600,7 +600,7 @@ export default function parse_page(lang, msg, content, embed, wiki, reaction, {n
600600
].filter( img => {
601601
let imgURL = ( img.attribs.src?.startsWith?.( 'data:' ) ? img.attribs['data-src'] : img.attribs.src );
602602
if ( !imgURL ) return false;
603-
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif)(?:\/|\?|$)/i.test(imgURL) );
603+
return ( /^(?:(?:https?:)?\/)?\//.test(imgURL) && /\.(?:png|jpg|jpeg|gif|webp)(?:\/|\?|$)/i.test(imgURL) );
604604
} ).map( img => {
605605
if ( img.attribs['data-image-name']?.toLowerCase().endsWith( '.gif' ) ) return wiki.toLink('Special:FilePath/' + img.attribs['data-image-name']);
606606
try {

‎util/functions.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function parse_infobox(infobox, embed, embedLimits = {fieldCount: 25, fieldLengt
118118
if ( embed.data.thumbnail?.url !== thumbnail ) break;
119119
try {
120120
let image = infobox.data.find( img => {
121-
if ( !/\.(?:png|jpg|jpeg|gif)$/.test(img.name) ) return false;
121+
if ( !/\.(?:png|jpg|jpeg|gif|webp)$/.test(img.name) ) return false;
122122
if ( pagelink ) return /^(?:(?:https?:)?\/)?\//.test(img.url);
123123
return /^(?:https?:)?\/\//.test(img.url);
124124
} );

0 commit comments

Comments
 (0)