diff options
Diffstat (limited to 'webAO/utils')
| -rw-r--r-- | webAO/utils/calculateApngLength.js | 24 | ||||
| -rw-r--r-- | webAO/utils/calculateGifLength.js | 14 | ||||
| -rw-r--r-- | webAO/utils/fileExistsSync.js | 11 | ||||
| -rw-r--r-- | webAO/utils/getAnimLength.js | 12 |
4 files changed, 25 insertions, 36 deletions
diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index d6a40b6..6b9aed2 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -1,7 +1,7 @@ /** - * Adds up the chunk delays to find out how long a APNG is - * @param {data} apngFile the APNG data - */ + * Adds up the chunk delays to find out how long a APNG is + * @param {data} apngFile the APNG data + */ const calculateApngLength = (apngFile) => { const d = new Uint8Array(apngFile); // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk @@ -9,20 +9,20 @@ const calculateApngLength = (apngFile) => { for (let i = 0; i < d.length; i++) { // Find fcTL header (66 63 54 4C) if (d[i] === 0x66 - && d[i + 1] === 0x63 - && d[i + 2] === 0x54 - && d[i + 3] === 0x4C) { + && d[i + 1] === 0x63 + && d[i + 2] === 0x54 + && d[i + 3] === 0x4C) { // numerator and denominator - const delay_num = Number(d[i + 23]); - const delay_den = Number(d[i + 25]); + const delayNum = Number(d[i + 23]); + const delayDen = Number(d[i + 25]); let delay; // minimum is 100ms - if (delay_den == 0) - delay = delay_num / 100; + if (delayDen === 0) + delay = delayNum / 100; else - delay = delay_num / delay_den; + delay = delayNum / delayDen; - duration = duration + delay; + duration += delay; } } return duration * 10; diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js index 1df0ba9..ca0e1e1 100644 --- a/webAO/utils/calculateGifLength.js +++ b/webAO/utils/calculateGifLength.js @@ -1,8 +1,8 @@ /** - * Adds up the frame delays to find out how long a GIF is - * I totally didn't steal this - * @param {data} gifFile the GIF data - */ + * Adds up the frame delays to find out how long a GIF is + * I totally didn't steal this + * @param {data} gifFile the GIF data + */ const calculateGifLength = (gifFile) => { const d = new Uint8Array(gifFile); // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/ @@ -11,9 +11,9 @@ const calculateGifLength = (gifFile) => { for (let i = 0; i < d.length; i++) { // Find a Graphic Control Extension hex(21F904__ ____ __00) if (d[i] === 0x21 - && d[i + 1] === 0xF9 - && d[i + 2] === 0x04 - && d[i + 7] === 0x00) { + && d[i + 1] === 0xF9 + && d[i + 2] === 0x04 + && d[i + 7] === 0x00) { // Swap 5th and 6th bytes to get the delay per frame const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); diff --git a/webAO/utils/fileExistsSync.js b/webAO/utils/fileExistsSync.js deleted file mode 100644 index 1d7fde2..0000000 --- a/webAO/utils/fileExistsSync.js +++ /dev/null @@ -1,11 +0,0 @@ -const fileExistsSync = (url) => { - try { - const http = new XMLHttpRequest(); - http.open('HEAD', url, false); - http.send(); - return http.status != 404; - } catch (e) { - return false; - } -}; -export default fileExistsSync; diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index aa303cf..f9d793f 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -1,11 +1,11 @@ import calculatorHandler from './calculatorHandler'; -import fileExists from './fileExists.js'; -import { requestBuffer } from '../services/request.js'; +import fileExists from './fileExists'; +import { requestBuffer } from '../services/request'; /** - * Gets animation length. If the animation cannot be found, it will - * silently fail and return 0 instead. - * @param {string} filename the animation file name - */ + * Gets animation length. If the animation cannot be found, it will + * silently fail and return 0 instead. + * @param {string} filename the animation file name + */ const getAnimLength = async (url) => { const extensions = ['.gif', '.webp', '.apng']; |
