Difference between revisions of "Widget:DCTList"
From LINKS Community Center
Line 2: | Line 2: | ||
<includeonly> | <includeonly> | ||
<script> | <script> | ||
+ | // Returns a mapping from ['File:Img1.png', 'File:Img2.png'] to [{ title: 'File:Img1.png', url: 'http...'}, { title: 'File...', url: 'http...'}] | ||
async function getImages(imageTitles) { | async function getImages(imageTitles) { | ||
const imageUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' + encodeURIComponent(imageTitles.join('|')); | const imageUrlQuery = '/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=' + encodeURIComponent(imageTitles.join('|')); | ||
const imageUrlResponse = await fetch(imageUrlQuery).then(response => response.json()); | const imageUrlResponse = await fetch(imageUrlQuery).then(response => response.json()); | ||
− | return Object.getOwnPropertyNames(imageUrlResponse.query.pages).map( | + | return Object.getOwnPropertyNames(imageUrlResponse.query.pages).map(pageKey => ({ |
− | title: imageUrlResponse.query.pages[ | + | title: imageUrlResponse.query.pages[pageKey].title, |
− | url: imageUrlResponse.query.pages[ | + | url: imageUrlResponse.query.pages[pageKey].imageinfo[0].url |
})); | })); | ||
} | } | ||
Line 21: | Line 22: | ||
const imageData = await getImages(sources.map(source => source.image)); | const imageData = await getImages(sources.map(source => source.image)); | ||
− | imageData.forEach( | + | imageData.forEach(image => sources[sources.findIndex(source => source.image === image.title)].image = image.url); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | console.log('Sources:', sources) | ||
return sources; | return sources; | ||
} | } |
Revision as of 15:27, 2 June 2022
Development verstion of the DCT List.
Not ready for production!