filesafe/dist/js/misc/render.js.map
Bobby Wibowo d29621d5ff
Make render.js standalone
Despite that, it still expects the existence of a so-called main script
in "page" variable, and also expects to be loaded by it instead,
with an internal check to load itself if the main script fails to call
itself within the expected conditions.

Improved button colors in SweetAlert prompts.

Refactored window.onload() to DOMContentLoaded's event listener.
This should essentially allow pages to have multiple scripts that listen
to that event.

Bumped v1 version string and rebuilt client assets.
2020-06-20 02:30:57 +07:00

1 line
7.3 KiB
Plaintext

{"version":3,"sources":["render.js"],"names":["const","render","lsKey","type","configs","al","name","root","array","miku","config","selected","triggered","i","push","slice","showTogglePrompt","renderEnabled","localStorage","div","document","createElement","innerHTML","buttons","reload","text","className","confirm","swal","content","then","value","do","newValue","querySelector","checked","undefined","removeItem","timer","parseVersion","renderScript","dataset","version","length","previousElement","remove","element","Math","floor","random","alt","title","src","classList","add","addEventListener","body","appendChild","window","page","apiChecked"],"mappings":"AA8DA,IA5DAA,IAAMC,OAAS,CACbC,MAAO,SACPC,KAAM,OACNC,QAAS,CACPC,GAAI,CACFC,KAAM,cACNC,KAAM,aACNC,MAAO,CACL,0BACA,uBACA,cACA,eACA,eACA,cACA,cACA,cACA,cACA,gBACA,gBACA,oBACA,mBACA,iBACA,gBACA,gBACA,gBACA,kBACA,aACA,aACA,aACA,eACA,eACA,eACA,oBACA,kBACA,cACA,gBACA,gBACA,gBACA,gBACA,gBACA,gBACA,gBACA,kBACA,kBACA,kBACA,mBAGJC,KAAM,CACJH,KAAM,WACNC,KAAM,eACNC,MAAO,KAGXE,OAAQ,KACRC,SAAU,KACVC,WAAW,GAIJC,EAAI,EAAGA,GAAK,GAAIA,IACvBZ,OAAOG,QAAQK,KAAKD,MAAMM,MAAS,KAAOD,GAAGE,OAAO,GAAE,QAExDd,OAAOe,iBAAgB,WACrBhB,IAAMiB,IAAiD,MAA/BC,aAAajB,OAAOC,QACtCiB,EAAMC,SAASC,cAAc,OACnCF,EAAIG,UAAY,+IAIiCL,EAAgB,UAAY,IAAE,wCAC7Ch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WAKtE6C,EAAU1B,SAASC,cAAc,MACzBK,UAAY,kCACpBoB,EAAQK,MAAQlD,OAAOS,OAAOJ,KAC9BwC,EAAQxB,UAAY,gCAKtBwB,EAAQO,UAAUC,IAAI,UACtBR,EAAQS,iBAAiB,QAAStD,OAAOe,kBACzCI,SAASoC,KAAKC,YAAYX,KAG5BY,OAAOH,iBAAiB,oBAAkB,gBAG3BnB,IAATuB,MAAsBA,KAAKC,aAAe3D,OAAOW,WACnDX,OAAO+B","file":"render.js","sourcesContent":["/* global page, swal */\n\nconst render = {\n lsKey: 'render',\n type: 'miku', // This is intended to be hard-coded\n configs: {\n al: {\n name: 'ship waifu~',\n root: 'render/al/',\n array: [\n 'admiral_graf_spee_1.png',\n 'admiral_hipper_1.png',\n 'akagi_1.png',\n 'akashi_1.png',\n 'akashi_2.png',\n 'atago_1.png',\n 'atago_3.png',\n 'atago_4.png',\n 'atago_5.png',\n 'belfast_2.png',\n 'choukai_1.png',\n 'deutschland_1.png',\n 'enterprise_1.png',\n 'glorious_1.png',\n 'hammann_1.png',\n 'hammann_2.png',\n 'hammann_3.png',\n 'hatsuharu_1.png',\n 'kaga_1.png',\n 'kaga_2.png',\n 'kaga_3.png',\n 'laffey_1.png',\n 'laffey_2.png',\n 'laffey_3.png',\n 'prinz_eugen_3.png',\n 'san_diego_1.png',\n 'takao_3.png',\n 'unicorn_1.png',\n 'unicorn_2.png',\n 'unicorn_3.png',\n 'unicorn_4.png',\n 'unicorn_6.png',\n 'unicorn_7.png',\n 'unicorn_8.png',\n 'yamashiro_1.png',\n 'yamashiro_2.png',\n 'yamashiro_3.png',\n 'yukikaze_1.png'\n ]\n },\n miku: {\n name: 'miku ❤️~',\n root: 'render/miku/',\n array: []\n }\n },\n config: null,\n selected: null,\n triggered: false\n}\n\n// miku: Generate an array of file names from 001.png to 050.png\nfor (let i = 1; i <= 50; i++)\n render.configs.miku.array.push(`${('00' + i).slice(-3)}.png`)\n\nrender.showTogglePrompt = () => {\n const renderEnabled = !(localStorage[render.lsKey] === '0')\n const div = document.createElement('div')\n div.innerHTML = `\n <div class=\"field\">\n <div class=\"control\">\n <label class=\"checkbox\">\n <input id=\"swalRender\" type=\"checkbox\" ${renderEnabled ? 'checked' : ''}>\n Enable random render of ${render.config.name}\n </label>\n </div>\n <p class=\"help\">If disabled, you will still be able to see a small button on the bottom right corner of the screen to re-enable it.</p>\n </div>\n `\n\n const buttons = {}\n if (renderEnabled)\n buttons.reload = {\n text: 'Nah fam, show me a different render',\n className: 'swal-button--cancel'\n }\n buttons.confirm = true\n\n swal({\n content: div,\n buttons\n }).then(value => {\n if (value === 'reload') {\n render.do(true)\n } else if (value) {\n const newValue = div.querySelector('#swalRender').checked ? undefined : '0'\n if (newValue !== localStorage[render.lsKey]) {\n if (newValue)\n localStorage[render.lsKey] = newValue\n else\n localStorage.removeItem(render.lsKey)\n swal('', `Random render is now ${newValue ? 'disabled' : 'enabled'}.`, 'success', {\n buttons: false,\n timer: 1500\n })\n render.do()\n }\n }\n })\n}\n\nrender.parseVersion = () => {\n const renderScript = document.querySelector('#renderScript')\n if (renderScript && renderScript.dataset.version)\n return `?v=${renderScript.dataset.version}`\n return ''\n}\n\nrender.do = reload => {\n if (!render.triggered)\n render.triggered = true\n\n render.config = render.configs[render.type]\n if (!render.config || !render.config.array.length) return\n\n const previousElement = document.querySelector('body > .render')\n if (previousElement)\n previousElement.remove()\n\n const doRender = () => {\n if (render.version === undefined)\n render.version = render.parseVersion()\n\n // Let us just allow people to get new render when toggling the option\n render.selected = render.config.array[Math.floor(Math.random() * render.config.array.length)]\n element = document.createElement('img')\n element.alt = element.title = render.config.name\n element.className = 'is-hidden-mobile'\n element.src = `${render.config.root}${render.selected}${render.version}`\n }\n\n let element\n if (!reload && localStorage[render.lsKey] === '0') {\n element = document.createElement('a')\n element.className = 'button is-info is-hidden-mobile'\n element.title = render.config.name\n element.innerHTML = '<i class=\"icon-picture\"></i>'\n } else {\n doRender()\n }\n\n element.classList.add('render')\n element.addEventListener('click', render.showTogglePrompt)\n document.body.appendChild(element)\n}\n\nwindow.addEventListener('DOMContentLoaded', () => {\n // If the main script had already done its API check, yet render haven't been triggered, do it\n // This would only happen if this render script only gets loaded after the main script's API check\n if (page !== undefined && page.apiChecked && !render.triggered)\n render.do()\n})\n"]}