diff --git a/server/index.js b/server/index.js index cc7fc5e..0a9b9ec 100644 --- a/server/index.js +++ b/server/index.js @@ -33,20 +33,25 @@ app.get('/cdn/*', cors({ }), async (req, res, next) => { const reqTarget = req.path.startsWith('/cdn/3kh0/') ? `https://player.work/${req.path.replace('/cdn/3kh0/', '')}` : `https://raw.githubusercontent.com/Skoolgq/Polaris-Assets/main/${req.path.replace('/cdn/', '')}`; - const asset = await fetch(reqTarget); + try { + const asset = await fetch(reqTarget); - if (asset.status == 200) { - var data = Buffer.from(await asset.arrayBuffer()); + if (asset.status == 200) { + var data = Buffer.from(await asset.arrayBuffer()); - const noRewrite = ['.unityweb']; - if (!noRewrite.includes(mime.getExtension(reqTarget))) res.writeHead(200, { - 'content-type': mime.getType(reqTarget) - }); + const noRewrite = ['.unityweb']; + if (!noRewrite.includes(mime.getExtension(reqTarget))) res.writeHead(200, { + 'content-type': mime.getType(reqTarget) + }); - if (mime.getType(reqTarget) === 'text/html') data = data + ''; + if (mime.getType(reqTarget) === 'text/html') data = data + ''; - res.end(data); - } else next(); + res.end(data); + } else next(); + } catch { + res.setHeader('content-type', 'text/html'); + res.status(404).end(await rewriter.html(fs.readFileSync(path.join(__dirname, '../pages/404.html')))); + } }); app.get('*', (req, res, next) => { diff --git a/static/assets/js/main.js b/static/assets/js/main.js index 52b61c0..27f0ebe 100644 --- a/static/assets/js/main.js +++ b/static/assets/js/main.js @@ -103,10 +103,10 @@ const hyperlinkHandler = (hyperlink, e) => { document.querySelectorAll('a').forEach(hyperlink => hyperlink.addEventListener('click', (e) => hyperlinkHandler(hyperlink, e))); -window.onhashchange = () => { +window.addEventListener('hashchange', () => { if (location.hash === '#settings') document.querySelector('.sidebar').classList.add('active'); else document.querySelector('.sidebar').classList.remove('active'); -}; +}); if (window.self === window.top && location.pathname !== '/view') setTimeout(async () => { loadSettings(); @@ -114,7 +114,6 @@ if (window.self === window.top && location.pathname !== '/view') setTimeout(asyn if (location.pathname === '/games') Games.load(); if (location.pathname === '/apps') Apps.load(); if (location.pathname === '/search') Search.load(); - if (location.pathname === '/') Search.load(); if (location.pathname === '/cheats') Cheats.load(); }, 500); @@ -221,9 +220,9 @@ if (window.self === window.top && location.pathname !== '/view') { else document.querySelector('.navbar').classList.remove('scrolling'); } -if (window.self === window.top && location.pathname !== '/view') window.onscroll = () => { +if (window.self === window.top && location.pathname !== '/view') window.addEventListener('scroll', () => { if (window.scrollY !== 0) document.querySelector('.navbar').classList.add('scrolling'); else document.querySelector('.navbar').classList.remove('scrolling'); -} +}); if (window.self !== window.top && document.querySelector('.navbar')) document.querySelector('.navbar').remove(); \ No newline at end of file diff --git a/static/assets/js/settings.js b/static/assets/js/settings.js index d69f5c2..6f78746 100644 --- a/static/assets/js/settings.js +++ b/static/assets/js/settings.js @@ -278,12 +278,12 @@ const loadSidebarInterface = () => { document.querySelector('#panic_url').addEventListener('input', (e) => settingsStorage.set('panic_url', document.querySelector('#panic_url').value)); - window.onkeydown = (e) => { + window.addEventListener('keydown', (e) => { if (document.querySelector('#panic_key') == document.activeElement) { document.querySelector('#panic_key').value = e.key; settingsStorage.set('panic_key', document.querySelector('#panic_key').value); } - } + }); document.querySelector('#themes').querySelectorAll('button').forEach(el => el.onclick = () => Theme.set(el.innerText.toLocaleLowerCase())); @@ -349,12 +349,11 @@ const loadSettings = () => { }); } - window.onkeydown = (e) => { + window.addEventListener('keydown', (e) => { if (e.key === settingsStorage.get('panic_key')) { if (settingsStorage.get('panic_url')) window.location.href = settingsStorage.get('panic_url'); - else new PolarisError('A panic key was used but no url was found.'); } - } + }); /*if (new URLSearchParams(location.search).get('clickoff')) { diff --git a/static/assets/js/utils.js b/static/assets/js/utils.js index 3a47dce..9a9f7d5 100644 --- a/static/assets/js/utils.js +++ b/static/assets/js/utils.js @@ -8,7 +8,7 @@ import ctc from './utils/ctc.js'; * The storage interface for polaris * @param {string} containerName */ -const storage = (containerName) => { +export const storage = (containerName) => { return { /** * Get a value from the storage container @@ -54,13 +54,13 @@ const storage = (containerName) => { /** * @returns {string} */ -const uuid = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); +export const uuid = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); /** * Register a proxy service worker * @param {'uv' | 'dynamic'} proxy */ -const loadProxyWorker = async (proxy) => await navigator.serviceWorker.register(`/${proxy}/sw.js`, { +export const loadProxyWorker = async (proxy) => await navigator.serviceWorker.register(`/${proxy}/sw.js`, { scope: `/${proxy}/service/` }); @@ -102,7 +102,7 @@ const loadPageScript = () => { } }; -const encoder = { +export const encoder = { b64: { encode: (data) => btoa(data), decode: (data) => atob(data) @@ -118,7 +118,7 @@ const encoder = { * @param {string} target * @param {{ trusted: boolean }} options */ -const redirect = (target, options) => location.href = `/view?load=${btoa(JSON.stringify({ +export const redirect = (target, options) => location.href = `/view?load=${btoa(JSON.stringify({ target, redirect: true, trusted: options.trusted @@ -128,7 +128,7 @@ const redirect = (target, options) => location.href = `/view?load=${btoa(JSON.st * Load a url into the view page * @param {{ target: string, title: string, return: string, proxied: boolean }} options */ -const createViewPage = (options) => location.href = `/view?load=${btoa(JSON.stringify({ +export const createViewPage = (options) => location.href = `/view?load=${btoa(JSON.stringify({ return: options.return || location.href, proxied: options.proxied, target: options.target, @@ -140,15 +140,21 @@ const createViewPage = (options) => location.href = `/view?load=${btoa(JSON.stri * @param {string} url * @returns {boolean} */ -const isValidURL = (url) => /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/.test(url); +export const isValidURL = (url) => /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/.test(url); /** * Get the css vh value * @param {*} value * @returns {number} */ -const getVH = (value) => (value * Math.max(document.documentElement.clientHeight, window.innerHeight || 0)) / 100; -const getVW = (value) => (value * Math.max(document.documentElement.clientWidth, window.innerWidth || 0)) / 100; -const isScrollable = (element) => element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight; +export const getVH = (value) => (value * Math.max(document.documentElement.clientHeight, window.innerHeight || 0)) / 100; +export const getVW = (value) => (value * Math.max(document.documentElement.clientWidth, window.innerWidth || 0)) / 100; +export const isScrollable = (element) => element.scrollWidth > element.clientWidth || element.scrollHeight > element.clientHeight; + +/** + * @param {() => {}} code + * @returns {string} + */ +export const evalify = (code) => '(' + String(code) + ')()'; /** * @type {import('./utils/ctc.js').CrossTabCommunication} @@ -178,19 +184,9 @@ export default { }; export { - storage, - loadProxyWorker, - encoder, - redirect, - createViewPage, - isValidURL, - getVH, - getVW, - isScrollable, indexedDBExporter, EventEmitter, cookie, - uuid, CrossTabCommunication, PolarisError }; \ No newline at end of file diff --git a/static/index.html b/static/index.html index 90107fc..d563f25 100644 --- a/static/index.html +++ b/static/index.html @@ -39,15 +39,6 @@ Terms of Service

- -

Changelog

diff --git a/templates/ad_horizontal.html b/templates/ad_horizontal.html index c8be133..bf7fec6 100644 --- a/templates/ad_horizontal.html +++ b/templates/ad_horizontal.html @@ -1,4 +1,4 @@ -
+ + \ No newline at end of file diff --git a/templates/adtop.html b/templates/adtop.html index 02dc122..3fa97b9 100644 --- a/templates/adtop.html +++ b/templates/adtop.html @@ -1,2 +1,2 @@ - - + + \ No newline at end of file diff --git a/templates/analytics.html b/templates/analytics.html index a68b8b7..c4decd5 100644 --- a/templates/analytics.html +++ b/templates/analytics.html @@ -1,4 +1,3 @@ -