diff --git a/static/assets/js/apps.js b/static/assets/js/apps.js index 820e7e5..19f9560 100644 --- a/static/assets/js/apps.js +++ b/static/assets/js/apps.js @@ -1,4 +1,4 @@ -import { createViewPage } from './utils.js'; +import { createViewPage, isValidURL } from './utils.js'; import PolarisError from './error.js'; import effects from './effects.js'; @@ -21,7 +21,7 @@ const load = () => fetch('/assets/JSON/apps.json').then(res => res.json()).then( document.body.style.opacity = '0.7'; setTimeout(() => { - if (URL.canParse(app.target)) createViewPage({ + if (isValidURL(app.target)) createViewPage({ target: app.target, title: app.name, proxied: true diff --git a/static/assets/js/cheats.js b/static/assets/js/cheats.js index a421c14..6834db4 100644 --- a/static/assets/js/cheats.js +++ b/static/assets/js/cheats.js @@ -1,4 +1,4 @@ -import { createViewPage } from './utils.js'; +import { createViewPage, isValidURL } from './utils.js'; import PolarisError from './error.js'; import effects from './effects.js'; @@ -22,7 +22,7 @@ const load = () => fetch('/assets/JSON/cheats.json') document.body.style.opacity = '0.7'; setTimeout(() => { - if (URL.canParse(cheat.target)) createViewPage({ + if (isValidURL(cheat.target)) createViewPage({ target: cheat.target, title: cheat.name, proxied: true diff --git a/static/assets/js/games.js b/static/assets/js/games.js index 2ee009b..5e26a85 100644 --- a/static/assets/js/games.js +++ b/static/assets/js/games.js @@ -1,4 +1,4 @@ -import { createViewPage } from './utils.js'; +import { createViewPage, isValidURL } from './utils.js'; import PolarisError from './error.js'; import effects from './effects.js'; @@ -55,7 +55,7 @@ const load = () => { document.body.style.opacity = '0.7'; setTimeout(() => { - if (URL.canParse(game.target)) createViewPage({ + if (isValidURL(game.target)) createViewPage({ target: game.target, title: game.name, proxied: true @@ -80,7 +80,7 @@ const load = () => { document.body.style.opacity = '0.7'; setTimeout(() => { - if (URL.canParse(game.target)) createViewPage({ + if (isValidURL(game.target)) createViewPage({ target: game.target, title: game.name, proxied: true diff --git a/static/assets/js/inject.js b/static/assets/js/inject.js deleted file mode 100644 index e69de29..0000000 diff --git a/static/assets/js/main.js b/static/assets/js/main.js index 6e444fa..4e2dca2 100644 --- a/static/assets/js/main.js +++ b/static/assets/js/main.js @@ -1,5 +1,5 @@ import loadEasterEggs from './eastereggs.js'; -import { createViewPage } from './utils.js'; +import { createViewPage, isValidURL, getVH } from './utils.js'; import PolarisError from './error.js'; import Settings from './settings.js'; import Search from './search.js'; @@ -55,7 +55,7 @@ if (location.pathname === '/') { const game = games.filter(g => g.name === gameName)[0]; document.querySelector('.featured').addEventListener('click', () => { - if (URL.canParse(game.target)) createViewPage({ + if (isValidURL(game.target)) createViewPage({ target: game.target, title: game.name, proxied: true @@ -71,19 +71,36 @@ if (location.pathname === '/') { fetch('/assets/JSON/changelog.json') .then(res => res.json()) - .then(changelog => changelog - .filter((data, i) => !(i >= 3)) - .forEach(change => { - const date = document.createElement('p'); - date.textContent = change.date; - date.classList = 'small'; - document.querySelector('#changelog').appendChild(date); + .then(changelog => { + changelog + .filter((data, i) => !(i >= 3)) + .forEach(change => { + const log = document.createElement('div'); + document.querySelector('#changelog').appendChild(log); - const description = document.createElement('i'); - description.textContent = change.simpleDescription; - description.classList = 'small'; - document.querySelector('#changelog').appendChild(description); - })); + const date = document.createElement('p'); + date.textContent = change.date; + date.classList = 'small'; + log.appendChild(date); + + const description = document.createElement('i'); + description.textContent = change.simpleDescription; + description.classList = 'small'; + log.appendChild(description); + }); + + const updateChangelog = (amount = 3) => { + amount = amount - 1; + + for (let i = 0; i < document.querySelector('#changelog').children.length; i++) { + if (i > amount) document.querySelector('#changelog').children[i].classList.add('hidden'); + else document.querySelector('#changelog').children[i].classList.remove('hidden'); + } + } + + updateChangelog(!(getVH(100) - getVH(69) > document.querySelector('#changelog').clientHeight) ? 2 : 3); + window.onresize = () => updateChangelog(!(getVH(100) - getVH(69) > document.querySelector('#changelog').clientHeight) ? 2 : 3); + }); } if (window.self === window.top && location.pathname !== '/view') { diff --git a/static/assets/js/search.js b/static/assets/js/search.js index 6817eb4..ef45079 100644 --- a/static/assets/js/search.js +++ b/static/assets/js/search.js @@ -1,4 +1,4 @@ -import { createViewPage } from './utils.js'; +import { createViewPage, isValidURL } from './utils.js'; const load = () => { const form = document.querySelector('#wpf'); @@ -7,7 +7,7 @@ const load = () => { form.addEventListener('submit', async (e) => { e.preventDefault(); - const url = /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/.test(query.value) ? ((!query.value.startsWith('http://') && !query.value.startsWith('https://')) ? 'https://' + query.value : query.value) : 'https://www.google.com/search?q=' + encodeURIComponent(query.value); + const url = isValidURL(query.value) ? ((!query.value.startsWith('http://') && !query.value.startsWith('https://')) ? 'https://' + query.value : query.value) : 'https://www.google.com/search?q=' + encodeURIComponent(query.value); document.body.style.opacity = '0.7'; diff --git a/static/assets/js/utils.js b/static/assets/js/utils.js index 8dbce13..c2bbcab 100644 --- a/static/assets/js/utils.js +++ b/static/assets/js/utils.js @@ -124,12 +124,25 @@ const createViewPage = (options) => location.href = `/view?load=${btoa(JSON.stri title: options.title }))}`; +/** + * Check if a url is valid + * @param {string} url + * @returns {boolean} + */ +const isValidURL = (url) => /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/.test(url); + +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; + export default { storage, loadProxyWorker, encoder, redirect, - createViewPage + createViewPage, + isValidURL, + getVH, + getVW }; export { @@ -137,5 +150,8 @@ export { loadProxyWorker, encoder, redirect, - createViewPage + createViewPage, + isValidURL, + getVH, + getVW }; \ No newline at end of file