diff options
Diffstat (limited to 'webAO/utils')
| -rw-r--r-- | webAO/utils/calculateGifLength.js | 32 | ||||
| -rw-r--r-- | webAO/utils/calculateWebpLength.js | 12 | ||||
| -rw-r--r-- | webAO/utils/calculatorHandler.js | 10 | ||||
| -rw-r--r-- | webAO/utils/getCookie.js | 32 | ||||
| -rw-r--r-- | webAO/utils/setCookie.js | 8 |
5 files changed, 47 insertions, 47 deletions
diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js index a57264d..1df0ba9 100644 --- a/webAO/utils/calculateGifLength.js +++ b/webAO/utils/calculateGifLength.js @@ -1,27 +1,27 @@ - /** +/** * 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/ - // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt - let duration = 0; - for (let i = 0; i < d.length; i++) { - // Find a Graphic Control Extension hex(21F904__ ____ __00) - if (d[i] === 0x21 + const d = new Uint8Array(gifFile); + // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/ + // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt + let duration = 0; + 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) { - // Swap 5th and 6th bytes to get the delay per frame - const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); + // Swap 5th and 6th bytes to get the delay per frame + const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); - // Should be aware browsers have a minimum frame delay - // e.g. 6ms for IE, 2ms modern browsers (50fps) - duration += delay < 2 ? 10 : delay; - } + // Should be aware browsers have a minimum frame delay + // e.g. 6ms for IE, 2ms modern browsers (50fps) + duration += delay < 2 ? 10 : delay; } - return duration * 10; } - export default calculateGifLength
\ No newline at end of file + return duration * 10; +}; +export default calculateGifLength; diff --git a/webAO/utils/calculateWebpLength.js b/webAO/utils/calculateWebpLength.js index 38da7c1..1b422a0 100644 --- a/webAO/utils/calculateWebpLength.js +++ b/webAO/utils/calculateWebpLength.js @@ -1,22 +1,22 @@ const calculateWebpLength = (webpFile) => { - let d = new Uint8Array(webpFile); + const d = new Uint8Array(webpFile); // https://developers.google.com/speed/webp/docs/riff_container#animation let duration = 0; - for (var i = 0; i < d.length; i++) { + for (let i = 0; i < d.length; i++) { // Find ANMF header (41 4E 4D 46) if (d[i] === 0x41 && d[i + 1] === 0x4E && d[i + 2] === 0x4D && d[i + 3] === 0x46) { // Swap 5th and 6th bytes to get the delay per frame - let delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF); + const delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF); - // Should be aware browsers have a minimum frame delay + // Should be aware browsers have a minimum frame delay // e.g. 6ms for IE, 2ms modern browsers (50fps) duration += delay < 2 ? 10 : delay; } } return duration; -} +}; -export default calculateWebpLength
\ No newline at end of file +export default calculateWebpLength; diff --git a/webAO/utils/calculatorHandler.js b/webAO/utils/calculatorHandler.js index 5ed8a43..7686573 100644 --- a/webAO/utils/calculatorHandler.js +++ b/webAO/utils/calculatorHandler.js @@ -1,7 +1,7 @@ -import calculateGifLength from "./calculateGifLength"; -import calculateWebpLength from "./calculateWebpLength"; +import calculateGifLength from './calculateGifLength'; +import calculateWebpLength from './calculateWebpLength'; export default { - '.gif': calculateGifLength, - '.webp': calculateWebpLength -}
\ No newline at end of file + '.gif': calculateGifLength, + '.webp': calculateWebpLength, +}; diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js index 000c870..3be0733 100644 --- a/webAO/utils/getCookie.js +++ b/webAO/utils/getCookie.js @@ -5,22 +5,22 @@ * @param {String} cname The name of the cookie to return */ const getCookie = (cname) => { - try { - const name = `${cname}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const ca = decodedCookie.split(';'); - for (let i = 0; i < ca.length; i++) { - let c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1); - } - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); - } + try { + const name = `${cname}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); } - return ''; - } catch (error) { - return ''; } + return ''; + } catch (error) { + return ''; } - export default getCookie;
\ No newline at end of file +}; +export default getCookie; diff --git a/webAO/utils/setCookie.js b/webAO/utils/setCookie.js index d3699a2..9734eae 100644 --- a/webAO/utils/setCookie.js +++ b/webAO/utils/setCookie.js @@ -4,7 +4,7 @@ * @param {String} cname The name of the cookie to return * @param {String} value The value of that cookie option */ - const setCookie = (cname, value) => { - document.cookie = `${cname}=${value}`; - } - export default setCookie
\ No newline at end of file +const setCookie = (cname, value) => { + document.cookie = `${cname}=${value}`; +}; +export default setCookie; |
