<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta charset="utf-8" /> <title>bing wallpaper</title> </head> <body> <button>Fetch</button> <!-- https://www.eee.dog/tech/rand-pic-api.html --> </body> </html>
var page = { packageName: "ushio-api-img-wallpaper", //1.121.76 result: [], loadPackage: (package) => new Promise(resolve => { var url = `https://data.jsdelivr.com/v1/package/npm/${package}`; fetch(url).then(resp => resp.json()).then(res => { resolve(res.versions) }) }), loadVersion: (version) => new Promise(resolve => { var url = `https://data.jsdelivr.com/v1/package/npm/${page.packageName}@${version}`; fetch(url).then(resp => resp.json()).then(res => { resolve(res.files) }) }), loopVersion: (versions, index) => { index = index || 0; var version = versions[index++]; console.debug(`${index} / ${versions.length}`) page.loadVersion(version).then(res => { var listName = res.filter(f => f.name.startsWith('img_')).map(x => `${version}/${x.name}`); page.result = page.result.concat(listName); if (index < versions.length) { page.loopVersion(versions, index); } else { console.debug(`Done! ${page.result.length}`); page.build(); } }) }, build: () => { var arr = page.result.map(x => { return `${x.split('/')[0]}/${x.split('_')[1]}` }) console.debug(JSON.stringify(arr)) }, load: (startVersion) => { page.loadPackage(page.packageName).then(versions => { versions = versions.reverse(); if (startVersion != null) { var si = versions.findIndex(x => x == startVersion); versions = versions.slice(si); } page.loopVersion(versions); }) } } document.querySelector('button').addEventListener('click', function () { page.load(); })