Skateside / pocket-grimoire

A mobile version of the Blood on the Clocktower grimoire
https://www.pocketgrimoire.co.uk
GNU General Public License v3.0
34 stars 14 forks source link

Download all images #33

Open Skateside opened 2 years ago

Skateside commented 2 years ago

Could be useful when you're going somewhere with spotty a internet connection. A dialog could download all images so your phone has them cached.

It's possible to go through the stylesheets to read all the background images (including their hashes) and the characters each have their own image.

[...document.styleSheets[0].cssRules].filter(({ style }) => style?.backgroundImage).map(({ style }) => style.backgroundImage)
Skateside commented 2 years ago

Helpful regexp https://github.com/lodash/lodash/blob/master/.internal/stringToPath.js

Skateside commented 2 years ago
const regexp = (/url\((['"]?)([^\1)]+)\1\)/);
const backgroundImages = [/* array here */];
const sources = backgroundImages
    .map((string) => string.match(new RegExp(regexp, "g")))
    .filter(Boolean)
    .map((matches) => matches.map((str) => str.match(regexp)?.[2]))
    .flat();

// sources contains an array of all background image URLs found.