diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..b0498d58 --- /dev/null +++ b/.babelrc @@ -0,0 +1,9 @@ +{ + "presets": [ + ["env", { + "targets": { + "browsers": ["defaults"] + } + }] + ] +} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..4f7cc892 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,38 @@ +module.exports = { + "env": { + "browser": true, + "es6": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 2018 + }, + "rules": { + "indent": [ + "error", + 2, + { + "SwitchCase": 1, + }, + ], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "single"], + "semi": ["error", "always"], + "eqeqeq": ["error", "always"], + "dot-location": ["error", "property"], + "dot-notation": ["warn"], + "no-else-return": ["warn"], + "no-var": ["error"], + "arrow-body-style": ["warn"], + "object-shorthand": ["warn"], + "prefer-arrow-callback": ["warn"], + "prefer-const": ["warn"], + "prefer-template": ["warn"], + "comma-dangle": ["error", "always-multiline"], + "array-bracket-newline": ["warn", "consistent"], + "array-bracket-spacing": ["warn", "never"], + "block-spacing": ["warn", "always"], + "brace-style": ["warn", "1tbs"], + "camelcase": ["warn"] + } +}; diff --git a/.gitattributes b/.gitattributes index 77526552..adf891b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,5 +10,8 @@ webserver/web/static/css/*/* linguist-vendored # vendored js files are in separate subdirectories webserver/web/static/js/*/* linguist-vendored +# generated js files are in js root +webserver/web/static/js/* linguist-generated + # linguist detects these as RenderScript, but they're Rust webserver/src/models/id/*.rs linguist-language=Rust diff --git a/.gitignore b/.gitignore index 8e8c7665..b5f023a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ /target **/*.rs.bk +/node_modules +/package-lock.json + /Rocket.toml /config.toml /.env diff --git a/webserver/Cargo.toml b/webserver/Cargo.toml index f801f7ce..094d03ad 100644 --- a/webserver/Cargo.toml +++ b/webserver/Cargo.toml @@ -5,6 +5,14 @@ authors = ["Kyle Clemens "] build = "build.rs" +exclude = [ + # pls + # "web/", + # "migrations/", + "web/**/*", + "migrations/**/*", +] + [badges] travis-ci = { repository = "jkcclemens/paste", branch = "master" } maintenance = { status = "actively-developed" } diff --git a/webserver/web/src/js/editor.js b/webserver/web/src/js/editor.js new file mode 100644 index 00000000..cd8c86e5 --- /dev/null +++ b/webserver/web/src/js/editor.js @@ -0,0 +1,191 @@ +/* global hljs:false, CodeSass:false */ + +let pasteNum = 0; +const pasteEditors = {}; + +(function() { + /** + * Create the upload array for handling multiple files. + */ + function createUpload() { + function getLanguage(parent) { + const lang = parent.querySelector('select[name=file_language]').value; + if (lang === '') { + return null; + } + return lang; + } + + const files = []; + for (const editor of Object.values(pasteEditors)) { + const parent = editor.editorRoot.parentElement.parentElement.parentElement; + const file = { + 'name': parent.querySelector('input[name=file_name]').value, + 'language': getLanguage(parent), + 'content': editor.getCode(), + }; + const id = editor.editorRoot.parentElement.parentElement.parentElement.querySelector('input[name=id]'); + if (id !== null) { + file.id = id.value; + } + files.push(file); + } + return files; + } + + function codeFlaskSucksHighlight(editor) { + hljs.highlightBlock(editor.elCode); + // remove the extra classes hljs adds without asking + for (const clazz of editor.elCode.classList) { + if (clazz !== 'hljs' && clazz !== 'codeflask__code' && !clazz.startsWith('language-')) { + editor.elCode.classList.remove(clazz); + } + } + } + + /** + * Create an editor. + * + * @param {HTMLElement} parent The file container. + * @param {HTMLElement} el The element to convert into an editor. + */ + function setUpEditor(parent, el) { + const div = document.createElement('div'); + + div.style.height = '400px'; + + const editor = new CodeSass(div, { + defaultTheme: false, + lineNumbers: true, + language: 'plaintext', + }); + + const hidden = document.createElement('input'); + hidden.type = 'hidden'; + hidden.name = 'file_content'; + hidden.id = 'hidden_content'; + editor.editorRoot.insertAdjacentElement('afterend', hidden); + + editor.elCode.style.background = 'none'; + editor.elCode.style.padding = '0'; + + editor.setHighlightCallback(codeFlaskSucksHighlight); + + const nameInput = parent.querySelector('input[name=file_name]'); + const langInput = parent.querySelector('select[name=file_language]'); + + function updateLanguage() { + let suffix; + if (langInput.value !== '') { + suffix = langInput.value; + } else if (nameInput.value !== '') { + suffix = nameInput.value.split('.').pop(); + } + const lang = hljs.getLanguage(suffix) !== undefined ? suffix : 'plaintext'; + editor.updateLanguage(lang); + editor.updateCode(editor.code); + } + + nameInput.addEventListener('input', updateLanguage); + langInput.addEventListener('change', updateLanguage); + + updateLanguage(); + editor.updateCode(el.value); + editor.createLineNumbers(); // TODO: fix this in codesass + + const toDelete = pasteNum; + parent + .querySelector('button[name=delete_button]') + .addEventListener('click', () => removeFile(toDelete)); + + pasteEditors[pasteNum] = editor; + + el.insertAdjacentElement('beforebegin', div); + el.remove(); + } + + function addFile() { + // get the base file for cloning (should be invisible if JS is running) + const base = document.getElementById('base_file'); + + // deep clone the base + const clone = base.cloneNode(true); + + // show the editor by removing the requires-no-js class that was on the base + clone.classList.remove('requires-no-js'); + + pasteNum += 1; + clone.id = `file${pasteNum}`; + + // set up an editor for each textarea in the base (should only be one) + for (const ta of clone.getElementsByTagName('textarea')) { + setUpEditor(clone, ta); + } + + // add the editor to the dom + document.getElementById('end_of_files').insertAdjacentElement('beforebegin', clone); + + updateButtons(); + } + + /** + * Remove a file. Will never remove the last file. + * + * @param {Number} num The number of the file to remove. + */ + function removeFile(num) { + if (Object.keys(pasteEditors).length === 1) { + return; + } + + const file = document.getElementById(`file${num}`); + + if (file === null) { + return; + } + + delete pasteEditors[num]; + + file.remove(); + + updateButtons(); + } + + function updateButtons() { + const enabled = Object.keys(pasteEditors).length > 1; + for (const button of document.getElementsByName('delete_button')) { + if (enabled) { + button.disabled = false; + } else { + button.disabled = true; + } + } + } + + function createEditors() { + for (const editor of document.querySelectorAll('textarea.editor')) { + pasteNum += 1; + setUpEditor(editor.parentElement.parentElement.parentElement, editor); + } + updateButtons(); + } + + document.getElementById('add_file').addEventListener('click', addFile); + + document.getElementById('paste_upload').addEventListener('submit', e => { + const input = document.createElement('input'); + input.type = 'hidden'; + input.value = JSON.stringify(createUpload()); + input.name = 'upload_json'; + + e.target.appendChild(input); + }); + + // create any initial editors + createEditors(); + + // add an initial file if necessary + if (Object.keys(pasteEditors).length === 0) { + addFile(); + } +})(); diff --git a/webserver/web/src/js/highlight.js b/webserver/web/src/js/highlight.js new file mode 100644 index 00000000..b66f7a4d --- /dev/null +++ b/webserver/web/src/js/highlight.js @@ -0,0 +1,45 @@ +/* global hljs */ + +(function() { + for (const pre of document.getElementsByTagName('pre')) { + (function() { + if (pre.id === '') { + return; + } + const title = document.getElementById(`${pre.id}-title`); + if (title === null) { + return; + } + let suffix; + if (pre.lang) { + suffix = pre.lang; + } else { + suffix = title.innerText.trim().split('.').pop(); + } + const classes = []; + if (hljs.getLanguage(suffix) === undefined) { + classes.push('no-highlight'); + classes.push('hljs'); + } else { + classes.push(`language-${suffix}`); + } + for (const clazz of classes) { + pre.classList.add(clazz); + } + })(); + + const cont = [...pre.classList].some(e => e === 'hljs' || e.startsWith('language-')); + + if (!cont) { + continue; + } + + hljs.highlightBlock(pre); + + if (pre.classList.contains('file-source')) { + hljs.lineNumbersBlock(pre, { + singleLine: true, + }); + } + } +})(); diff --git a/webserver/web/src/js/navbar.js b/webserver/web/src/js/navbar.js new file mode 100644 index 00000000..0016571d --- /dev/null +++ b/webserver/web/src/js/navbar.js @@ -0,0 +1,22 @@ +(function() { + document.addEventListener('DOMContentLoaded', () => { + // Get all "navbar-burger" elements + const navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); + + // Check if there are any navbar burgers + if (navbarBurgers.length > 0) { + // Add a click event on each of them + navbarBurgers.forEach(el => { + el.addEventListener('click', () => { + // Get the target from the "data-target" attribute + const targetId = el.dataset.target; + const target = document.getElementById(targetId); + + // Toggle the class on both the "navbar-burger" and the "navbar-menu" + el.classList.toggle('is-active'); + target.classList.toggle('is-active'); + }); + }); + } + }); +})(); diff --git a/webserver/web/src/js/notifications.js b/webserver/web/src/js/notifications.js new file mode 100644 index 00000000..4cdaf8b4 --- /dev/null +++ b/webserver/web/src/js/notifications.js @@ -0,0 +1,8 @@ +(function() { + for (const button of document.querySelectorAll('.message > .message-header > .delete')) { + button.addEventListener('click', () => this.parentElement.parentElement.remove()); + } + for (const button of document.querySelectorAll('.notification > .delete')) { + button.addEventListener('click', () => this.parentElement.remove()); + } +})(); diff --git a/webserver/web/src/js/password.js b/webserver/web/src/js/password.js new file mode 100644 index 00000000..6b47d12f --- /dev/null +++ b/webserver/web/src/js/password.js @@ -0,0 +1,95 @@ +/* global zxcvbn */ + +(function() { + function checkMatch(pw, verify) { + if (pw.value === verify.value && pw.value.length !== 0) { + verify.classList.add('is-success'); + } else { + verify.classList.remove('is-success'); + } + } + + document + .getElementById('password_verify') + .addEventListener('input', () => checkMatch(document.getElementById('password'), this)); + + function doHides(pw, strength) { + if (pw.value.length === 0) { + strength.classList.add('is-not-displayed'); + } else { + strength.classList.remove('is-not-displayed'); + } + } + + function passwordStrength(pw) { + checkMatch(pw, document.getElementById('password_verify')); + + const values = []; + { + const name = document.getElementById('name'); + if (name) { + values.push(name.value); + } + const username = document.getElementById('username'); + if (username) { + values.push(username.value); + } + const email = document.getElementById('email'); + if (email) { + values.push(email.value); + } + } + + const password = pw.value; + const strength = document.getElementById('strength'); + const progress = document.getElementById('strength_progress'); + const warning = document.getElementById('strength_warning'); + + if (pw.getAttribute('data-bar') === 'hidden') { + doHides(pw, progress); + } + + if (password.length === 0) { + strength.innerHTML = ''; + warning.innerHTML = ''; + progress.classList.add('is-danger'); + progress.classList.remove('is-warning'); + progress.classList.remove('is-success'); + return; + } + + const z = zxcvbn(password, values); + + let message = `Time to crack your password: ${z.crack_times_display.offline_slow_hashing_1e4_per_second}`; + message += ' What is this?'; + strength.innerHTML = message; + + warning.innerHTML = `
${z.feedback.warning}`; + + let color; + switch (z.score) { + case 0: + color = 'is-danger'; + break; + case 1: + color = 'is-danger'; + break; + case 2: + color = 'is-warning'; + break; + case 3: + color = 'is-warning'; + break; + case 4: + color = 'is-success'; + break; + } + + progress.classList.remove('is-danger'); + progress.classList.remove('is-warning'); + progress.classList.remove('is-success'); + progress.classList.add(color); + } + + document.getElementById('password').addEventListener('input', () => passwordStrength(this)); +})(); diff --git a/webserver/web/src/js/paste.js b/webserver/web/src/js/paste.js new file mode 100644 index 00000000..2aaff0a7 --- /dev/null +++ b/webserver/web/src/js/paste.js @@ -0,0 +1,127 @@ +(function() { + function openModal() { + document.getElementById('deletion_modal').classList.add('is-active'); + } + + function closeModal() { + document.getElementById('deletion_modal').classList.remove('is-active'); + } + + [...document.getElementsByClassName('opens-modal')].forEach(e => e.addEventListener('click', openModal)); + + [...document.getElementsByClassName('closes-modal')].forEach(e => e.addEventListener('click', closeModal)); + + function swap(current, currentContent, next, nextContent) { + current.classList.remove('is-active'); + next.classList.add('is-active'); + + currentContent.classList.add('is-not-displayed'); + nextContent.classList.remove('is-not-displayed'); + } + + for (const tabsContainer of document.getElementsByClassName('paste-tabs-container')) { + const fileId = tabsContainer.dataset.id; + const tabLinks = document.getElementById(`${fileId}-tab-links`); + + const rendered = tabLinks.querySelector('.paste-rendered-tab'); + const renderedA = rendered.firstChild; + + const source = tabLinks.querySelector('.paste-source-tab'); + const sourceA = source.firstChild; + + const renderedContent = tabsContainer.querySelector('div.paste-rendered-content'); + const sourceContent = tabsContainer.querySelector('div.paste-source-content'); + + renderedA.addEventListener('click', () => swap(source, sourceContent, rendered, renderedContent)); + sourceA.addEventListener('click', () => swap(rendered, renderedContent, source, sourceContent)); + } + + function getDeletionKeys() { + let keys = localStorage.getItem('deletion_keys'); + + if (keys === null) { + keys = {}; + } else { + keys = JSON.parse(keys); + } + + return keys; + } + + function setDeletionKeys(keys) { + localStorage.setItem('deletion_keys', JSON.stringify(keys)); + } + + // check if the page is displaying a deletion key and add it to local storage + (function() { + const dkElem = document.getElementById('deletion_key'); + + if (dkElem === null) { + return; + } + + const deletionKey = dkElem.innerText; + + const keys = getDeletionKeys(); + + const pasteId = dkElem.dataset.pasteId; + + keys[pasteId] = { + deletionKey, + expires: new Date((new Date).getTime() + (30 * 24 * 60 * 60 * 1000)), + }; + + setDeletionKeys(keys); + })(); + + // check if we have a deletion key for this paste and insert it + (function() { + const dkInput = document.getElementById('deletion_key_input'); + + if (dkInput === null) { + return; + } + + const pasteId = dkInput.dataset.pasteId; + + const keys = getDeletionKeys(); + + const key = keys[pasteId]; + + if (key === undefined) { + return; + } + + dkInput.value = key.deletion_key; + + // add a listener for form submit to remove key from local storage + const deletionForm = document.getElementById('deletion_form'); + + if (deletionForm === null) { + return; + } + + deletionForm.addEventListener('submit', () => { + const keys = getDeletionKeys(); + delete keys[pasteId]; + setDeletionKeys(keys); + }); + })(); + + // expire old deletion keys + (function() { + const keys = getDeletionKeys(); + + for (const key of Object.entries(keys)) { + if ((new Date) >= new Date(key[1].expires)) { + delete keys[key[0]]; + } + } + + setDeletionKeys(keys); + })(); + + document + .querySelectorAll('.paste-rendered-content pre[lang]') + .forEach(pre => pre.classList.add(`language-${pre.lang}`)); +})(); diff --git a/webserver/web/src/js/register.js b/webserver/web/src/js/register.js new file mode 100644 index 00000000..d50f7487 --- /dev/null +++ b/webserver/web/src/js/register.js @@ -0,0 +1,10 @@ +(function() { + if (localStorage.getItem('style') === 'dark') { + document.getElementById('submit_button').setAttribute('data-theme', 'dark'); + } +})(); + +// eslint-disable-next-line no-unused-vars +function submitRegistration() { + document.getElementById('registration_form').submit(); +} diff --git a/webserver/web/src/js/style.js b/webserver/web/src/js/style.js new file mode 100644 index 00000000..775fa8d2 --- /dev/null +++ b/webserver/web/src/js/style.js @@ -0,0 +1,60 @@ +(function() { + function setActiveStyleSheet(title) { + for (const a of document.getElementsByTagName('link')) { + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title')) { + a.disabled = true; + if (a.getAttribute('title') === title) { + a.disabled = false; + } + } + } + localStorage.setItem('style', getActiveStyleSheet()); + } + + function getActiveStyleSheet() { + for (const a of document.getElementsByTagName('link')) { + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title') && !a.disabled) { + return a.getAttribute('title'); + } + } + return null; + } + + function getPreferredStyleSheet() { + for (const a of document.getElementsByTagName('link')) { + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('rel').indexOf('alt') === -1 && a.getAttribute('title')) { + return a.getAttribute('title'); + } + } + return null; + } + + function swapTheme() { + let next; + if (getActiveStyleSheet() === 'dark') { + next = 'light'; + } else { + next = 'dark'; + } + setActiveStyleSheet(next); + } + + function loadSheet() { + const style = localStorage.getItem('style'); + const title = style ? style : getPreferredStyleSheet(); + setActiveStyleSheet(title); + } + + window.addEventListener('load', () => { + loadSheet(); + + document.getElementById('swap_theme').addEventListener('click', swapTheme); + }); + + window.addEventListener('unload', function() { + const title = getActiveStyleSheet(); + this.localStorage.setItem('style', title); + }); + + loadSheet(); +})(); diff --git a/webserver/web/src/js/timestamps.js b/webserver/web/src/js/timestamps.js new file mode 100644 index 00000000..024a2325 --- /dev/null +++ b/webserver/web/src/js/timestamps.js @@ -0,0 +1,31 @@ +/* global moment */ + +(function() { + function updateTime(elem) { + const ts = elem.dataset.timestamp; + if (ts === undefined) { + return; + } + + const m = moment.utc(ts).local(); + + elem.innerHTML = m.fromNow(); + elem.title = m.format('LLL'); + } + + function updateAllTimes() { + for (const ts of document.getElementsByClassName('timestamp')) { + updateTime(ts); + } + } + + (function() { + if (navigator.languages) { + moment.locale(navigator.languages); + } + + updateAllTimes(); + + setInterval(updateAllTimes, 60 * 1000); + })(); +})(); diff --git a/webserver/web/static/js/editor.js b/webserver/web/static/js/editor.js index 4b7d4b5e..0ab2e3d9 100644 --- a/webserver/web/static/js/editor.js +++ b/webserver/web/static/js/editor.js @@ -1,13 +1,17 @@ -var paste_num = 0; -var paste_editors = {}; +'use strict'; -(function() { +/* global hljs:false, CodeSass:false */ + +var pasteNum = 0; +var pasteEditors = {}; + +(function () { /** * Create the upload array for handling multiple files. */ function createUpload() { function getLanguage(parent) { - const lang = parent.querySelector('select[name=file_language]').value; + var lang = parent.querySelector('select[name=file_language]').value; if (lang === '') { return null; } @@ -15,28 +19,71 @@ var paste_editors = {}; } var files = []; - for (const editor of Object.values(paste_editors)) { - const parent = editor.editorRoot.parentElement.parentElement.parentElement; - const file = { - 'name': parent.querySelector('input[name=file_name]').value, - 'language': getLanguage(parent), - 'content': editor.getCode(), - }; - const id = editor.editorRoot.parentElement.parentElement.parentElement.querySelector('input[name=id]'); - if (id !== null) { - file['id'] = id.value; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = Object.values(pasteEditors)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var editor = _step.value; + + var parent = editor.editorRoot.parentElement.parentElement.parentElement; + var file = { + 'name': parent.querySelector('input[name=file_name]').value, + 'language': getLanguage(parent), + 'content': editor.getCode() + }; + var id = editor.editorRoot.parentElement.parentElement.parentElement.querySelector('input[name=id]'); + if (id !== null) { + file.id = id.value; + } + files.push(file); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } - files.push(file); } + return files; } function codeFlaskSucksHighlight(editor) { hljs.highlightBlock(editor.elCode); // remove the extra classes hljs adds without asking - for (const clazz of editor.elCode.classList) { - if (clazz !== 'hljs' && clazz !== 'codeflask__code' && !clazz.startsWith('language-')) { - editor.elCode.classList.remove(clazz); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = editor.elCode.classList[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var clazz = _step2.value; + + if (clazz !== 'hljs' && clazz !== 'codeflask__code' && !clazz.startsWith('language-')) { + editor.elCode.classList.remove(clazz); + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } } @@ -48,17 +95,17 @@ var paste_editors = {}; * @param {HTMLElement} el The element to convert into an editor. */ function setUpEditor(parent, el) { - const div = document.createElement('div'); + var div = document.createElement('div'); div.style.height = '400px'; - const editor = new CodeSass(div, { + var editor = new CodeSass(div, { defaultTheme: false, lineNumbers: true, - language: 'plaintext', + language: 'plaintext' }); - const hidden = document.createElement('input'); + var hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = 'file_content'; hidden.id = 'hidden_content'; @@ -67,38 +114,36 @@ var paste_editors = {}; editor.elCode.style.background = 'none'; editor.elCode.style.padding = '0'; - editor.setHighlightCallback(function(ed) { - codeFlaskSucksHighlight(ed); - }); + editor.setHighlightCallback(codeFlaskSucksHighlight); - const name_input = parent.querySelector('input[name=file_name]'); - const lang_input = parent.querySelector('select[name=file_language]'); + var nameInput = parent.querySelector('input[name=file_name]'); + var langInput = parent.querySelector('select[name=file_language]'); function updateLanguage() { - var suffix; - if (lang_input.value !== '') { - suffix = lang_input.value; - } else if (name_input.value !== '') { - suffix = name_input.value.split('.').pop(); + var suffix = void 0; + if (langInput.value !== '') { + suffix = langInput.value; + } else if (nameInput.value !== '') { + suffix = nameInput.value.split('.').pop(); } - const lang = hljs.getLanguage(suffix) !== undefined ? suffix : 'plaintext'; + var lang = hljs.getLanguage(suffix) !== undefined ? suffix : 'plaintext'; editor.updateLanguage(lang); editor.updateCode(editor.code); } - name_input.addEventListener('input', updateLanguage); - lang_input.addEventListener('change', updateLanguage); + nameInput.addEventListener('input', updateLanguage); + langInput.addEventListener('change', updateLanguage); updateLanguage(); editor.updateCode(el.value); editor.createLineNumbers(); // TODO: fix this in codesass - const to_delete = paste_num; - parent.querySelector('button[name=delete_button]').addEventListener('click', function() { - removeFile(to_delete); + var toDelete = pasteNum; + parent.querySelector('button[name=delete_button]').addEventListener('click', function () { + return removeFile(toDelete); }); - paste_editors[paste_num] = editor; + pasteEditors[pasteNum] = editor; el.insertAdjacentElement('beforebegin', div); el.remove(); @@ -106,23 +151,45 @@ var paste_editors = {}; function addFile() { // get the base file for cloning (should be invisible if JS is running) - const base = document.getElementById('base_file'); + var base = document.getElementById('base_file'); // deep clone the base - const clone = base.cloneNode(true); + var clone = base.cloneNode(true); // show the editor by removing the requires-no-js class that was on the base clone.classList.remove('requires-no-js'); - paste_num += 1; - clone.id = 'file' + paste_num; + pasteNum += 1; + clone.id = 'file' + pasteNum; // set up an editor for each textarea in the base (should only be one) - for (const ta of clone.getElementsByTagName('textarea')) { - setUpEditor(clone, ta); + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = clone.getElementsByTagName('textarea')[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var ta = _step3.value; + + setUpEditor(clone, ta); + } + + // add the editor to the dom + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } } - // add the editor to the dom document.getElementById('end_of_files').insertAdjacentElement('beforebegin', clone); updateButtons(); @@ -134,17 +201,17 @@ var paste_editors = {}; * @param {Number} num The number of the file to remove. */ function removeFile(num) { - if (Object.keys(paste_editors).length === 1) { + if (Object.keys(pasteEditors).length === 1) { return; } - const file = document.getElementById('file' + num); + var file = document.getElementById('file' + num); if (file === null) { return; } - delete paste_editors[num]; + delete pasteEditors[num]; file.remove(); @@ -152,40 +219,84 @@ var paste_editors = {}; } function updateButtons() { - const enabled = Object.keys(paste_editors).length > 1; - for (const button of document.getElementsByName('delete_button')) { - if (enabled) { - button.disabled = false; - } else { - button.disabled = true; + var enabled = Object.keys(pasteEditors).length > 1; + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = document.getElementsByName('delete_button')[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var button = _step4.value; + + if (enabled) { + button.disabled = false; + } else { + button.disabled = true; + } + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } } } } function createEditors() { - for (const editor of document.querySelectorAll('textarea.editor')) { - paste_num += 1; - setUpEditor(editor.parentElement.parentElement.parentElement, editor); + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = document.querySelectorAll('textarea.editor')[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var editor = _step5.value; + + pasteNum += 1; + setUpEditor(editor.parentElement.parentElement.parentElement, editor); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } } + updateButtons(); } document.getElementById('add_file').addEventListener('click', addFile); - document.getElementById('paste_upload').addEventListener('submit', function() { - const input = document.createElement('input'); + document.getElementById('paste_upload').addEventListener('submit', function (e) { + var input = document.createElement('input'); input.type = 'hidden'; input.value = JSON.stringify(createUpload()); input.name = 'upload_json'; - this.appendChild(input); + e.target.appendChild(input); }); // create any initial editors createEditors(); // add an initial file if necessary - if (Object.keys(paste_editors).length === 0) { + if (Object.keys(pasteEditors).length === 0) { addFile(); } })(); +//# sourceMappingURL=editor.js.map \ No newline at end of file diff --git a/webserver/web/static/js/editor.js.map b/webserver/web/static/js/editor.js.map new file mode 100644 index 00000000..1dc11971 --- /dev/null +++ b/webserver/web/static/js/editor.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/editor.js"],"names":["pasteNum","pasteEditors","createUpload","getLanguage","parent","lang","querySelector","value","files","Object","values","editor","editorRoot","parentElement","file","getCode","id","push","codeFlaskSucksHighlight","hljs","highlightBlock","elCode","classList","clazz","startsWith","remove","setUpEditor","el","div","document","createElement","style","height","CodeSass","defaultTheme","lineNumbers","language","hidden","type","name","insertAdjacentElement","background","padding","setHighlightCallback","nameInput","langInput","updateLanguage","suffix","split","pop","undefined","updateCode","code","addEventListener","createLineNumbers","toDelete","removeFile","addFile","base","getElementById","clone","cloneNode","getElementsByTagName","ta","updateButtons","num","keys","length","enabled","getElementsByName","button","disabled","createEditors","querySelectorAll","input","JSON","stringify","e","target","appendChild"],"mappings":";;AAAA;;AAEA,IAAIA,WAAW,CAAf;AACA,IAAMC,eAAe,EAArB;;AAEA,CAAC,YAAW;AACV;;;AAGA,WAASC,YAAT,GAAwB;AACtB,aAASC,WAAT,CAAqBC,MAArB,EAA6B;AAC3B,UAAMC,OAAOD,OAAOE,aAAP,CAAqB,4BAArB,EAAmDC,KAAhE;AACA,UAAIF,SAAS,EAAb,EAAiB;AACf,eAAO,IAAP;AACD;AACD,aAAOA,IAAP;AACD;;AAED,QAAMG,QAAQ,EAAd;AATsB;AAAA;AAAA;;AAAA;AAUtB,2BAAqBC,OAAOC,MAAP,CAAcT,YAAd,CAArB,8HAAkD;AAAA,YAAvCU,MAAuC;;AAChD,YAAMP,SAASO,OAAOC,UAAP,CAAkBC,aAAlB,CAAgCA,aAAhC,CAA8CA,aAA7D;AACA,YAAMC,OAAO;AACX,kBAAQV,OAAOE,aAAP,CAAqB,uBAArB,EAA8CC,KAD3C;AAEX,sBAAYJ,YAAYC,MAAZ,CAFD;AAGX,qBAAWO,OAAOI,OAAP;AAHA,SAAb;AAKA,YAAMC,KAAKL,OAAOC,UAAP,CAAkBC,aAAlB,CAAgCA,aAAhC,CAA8CA,aAA9C,CAA4DP,aAA5D,CA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BAAOC,QAAP,GAAkB,IAAlB;AACD;AACF;AARsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASxB;;AAED,WAASC,aAAT,GAAyB;AAAA;AAAA;AAAA;;AAAA;AACvB,4BAAqB3C,SAAS4C,gBAAT,CAA0B,iBAA1B,CAArB,mIAAmE;AAAA,YAAxD9D,MAAwD;;AACjEX,oBAAY,CAAZ;AACA0B,oBAAYf,OAAOE,aAAP,CAAqBA,aAArB,CAAmCA,aAA/C,EAA8DF,MAA9D;AACD;AAJsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAKvBqD;AACD;;AAEDnC,WAAS8B,cAAT,CAAwB,UAAxB,EAAoCN,gBAApC,CAAqD,OAArD,EAA8DI,OAA9D;;AAEA5B,WAAS8B,cAAT,CAAwB,cAAxB,EAAwCN,gBAAxC,CAAyD,QAAzD,EAAmE,aAAK;AACtE,QAAMqB,QAAQ7C,SAASC,aAAT,CAAuB,OAAvB,CAAd;AACA4C,UAAMpC,IAAN,GAAa,QAAb;AACAoC,UAAMnE,KAAN,GAAcoE,KAAKC,SAAL,CAAe1E,cAAf,CAAd;AACAwE,UAAMnC,IAAN,GAAa,aAAb;;AAEAsC,MAAEC,MAAF,CAASC,WAAT,CAAqBL,KAArB;AACD,GAPD;;AASA;AACAF;;AAEA;AACA,MAAI/D,OAAOyD,IAAP,CAAYjE,YAAZ,EAA0BkE,MAA1B,KAAqC,CAAzC,EAA4C;AAC1CV;AACD;AACF,CAzLD","file":"editor.js","sourcesContent":["/* global hljs:false, CodeSass:false */\n\nlet pasteNum = 0;\nconst pasteEditors = {};\n\n(function() {\n /**\n * Create the upload array for handling multiple files.\n */\n function createUpload() {\n function getLanguage(parent) {\n const lang = parent.querySelector('select[name=file_language]').value;\n if (lang === '') {\n return null;\n }\n return lang;\n }\n\n const files = [];\n for (const editor of Object.values(pasteEditors)) {\n const parent = editor.editorRoot.parentElement.parentElement.parentElement;\n const file = {\n 'name': parent.querySelector('input[name=file_name]').value,\n 'language': getLanguage(parent),\n 'content': editor.getCode(),\n };\n const id = editor.editorRoot.parentElement.parentElement.parentElement.querySelector('input[name=id]');\n if (id !== null) {\n file.id = id.value;\n }\n files.push(file);\n }\n return files;\n }\n\n function codeFlaskSucksHighlight(editor) {\n hljs.highlightBlock(editor.elCode);\n // remove the extra classes hljs adds without asking\n for (const clazz of editor.elCode.classList) {\n if (clazz !== 'hljs' && clazz !== 'codeflask__code' && !clazz.startsWith('language-')) {\n editor.elCode.classList.remove(clazz);\n }\n }\n }\n\n /**\n * Create an editor.\n *\n * @param {HTMLElement} parent The file container.\n * @param {HTMLElement} el The element to convert into an editor.\n */\n function setUpEditor(parent, el) {\n const div = document.createElement('div');\n\n div.style.height = '400px';\n\n const editor = new CodeSass(div, {\n defaultTheme: false,\n lineNumbers: true,\n language: 'plaintext',\n });\n\n const hidden = document.createElement('input');\n hidden.type = 'hidden';\n hidden.name = 'file_content';\n hidden.id = 'hidden_content';\n editor.editorRoot.insertAdjacentElement('afterend', hidden);\n\n editor.elCode.style.background = 'none';\n editor.elCode.style.padding = '0';\n\n editor.setHighlightCallback(codeFlaskSucksHighlight);\n\n const nameInput = parent.querySelector('input[name=file_name]');\n const langInput = parent.querySelector('select[name=file_language]');\n\n function updateLanguage() {\n let suffix;\n if (langInput.value !== '') {\n suffix = langInput.value;\n } else if (nameInput.value !== '') {\n suffix = nameInput.value.split('.').pop();\n }\n const lang = hljs.getLanguage(suffix) !== undefined ? suffix : 'plaintext';\n editor.updateLanguage(lang);\n editor.updateCode(editor.code);\n }\n\n nameInput.addEventListener('input', updateLanguage);\n langInput.addEventListener('change', updateLanguage);\n\n updateLanguage();\n editor.updateCode(el.value);\n editor.createLineNumbers(); // TODO: fix this in codesass\n\n const toDelete = pasteNum;\n parent\n .querySelector('button[name=delete_button]')\n .addEventListener('click', () => removeFile(toDelete));\n\n pasteEditors[pasteNum] = editor;\n\n el.insertAdjacentElement('beforebegin', div);\n el.remove();\n }\n\n function addFile() {\n // get the base file for cloning (should be invisible if JS is running)\n const base = document.getElementById('base_file');\n\n // deep clone the base\n const clone = base.cloneNode(true);\n\n // show the editor by removing the requires-no-js class that was on the base\n clone.classList.remove('requires-no-js');\n\n pasteNum += 1;\n clone.id = `file${pasteNum}`;\n\n // set up an editor for each textarea in the base (should only be one)\n for (const ta of clone.getElementsByTagName('textarea')) {\n setUpEditor(clone, ta);\n }\n\n // add the editor to the dom\n document.getElementById('end_of_files').insertAdjacentElement('beforebegin', clone);\n\n updateButtons();\n }\n\n /**\n * Remove a file. Will never remove the last file.\n *\n * @param {Number} num The number of the file to remove.\n */\n function removeFile(num) {\n if (Object.keys(pasteEditors).length === 1) {\n return;\n }\n\n const file = document.getElementById(`file${num}`);\n\n if (file === null) {\n return;\n }\n\n delete pasteEditors[num];\n\n file.remove();\n\n updateButtons();\n }\n\n function updateButtons() {\n const enabled = Object.keys(pasteEditors).length > 1;\n for (const button of document.getElementsByName('delete_button')) {\n if (enabled) {\n button.disabled = false;\n } else {\n button.disabled = true;\n }\n }\n }\n\n function createEditors() {\n for (const editor of document.querySelectorAll('textarea.editor')) {\n pasteNum += 1;\n setUpEditor(editor.parentElement.parentElement.parentElement, editor);\n }\n updateButtons();\n }\n\n document.getElementById('add_file').addEventListener('click', addFile);\n\n document.getElementById('paste_upload').addEventListener('submit', e => {\n const input = document.createElement('input');\n input.type = 'hidden';\n input.value = JSON.stringify(createUpload());\n input.name = 'upload_json';\n\n e.target.appendChild(input);\n });\n\n // create any initial editors\n createEditors();\n\n // add an initial file if necessary\n if (Object.keys(pasteEditors).length === 0) {\n addFile();\n }\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/highlight.js b/webserver/web/static/js/highlight.js index e8613c5e..c3806d03 100644 --- a/webserver/web/static/js/highlight.js +++ b/webserver/web/static/js/highlight.js @@ -1,45 +1,100 @@ -(function() { - for (const pre of document.getElementsByTagName('pre')) { - (function() { +'use strict'; + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +/* global hljs */ + +(function () { + var _loop = function _loop(pre) { + (function () { if (pre.id === '') { return; } - const title = document.getElementById(pre.id + '-title'); + var title = document.getElementById(pre.id + '-title'); if (title === null) { return; } - var suffix; + var suffix = void 0; if (pre.lang) { suffix = pre.lang; } else { suffix = title.innerText.trim().split('.').pop(); } - const classes = []; + var classes = []; if (hljs.getLanguage(suffix) === undefined) { classes.push('no-highlight'); classes.push('hljs'); } else { classes.push('language-' + suffix); } - for (const clazz of classes) { - pre.classList.add(clazz); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = classes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var clazz = _step2.value; + + pre.classList.add(clazz); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } } })(); - const cont = [...pre.classList].some(function(e) { + var cont = [].concat(_toConsumableArray(pre.classList)).some(function (e) { return e === 'hljs' || e.startsWith('language-'); }); if (!cont) { - continue; + return 'continue'; } hljs.highlightBlock(pre); if (pre.classList.contains('file-source')) { hljs.lineNumbersBlock(pre, { - singleLine: true, + singleLine: true }); } + }; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = document.getElementsByTagName('pre')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var pre = _step.value; + + var _ret = _loop(pre); + + if (_ret === 'continue') continue; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } })(); +//# sourceMappingURL=highlight.js.map \ No newline at end of file diff --git a/webserver/web/static/js/highlight.js.map b/webserver/web/static/js/highlight.js.map new file mode 100644 index 00000000..635fa32b --- /dev/null +++ b/webserver/web/static/js/highlight.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/highlight.js"],"names":["pre","id","title","document","getElementById","suffix","lang","innerText","trim","split","pop","classes","hljs","getLanguage","undefined","push","clazz","classList","add","cont","some","e","startsWith","highlightBlock","contains","lineNumbersBlock","singleLine","getElementsByTagName"],"mappings":";;;;AAAA;;AAEA,CAAC,YAAW;AAAA,6BACCA,GADD;AAER,KAAC,YAAW;AACV,UAAIA,IAAIC,EAAJ,KAAW,EAAf,EAAmB;AACjB;AACD;AACD,UAAMC,QAAQC,SAASC,cAAT,CAA2BJ,IAAIC,EAA/B,YAAd;AACA,UAAIC,UAAU,IAAd,EAAoB;AAClB;AACD;AACD,UAAIG,eAAJ;AACA,UAAIL,IAAIM,IAAR,EAAc;AACZD,iBAASL,IAAIM,IAAb;AACD,OAFD,MAEO;AACLD,iBAASH,MAAMK,SAAN,CAAgBC,IAAhB,GAAuBC,KAAvB,CAA6B,GAA7B,EAAkCC,GAAlC,EAAT;AACD;AACD,UAAMC,UAAU,EAAhB;AACA,UAAIC,KAAKC,WAAL,CAAiBR,MAAjB,MAA6BS,SAAjC,EAA4C;AAC1CH,gBAAQI,IAAR,CAAa,cAAb;AACAJ,gBAAQI,IAAR,CAAa,MAAb;AACD,OAHD,MAGO;AACLJ,gBAAQI,IAAR,eAAyBV,MAAzB;AACD;AApBS;AAAA;AAAA;;AAAA;AAqBV,8BAAoBM,OAApB,mIAA6B;AAAA,cAAlBK,KAAkB;;AAC3BhB,cAAIiB,SAAJ,CAAcC,GAAd,CAAkBF,KAAlB;AACD;AAvBS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBX,KAxBD;;AA0BA,QAAMG,OAAO,6BAAInB,IAAIiB,SAAR,GAAmBG,IAAnB,CAAwB;AAAA,aAAKC,MAAM,MAAN,IAAgBA,EAAEC,UAAF,CAAa,WAAb,CAArB;AAAA,KAAxB,CAAb;;AAEA,QAAI,CAACH,IAAL,EAAW;AACT;AACD;;AAEDP,SAAKW,cAAL,CAAoBvB,GAApB;;AAEA,QAAIA,IAAIiB,SAAJ,CAAcO,QAAd,CAAuB,aAAvB,CAAJ,EAA2C;AACzCZ,WAAKa,gBAAL,CAAsBzB,GAAtB,EAA2B;AACzB0B,oBAAY;AADa,OAA3B;AAGD;AAxCO;;AAAA;AAAA;AAAA;;AAAA;AACV,yBAAkBvB,SAASwB,oBAAT,CAA8B,KAA9B,CAAlB,8HAAwD;AAAA,UAA7C3B,GAA6C;;AAAA,uBAA7CA,GAA6C;;AAAA,+BA8BpD;AAUH;AAzCS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CX,CA1CD","file":"highlight.js","sourcesContent":["/* global hljs */\n\n(function() {\n for (const pre of document.getElementsByTagName('pre')) {\n (function() {\n if (pre.id === '') {\n return;\n }\n const title = document.getElementById(`${pre.id}-title`);\n if (title === null) {\n return;\n }\n let suffix;\n if (pre.lang) {\n suffix = pre.lang;\n } else {\n suffix = title.innerText.trim().split('.').pop();\n }\n const classes = [];\n if (hljs.getLanguage(suffix) === undefined) {\n classes.push('no-highlight');\n classes.push('hljs');\n } else {\n classes.push(`language-${suffix}`);\n }\n for (const clazz of classes) {\n pre.classList.add(clazz);\n }\n })();\n\n const cont = [...pre.classList].some(e => e === 'hljs' || e.startsWith('language-'));\n\n if (!cont) {\n continue;\n }\n\n hljs.highlightBlock(pre);\n\n if (pre.classList.contains('file-source')) {\n hljs.lineNumbersBlock(pre, {\n singleLine: true,\n });\n }\n }\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/navbar.js b/webserver/web/static/js/navbar.js index e0ef59aa..a8136e37 100644 --- a/webserver/web/static/js/navbar.js +++ b/webserver/web/static/js/navbar.js @@ -1,16 +1,18 @@ -(function() { - document.addEventListener('DOMContentLoaded', function() { +'use strict'; + +(function () { + document.addEventListener('DOMContentLoaded', function () { // Get all "navbar-burger" elements - const navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); + var navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); // Check if there are any navbar burgers if (navbarBurgers.length > 0) { // Add a click event on each of them - navbarBurgers.forEach(function(el) { - el.addEventListener('click', function() { + navbarBurgers.forEach(function (el) { + el.addEventListener('click', function () { // Get the target from the "data-target" attribute - const target_id = el.dataset.target; - const target = document.getElementById(target_id); + var targetId = el.dataset.target; + var target = document.getElementById(targetId); // Toggle the class on both the "navbar-burger" and the "navbar-menu" el.classList.toggle('is-active'); @@ -20,3 +22,4 @@ } }); })(); +//# sourceMappingURL=navbar.js.map \ No newline at end of file diff --git a/webserver/web/static/js/navbar.js.map b/webserver/web/static/js/navbar.js.map new file mode 100644 index 00000000..481a566e --- /dev/null +++ b/webserver/web/static/js/navbar.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/navbar.js"],"names":["document","addEventListener","navbarBurgers","Array","prototype","slice","call","querySelectorAll","length","forEach","el","targetId","dataset","target","getElementById","classList","toggle"],"mappings":";;AAAA,CAAC,YAAW;AACVA,WAASC,gBAAT,CAA0B,kBAA1B,EAA8C,YAAM;AAClD;AACA,QAAMC,gBAAgBC,MAAMC,SAAN,CAAgBC,KAAhB,CAAsBC,IAAtB,CAA2BN,SAASO,gBAAT,CAA0B,gBAA1B,CAA3B,EAAwE,CAAxE,CAAtB;;AAEA;AACA,QAAIL,cAAcM,MAAd,GAAuB,CAA3B,EAA8B;AAC5B;AACAN,oBAAcO,OAAd,CAAsB,cAAM;AAC1BC,WAAGT,gBAAH,CAAoB,OAApB,EAA6B,YAAM;AACjC;AACA,cAAMU,WAAWD,GAAGE,OAAH,CAAWC,MAA5B;AACA,cAAMA,SAASb,SAASc,cAAT,CAAwBH,QAAxB,CAAf;;AAEA;AACAD,aAAGK,SAAH,CAAaC,MAAb,CAAoB,WAApB;AACAH,iBAAOE,SAAP,CAAiBC,MAAjB,CAAwB,WAAxB;AACD,SARD;AASD,OAVD;AAWD;AACF,GAnBD;AAoBD,CArBD","file":"navbar.js","sourcesContent":["(function() {\n document.addEventListener('DOMContentLoaded', () => {\n // Get all \"navbar-burger\" elements\n const navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);\n\n // Check if there are any navbar burgers\n if (navbarBurgers.length > 0) {\n // Add a click event on each of them\n navbarBurgers.forEach(el => {\n el.addEventListener('click', () => {\n // Get the target from the \"data-target\" attribute\n const targetId = el.dataset.target;\n const target = document.getElementById(targetId);\n\n // Toggle the class on both the \"navbar-burger\" and the \"navbar-menu\"\n el.classList.toggle('is-active');\n target.classList.toggle('is-active');\n });\n });\n }\n });\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/notifications.js b/webserver/web/static/js/notifications.js index 2533c7ee..79aa3399 100644 --- a/webserver/web/static/js/notifications.js +++ b/webserver/web/static/js/notifications.js @@ -1,12 +1,60 @@ -(function() { - for (const button of document.querySelectorAll('.message > .message-header > .delete')) { - button.addEventListener('click', function() { - this.parentElement.parentElement.remove(); - }); +'use strict'; + +(function () { + var _this = this; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = document.querySelectorAll('.message > .message-header > .delete')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var button = _step.value; + + button.addEventListener('click', function () { + return _this.parentElement.parentElement.remove(); + }); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } - for (const button of document.querySelectorAll('.notification > .delete')) { - button.addEventListener('click', function() { - this.parentElement.remove(); - }); + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = document.querySelectorAll('.notification > .delete')[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var _button = _step2.value; + + _button.addEventListener('click', function () { + return _this.parentElement.remove(); + }); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } } })(); +//# sourceMappingURL=notifications.js.map \ No newline at end of file diff --git a/webserver/web/static/js/notifications.js.map b/webserver/web/static/js/notifications.js.map new file mode 100644 index 00000000..7b95b7bc --- /dev/null +++ b/webserver/web/static/js/notifications.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/notifications.js"],"names":["document","querySelectorAll","button","addEventListener","parentElement","remove"],"mappings":";;AAAA,CAAC,YAAW;AAAA;;AAAA;AAAA;AAAA;;AAAA;AACV,yBAAqBA,SAASC,gBAAT,CAA0B,sCAA1B,CAArB,8HAAwF;AAAA,UAA7EC,MAA6E;;AACtFA,aAAOC,gBAAP,CAAwB,OAAxB,EAAiC;AAAA,eAAM,MAAKC,aAAL,CAAmBA,aAAnB,CAAiCC,MAAjC,EAAN;AAAA,OAAjC;AACD;AAHS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAIV,0BAAqBL,SAASC,gBAAT,CAA0B,yBAA1B,CAArB,mIAA2E;AAAA,UAAhEC,OAAgE;;AACzEA,cAAOC,gBAAP,CAAwB,OAAxB,EAAiC;AAAA,eAAM,MAAKC,aAAL,CAAmBC,MAAnB,EAAN;AAAA,OAAjC;AACD;AANS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOX,CAPD","file":"notifications.js","sourcesContent":["(function() {\n for (const button of document.querySelectorAll('.message > .message-header > .delete')) {\n button.addEventListener('click', () => this.parentElement.parentElement.remove());\n }\n for (const button of document.querySelectorAll('.notification > .delete')) {\n button.addEventListener('click', () => this.parentElement.remove());\n }\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/password.js b/webserver/web/static/js/password.js index 2c9ac13f..924e7d92 100644 --- a/webserver/web/static/js/password.js +++ b/webserver/web/static/js/password.js @@ -1,4 +1,10 @@ -(function() { +'use strict'; + +/* global zxcvbn */ + +(function () { + var _this = this; + function checkMatch(pw, verify) { if (pw.value === verify.value && pw.value.length !== 0) { verify.classList.add('is-success'); @@ -7,8 +13,8 @@ } } - document.getElementById('password_verify').addEventListener('input', function() { - checkMatch(document.getElementById('password'), this); + document.getElementById('password_verify').addEventListener('input', function () { + return checkMatch(document.getElementById('password'), _this); }); function doHides(pw, strength) { @@ -22,29 +28,29 @@ function passwordStrength(pw) { checkMatch(pw, document.getElementById('password_verify')); - const values = []; + var values = []; { - const name = document.getElementById('name'); + var name = document.getElementById('name'); if (name) { values.push(name.value); } - const username = document.getElementById('username'); + var username = document.getElementById('username'); if (username) { values.push(username.value); } - const email = document.getElementById('email'); + var email = document.getElementById('email'); if (email) { values.push(email.value); } } - const password = pw.value; - const strength = document.getElementById('strength'); - const progress = document.getElementById('strength_progress'); - const warning = document.getElementById('strength_warning'); + var password = pw.value; + var strength = document.getElementById('strength'); + var progress = document.getElementById('strength_progress'); + var warning = document.getElementById('strength_warning'); if (pw.getAttribute('data-bar') === 'hidden') { - doHides(pw, strength_progress); + doHides(pw, progress); } if (password.length === 0) { @@ -56,7 +62,7 @@ return; } - const z = zxcvbn(password, values); + var z = zxcvbn(password, values); var message = 'Time to crack your password: ' + z.crack_times_display.offline_slow_hashing_1e4_per_second; message += ' What is this?'; @@ -64,7 +70,7 @@ warning.innerHTML = '
' + z.feedback.warning; - var color; + var color = void 0; switch (z.score) { case 0: color = 'is-danger'; @@ -83,14 +89,14 @@ break; } - const classes = progress.classList; progress.classList.remove('is-danger'); progress.classList.remove('is-warning'); progress.classList.remove('is-success'); progress.classList.add(color); } - document.getElementById('password').addEventListener('input', function() { - passwordStrength(this); + document.getElementById('password').addEventListener('input', function () { + return passwordStrength(_this); }); })(); +//# sourceMappingURL=password.js.map \ No newline at end of file diff --git a/webserver/web/static/js/password.js.map b/webserver/web/static/js/password.js.map new file mode 100644 index 00000000..47a9b4e6 --- /dev/null +++ b/webserver/web/static/js/password.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/password.js"],"names":["checkMatch","pw","verify","value","length","classList","add","remove","document","getElementById","addEventListener","doHides","strength","passwordStrength","values","name","push","username","email","password","progress","warning","getAttribute","innerHTML","z","zxcvbn","message","crack_times_display","offline_slow_hashing_1e4_per_second","feedback","color","score"],"mappings":";;AAAA;;AAEA,CAAC,YAAW;AAAA;;AACV,WAASA,UAAT,CAAoBC,EAApB,EAAwBC,MAAxB,EAAgC;AAC9B,QAAID,GAAGE,KAAH,KAAaD,OAAOC,KAApB,IAA6BF,GAAGE,KAAH,CAASC,MAAT,KAAoB,CAArD,EAAwD;AACtDF,aAAOG,SAAP,CAAiBC,GAAjB,CAAqB,YAArB;AACD,KAFD,MAEO;AACLJ,aAAOG,SAAP,CAAiBE,MAAjB,CAAwB,YAAxB;AACD;AACF;;AAEDC,WACGC,cADH,CACkB,iBADlB,EAEGC,gBAFH,CAEoB,OAFpB,EAE6B;AAAA,WAAMV,WAAWQ,SAASC,cAAT,CAAwB,UAAxB,CAAX,EAAgD,KAAhD,CAAN;AAAA,GAF7B;;AAIA,WAASE,OAAT,CAAiBV,EAAjB,EAAqBW,QAArB,EAA+B;AAC7B,QAAIX,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B,CAA0B,YAA1B;AACA;AACD;;AAED,QAAMiB,IAAIC,OAAON,QAAP,EAAiBL,MAAjB,CAAV;;AAEA,QAAIY,4CAA0CF,EAAEG,mBAAF,CAAsBC,mCAApE;AACAF,eAAW,2SAAX;AACAd,aAASW,SAAT,GAAqBG,OAArB;;AAEAL,YAAQE,SAAR,aAA4BC,EAAEK,QAAF,CAAWR,OAAvC;;AAEA,QAAIS,cAAJ;AACA,YAAQN,EAAEO,KAAV;AACE,WAAK,CAAL;AACED,gBAAQ,WAAR;AACA;AACF,WAAK,CAAL;AACEA,gBAAQ,WAAR;AACA;AACF,WAAK,CAAL;AACEA,gBAAQ,YAAR;AACA;AACF,WAAK,CAAL;AACEA,gBAAQ,YAAR;AACA;AACF,WAAK,CAAL;AACEA,gBAAQ,YAAR;AACA;AAfJ;;AAkBAV,aAASf,SAAT,CAAmBE,MAAnB,CAA0B,WAA1B;AACAa,aAASf,SAAT,CAAmBE,MAAnB,CAA0B,YAA1B;AACAa,aAASf,SAAT,CAAmBE,MAAnB,CAA0B,YAA1B;AACAa,aAASf,SAAT,CAAmBC,GAAnB,CAAuBwB,KAAvB;AACD;;AAEDtB,WAASC,cAAT,CAAwB,UAAxB,EAAoCC,gBAApC,CAAqD,OAArD,EAA8D;AAAA,WAAMG,iBAAiB,KAAjB,CAAN;AAAA,GAA9D;AACD,CA5FD","file":"password.js","sourcesContent":["/* global zxcvbn */\n\n(function() {\n function checkMatch(pw, verify) {\n if (pw.value === verify.value && pw.value.length !== 0) {\n verify.classList.add('is-success');\n } else {\n verify.classList.remove('is-success');\n }\n }\n\n document\n .getElementById('password_verify')\n .addEventListener('input', () => checkMatch(document.getElementById('password'), this));\n\n function doHides(pw, strength) {\n if (pw.value.length === 0) {\n strength.classList.add('is-not-displayed');\n } else {\n strength.classList.remove('is-not-displayed');\n }\n }\n\n function passwordStrength(pw) {\n checkMatch(pw, document.getElementById('password_verify'));\n\n const values = [];\n {\n const name = document.getElementById('name');\n if (name) {\n values.push(name.value);\n }\n const username = document.getElementById('username');\n if (username) {\n values.push(username.value);\n }\n const email = document.getElementById('email');\n if (email) {\n values.push(email.value);\n }\n }\n\n const password = pw.value;\n const strength = document.getElementById('strength');\n const progress = document.getElementById('strength_progress');\n const warning = document.getElementById('strength_warning');\n\n if (pw.getAttribute('data-bar') === 'hidden') {\n doHides(pw, progress);\n }\n\n if (password.length === 0) {\n strength.innerHTML = '';\n warning.innerHTML = '';\n progress.classList.add('is-danger');\n progress.classList.remove('is-warning');\n progress.classList.remove('is-success');\n return;\n }\n\n const z = zxcvbn(password, values);\n\n let message = `Time to crack your password: ${z.crack_times_display.offline_slow_hashing_1e4_per_second}`;\n message += ' What is this?';\n strength.innerHTML = message;\n\n warning.innerHTML = `
${z.feedback.warning}`;\n\n let color;\n switch (z.score) {\n case 0:\n color = 'is-danger';\n break;\n case 1:\n color = 'is-danger';\n break;\n case 2:\n color = 'is-warning';\n break;\n case 3:\n color = 'is-warning';\n break;\n case 4:\n color = 'is-success';\n break;\n }\n\n progress.classList.remove('is-danger');\n progress.classList.remove('is-warning');\n progress.classList.remove('is-success');\n progress.classList.add(color);\n }\n\n document.getElementById('password').addEventListener('input', () => passwordStrength(this));\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/paste.js b/webserver/web/static/js/paste.js index bbf909a8..84362341 100644 --- a/webserver/web/static/js/paste.js +++ b/webserver/web/static/js/paste.js @@ -1,4 +1,8 @@ -(function() { +'use strict'; + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +(function () { function openModal() { document.getElementById('deletion_modal').classList.add('is-active'); } @@ -7,41 +11,66 @@ document.getElementById('deletion_modal').classList.remove('is-active'); } - for (var e of document.getElementsByClassName('opens-modal')) { - e.addEventListener('click', openModal); - } + [].concat(_toConsumableArray(document.getElementsByClassName('opens-modal'))).forEach(function (e) { + return e.addEventListener('click', openModal); + }); - for (var e of document.getElementsByClassName('closes-modal')) { - e.addEventListener('click', closeModal); - } + [].concat(_toConsumableArray(document.getElementsByClassName('closes-modal'))).forEach(function (e) { + return e.addEventListener('click', closeModal); + }); - function swap(current, current_content, next, next_content) { + function swap(current, currentContent, next, nextContent) { current.classList.remove('is-active'); next.classList.add('is-active'); - current_content.classList.add('is-not-displayed'); - next_content.classList.remove('is-not-displayed'); + currentContent.classList.add('is-not-displayed'); + nextContent.classList.remove('is-not-displayed'); } - for (const tabs_container of document.getElementsByClassName('paste-tabs-container')) { - const file_id = tabs_container.dataset.id; - const tab_links = document.getElementById(file_id + '-tab-links'); + var _loop = function _loop(tabsContainer) { + var fileId = tabsContainer.dataset.id; + var tabLinks = document.getElementById(fileId + '-tab-links'); - const rendered = tab_links.querySelector('.paste-rendered-tab'); - const rendered_a = rendered.firstChild; + var rendered = tabLinks.querySelector('.paste-rendered-tab'); + var renderedA = rendered.firstChild; - const source = tab_links.querySelector('.paste-source-tab'); - const source_a = source.firstChild; + var source = tabLinks.querySelector('.paste-source-tab'); + var sourceA = source.firstChild; - const rendered_content = tabs_container.querySelector('div.paste-rendered-content'); - const source_content = tabs_container.querySelector('div.paste-source-content'); + var renderedContent = tabsContainer.querySelector('div.paste-rendered-content'); + var sourceContent = tabsContainer.querySelector('div.paste-source-content'); - rendered_a.addEventListener('click', function() { - swap(source, source_content, rendered, rendered_content); + renderedA.addEventListener('click', function () { + return swap(source, sourceContent, rendered, renderedContent); }); - source_a.addEventListener('click', function() { - swap(rendered, rendered_content, source, source_content); + sourceA.addEventListener('click', function () { + return swap(rendered, renderedContent, source, sourceContent); }); + }; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = document.getElementsByClassName('paste-tabs-container')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var tabsContainer = _step.value; + + _loop(tabsContainer); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } function getDeletionKeys() { @@ -61,75 +90,97 @@ } // check if the page is displaying a deletion key and add it to local storage - (function() { - const dk_elem = document.getElementById('deletion_key'); + (function () { + var dkElem = document.getElementById('deletion_key'); - if (dk_elem === null) { + if (dkElem === null) { return; } - const deletion_key = dk_elem.innerText; + var deletionKey = dkElem.innerText; - const keys = getDeletionKeys(); + var keys = getDeletionKeys(); - const paste_id = dk_elem.dataset.pasteId; + var pasteId = dkElem.dataset.pasteId; - keys[paste_id] = { - deletion_key: deletion_key, - expires: new Date((new Date).getTime() + (30 * 24 * 60 * 60 * 1000)), + keys[pasteId] = { + deletionKey: deletionKey, + expires: new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000) }; setDeletionKeys(keys); })(); // check if we have a deletion key for this paste and insert it - (function() { - const dk_input = document.getElementById('deletion_key_input'); + (function () { + var dkInput = document.getElementById('deletion_key_input'); - if (dk_input === null) { + if (dkInput === null) { return; } - const paste_id = dk_input.dataset.pasteId; + var pasteId = dkInput.dataset.pasteId; - const keys = getDeletionKeys(); + var keys = getDeletionKeys(); - const key = keys[paste_id]; + var key = keys[pasteId]; if (key === undefined) { return; } - dk_input.value = key['deletion_key']; + dkInput.value = key.deletion_key; // add a listener for form submit to remove key from local storage - const deletion_form = document.getElementById('deletion_form'); + var deletionForm = document.getElementById('deletion_form'); - if (deletion_form === null) { + if (deletionForm === null) { return; } - deletion_form.addEventListener('submit', function() { - const keys = getDeletionKeys(); - delete keys[paste_id]; + deletionForm.addEventListener('submit', function () { + var keys = getDeletionKeys(); + delete keys[pasteId]; setDeletionKeys(keys); }); })(); // expire old deletion keys - (function() { - const keys = getDeletionKeys(); + (function () { + var keys = getDeletionKeys(); + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - for (const key of Object.entries(keys)) { - if ((new Date) >= new Date(key[1]['expires'])) { - delete keys[key[0]]; + try { + for (var _iterator2 = Object.entries(keys)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var key = _step2.value; + + if (new Date() >= new Date(key[1].expires)) { + delete keys[key[0]]; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } setDeletionKeys(keys); })(); - for (const pre of document.querySelectorAll('.paste-rendered-content pre[lang]')) { - pre.classList.add('language-' + pre.lang); - } + document.querySelectorAll('.paste-rendered-content pre[lang]').forEach(function (pre) { + return pre.classList.add('language-' + pre.lang); + }); })(); +//# sourceMappingURL=paste.js.map \ No newline at end of file diff --git a/webserver/web/static/js/paste.js.map b/webserver/web/static/js/paste.js.map new file mode 100644 index 00000000..3270c14e --- /dev/null +++ b/webserver/web/static/js/paste.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/paste.js"],"names":["openModal","document","getElementById","classList","add","closeModal","remove","getElementsByClassName","forEach","e","addEventListener","swap","current","currentContent","next","nextContent","tabsContainer","fileId","dataset","id","tabLinks","rendered","querySelector","renderedA","firstChild","source","sourceA","renderedContent","sourceContent","getDeletionKeys","keys","localStorage","getItem","JSON","parse","setDeletionKeys","setItem","stringify","dkElem","deletionKey","innerText","pasteId","expires","Date","getTime","dkInput","key","undefined","value","deletion_key","deletionForm","Object","entries","querySelectorAll","pre","lang"],"mappings":";;;;AAAA,CAAC,YAAW;AACV,WAASA,SAAT,GAAqB;AACnBC,aAASC,cAAT,CAAwB,gBAAxB,EAA0CC,SAA1C,CAAoDC,GAApD,CAAwD,WAAxD;AACD;;AAED,WAASC,UAAT,GAAsB;AACpBJ,aAASC,cAAT,CAAwB,gBAAxB,EAA0CC,SAA1C,CAAoDG,MAApD,CAA2D,WAA3D;AACD;;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AAUI,QAAQ3B,OAAR,CAAgBuB,OAAhC;;AAEA,QAAMX,OAAOD,iBAAb;;AAEA,QAAMiB,MAAMhB,KAAKW,OAAL,CAAZ;;AAEA,QAAIK,QAAQC,SAAZ,EAAuB;AACrB;AACD;;AAEDF,YAAQG,KAAR,GAAgBF,IAAIG,YAApB;;AAEA;AACA,QAAMC,eAAejD,SAASC,cAAT,CAAwB,eAAxB,CAArB;;AAEA,QAAIgD,iBAAiB,IAArB,EAA2B;AACzB;AACD;;AAEDA,iBAAaxC,gBAAb,CAA8B,QAA9B,EAAwC,YAAM;AAC5C,UAAMoB,OAAOD,iBAAb;AACA,aAAOC,KAAKW,OAAL,CAAP;AACAN,sBAAgBL,IAAhB;AACD,KAJD;AAKD,GA/BD;;AAiCA;AACA,GAAC,YAAW;AACV,QAAMA,OAAOD,iBAAb;;AADU;AAAA;AAAA;;AAAA;AAGV,4BAAkBsB,OAAOC,OAAP,CAAetB,IAAf,CAAlB,mIAAwC;AAAA,YAA7BgB,GAA6B;;AACtC,YAAK,IAAIH,IAAJ,EAAD,IAAc,IAAIA,IAAJ,CAASG,IAAI,CAAJ,EAAOJ,OAAhB,CAAlB,EAA4C;AAC1C,iBAAOZ,KAAKgB,IAAI,CAAJ,CAAL,CAAP;AACD;AACF;AAPS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AASVX,oBAAgBL,IAAhB;AACD,GAVD;;AAYA7B,WACGoD,gBADH,CACoB,mCADpB,EAEG7C,OAFH,CAEW;AAAA,WAAO8C,IAAInD,SAAJ,CAAcC,GAAd,eAA8BkD,IAAIC,IAAlC,CAAP;AAAA,GAFX;AAGD,CA9HD","file":"paste.js","sourcesContent":["(function() {\n function openModal() {\n document.getElementById('deletion_modal').classList.add('is-active');\n }\n\n function closeModal() {\n document.getElementById('deletion_modal').classList.remove('is-active');\n }\n\n [...document.getElementsByClassName('opens-modal')].forEach(e => e.addEventListener('click', openModal));\n\n [...document.getElementsByClassName('closes-modal')].forEach(e => e.addEventListener('click', closeModal));\n\n function swap(current, currentContent, next, nextContent) {\n current.classList.remove('is-active');\n next.classList.add('is-active');\n\n currentContent.classList.add('is-not-displayed');\n nextContent.classList.remove('is-not-displayed');\n }\n\n for (const tabsContainer of document.getElementsByClassName('paste-tabs-container')) {\n const fileId = tabsContainer.dataset.id;\n const tabLinks = document.getElementById(`${fileId}-tab-links`);\n\n const rendered = tabLinks.querySelector('.paste-rendered-tab');\n const renderedA = rendered.firstChild;\n\n const source = tabLinks.querySelector('.paste-source-tab');\n const sourceA = source.firstChild;\n\n const renderedContent = tabsContainer.querySelector('div.paste-rendered-content');\n const sourceContent = tabsContainer.querySelector('div.paste-source-content');\n\n renderedA.addEventListener('click', () => swap(source, sourceContent, rendered, renderedContent));\n sourceA.addEventListener('click', () => swap(rendered, renderedContent, source, sourceContent));\n }\n\n function getDeletionKeys() {\n let keys = localStorage.getItem('deletion_keys');\n\n if (keys === null) {\n keys = {};\n } else {\n keys = JSON.parse(keys);\n }\n\n return keys;\n }\n\n function setDeletionKeys(keys) {\n localStorage.setItem('deletion_keys', JSON.stringify(keys));\n }\n\n // check if the page is displaying a deletion key and add it to local storage\n (function() {\n const dkElem = document.getElementById('deletion_key');\n\n if (dkElem === null) {\n return;\n }\n\n const deletionKey = dkElem.innerText;\n\n const keys = getDeletionKeys();\n\n const pasteId = dkElem.dataset.pasteId;\n\n keys[pasteId] = {\n deletionKey,\n expires: new Date((new Date).getTime() + (30 * 24 * 60 * 60 * 1000)),\n };\n\n setDeletionKeys(keys);\n })();\n\n // check if we have a deletion key for this paste and insert it\n (function() {\n const dkInput = document.getElementById('deletion_key_input');\n\n if (dkInput === null) {\n return;\n }\n\n const pasteId = dkInput.dataset.pasteId;\n\n const keys = getDeletionKeys();\n\n const key = keys[pasteId];\n\n if (key === undefined) {\n return;\n }\n\n dkInput.value = key.deletion_key;\n\n // add a listener for form submit to remove key from local storage\n const deletionForm = document.getElementById('deletion_form');\n\n if (deletionForm === null) {\n return;\n }\n\n deletionForm.addEventListener('submit', () => {\n const keys = getDeletionKeys();\n delete keys[pasteId];\n setDeletionKeys(keys);\n });\n })();\n\n // expire old deletion keys\n (function() {\n const keys = getDeletionKeys();\n\n for (const key of Object.entries(keys)) {\n if ((new Date) >= new Date(key[1].expires)) {\n delete keys[key[0]];\n }\n }\n\n setDeletionKeys(keys);\n })();\n\n document\n .querySelectorAll('.paste-rendered-content pre[lang]')\n .forEach(pre => pre.classList.add(`language-${pre.lang}`));\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/register.js b/webserver/web/static/js/register.js index 2104de31..571582c6 100644 --- a/webserver/web/static/js/register.js +++ b/webserver/web/static/js/register.js @@ -1,9 +1,13 @@ -(function() { +'use strict'; + +(function () { if (localStorage.getItem('style') === 'dark') { document.getElementById('submit_button').setAttribute('data-theme', 'dark'); } })(); +// eslint-disable-next-line no-unused-vars function submitRegistration() { document.getElementById('registration_form').submit(); } +//# sourceMappingURL=register.js.map \ No newline at end of file diff --git a/webserver/web/static/js/register.js.map b/webserver/web/static/js/register.js.map new file mode 100644 index 00000000..e601d90f --- /dev/null +++ b/webserver/web/static/js/register.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/register.js"],"names":["localStorage","getItem","document","getElementById","setAttribute","submitRegistration","submit"],"mappings":";;AAAA,CAAC,YAAW;AACV,MAAIA,aAAaC,OAAb,CAAqB,OAArB,MAAkC,MAAtC,EAA8C;AAC5CC,aAASC,cAAT,CAAwB,eAAxB,EAAyCC,YAAzC,CAAsD,YAAtD,EAAoE,MAApE;AACD;AACF,CAJD;;AAMA;AACA,SAASC,kBAAT,GAA8B;AAC5BH,WAASC,cAAT,CAAwB,mBAAxB,EAA6CG,MAA7C;AACD","file":"register.js","sourcesContent":["(function() {\n if (localStorage.getItem('style') === 'dark') {\n document.getElementById('submit_button').setAttribute('data-theme', 'dark');\n }\n})();\n\n// eslint-disable-next-line no-unused-vars\nfunction submitRegistration() {\n document.getElementById('registration_form').submit();\n}\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/style.js b/webserver/web/static/js/style.js index 602aa4b7..624db46c 100644 --- a/webserver/web/static/js/style.js +++ b/webserver/web/static/js/style.js @@ -1,36 +1,104 @@ -(function() { +'use strict'; + +(function () { function setActiveStyleSheet(title) { - for (const a of document.getElementsByTagName('link')) { - if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) { - a.disabled = true; - if (a.getAttribute('title') === title) { - a.disabled = false; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = document.getElementsByTagName('link')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var a = _step.value; + + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title')) { + a.disabled = true; + if (a.getAttribute('title') === title) { + a.disabled = false; + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; } } } + localStorage.setItem('style', getActiveStyleSheet()); } function getActiveStyleSheet() { - for (var a of document.getElementsByTagName('link')) { - if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled) { - return a.getAttribute('title'); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = document.getElementsByTagName('link')[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var a = _step2.value; + + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title') && !a.disabled) { + return a.getAttribute('title'); + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } + return null; } function getPreferredStyleSheet() { - for (var a of document.getElementsByTagName('link')) { - if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('rel').indexOf('alt') == -1 && a.getAttribute('title')) { - return a.getAttribute('title'); + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = document.getElementsByTagName('link')[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var a = _step3.value; + + if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('rel').indexOf('alt') === -1 && a.getAttribute('title')) { + return a.getAttribute('title'); + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } } } + return null; } function swapTheme() { - var next; + var next = void 0; if (getActiveStyleSheet() === 'dark') { next = 'light'; } else { @@ -40,21 +108,22 @@ } function loadSheet() { - const style = localStorage.getItem('style'); - const title = style ? style : getPreferredStyleSheet(); + var style = localStorage.getItem('style'); + var title = style ? style : getPreferredStyleSheet(); setActiveStyleSheet(title); } - window.addEventListener('load', function() { + window.addEventListener('load', function () { loadSheet(); document.getElementById('swap_theme').addEventListener('click', swapTheme); }); - window.addEventListener('unload', function() { - const title = getActiveStyleSheet(); + window.addEventListener('unload', function () { + var title = getActiveStyleSheet(); this.localStorage.setItem('style', title); }); loadSheet(); })(); +//# sourceMappingURL=style.js.map \ No newline at end of file diff --git a/webserver/web/static/js/style.js.map b/webserver/web/static/js/style.js.map new file mode 100644 index 00000000..9699d9b9 --- /dev/null +++ b/webserver/web/static/js/style.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/style.js"],"names":["setActiveStyleSheet","title","document","getElementsByTagName","a","getAttribute","indexOf","disabled","localStorage","setItem","getActiveStyleSheet","getPreferredStyleS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AA4C;;AACrD,YAAIA,EAAEC,YAAF,CAAe,KAAf,EAAsBC,OAAtB,CAA8B,OAA9B,MAA2C,CAAC,CAA5C,IAAiDF,EAAEC,YAAF,CAAe,KAAf,EAAsBC,OAAtB,CAA8B,KAA9B,MAAyC,CAAC,CAA3F,IAAgGF,EAAEC,YAAF,CAAe,OAAf,CAApG,EAA6H;AAC3H,iBAAOD,EAAEC,YAAF,CAAe,OAAf,CAAP;AACD;AACF;AAL+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAMhC,WAAO,IAAP;AACD;;AAED,WAASO,SAAT,GAAqB;AACnB,QAAIC,aAAJ;AACA,QAAIH,0BAA0B,MAA9B,EAAsC;AACpCG,aAAO,OAAP;AACD,KAFD,MAEO;AACLA,aAAO,MAAP;AACD;AACDb,wBAAoBa,IAApB;AACD;;AAED,WAASC,SAAT,GAAqB;AACnB,QAAMC,QAAQP,aAAaQ,OAAb,CAAqB,OAArB,CAAd;AACA,QAAMf,QAAQc,QAAQA,KAAR,GAAgBJ,wBAA9B;AACAX,wBAAoBC,KAApB;AACD;;AAEDgB,SAAOC,gBAAP,CAAwB,MAAxB,EAAgC,YAAM;AACpCJ;;AAEAZ,aAASiB,cAAT,CAAwB,YAAxB,EAAsCD,gBAAtC,CAAuD,OAAvD,EAAgEN,SAAhE;AACD,GAJD;;AAMAK,SAAOC,gBAAP,CAAwB,QAAxB,EAAkC,YAAW;AAC3C,QAAMjB,QAAQS,qBAAd;AACA,SAAKF,YAAL,CAAkBC,OAAlB,CAA0B,OAA1B,EAAmCR,KAAnC;AACD,GAHD;;AAKAa;AACD,CA3DD","file":"style.js","sourcesContent":["(function() {\n function setActiveStyleSheet(title) {\n for (const a of document.getElementsByTagName('link')) {\n if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title')) {\n a.disabled = true;\n if (a.getAttribute('title') === title) {\n a.disabled = false;\n }\n }\n }\n localStorage.setItem('style', getActiveStyleSheet());\n }\n\n function getActiveStyleSheet() {\n for (const a of document.getElementsByTagName('link')) {\n if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('title') && !a.disabled) {\n return a.getAttribute('title');\n }\n }\n return null;\n }\n\n function getPreferredStyleSheet() {\n for (const a of document.getElementsByTagName('link')) {\n if (a.getAttribute('rel').indexOf('style') !== -1 && a.getAttribute('rel').indexOf('alt') === -1 && a.getAttribute('title')) {\n return a.getAttribute('title');\n }\n }\n return null;\n }\n\n function swapTheme() {\n let next;\n if (getActiveStyleSheet() === 'dark') {\n next = 'light';\n } else {\n next = 'dark';\n }\n setActiveStyleSheet(next);\n }\n\n function loadSheet() {\n const style = localStorage.getItem('style');\n const title = style ? style : getPreferredStyleSheet();\n setActiveStyleSheet(title);\n }\n\n window.addEventListener('load', () => {\n loadSheet();\n\n document.getElementById('swap_theme').addEventListener('click', swapTheme);\n });\n\n window.addEventListener('unload', function() {\n const title = getActiveStyleSheet();\n this.localStorage.setItem('style', title);\n });\n\n loadSheet();\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/static/js/timestamps.js b/webserver/web/static/js/timestamps.js index ee69dba6..c9d7617b 100644 --- a/webserver/web/static/js/timestamps.js +++ b/webserver/web/static/js/timestamps.js @@ -1,23 +1,48 @@ -(function() { +'use strict'; + +/* global moment */ + +(function () { function updateTime(elem) { - const ts = elem.dataset.timestamp; + var ts = elem.dataset.timestamp; if (ts === undefined) { return; } - const m = moment.utc(ts).local(); + var m = moment.utc(ts).local(); elem.innerHTML = m.fromNow(); elem.title = m.format('LLL'); } function updateAllTimes() { - for (const ts_elem of document.getElementsByClassName('timestamp')) { - updateTime(ts_elem); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = document.getElementsByClassName('timestamp')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var ts = _step.value; + + updateTime(ts); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } } - (function() { + (function () { if (navigator.languages) { moment.locale(navigator.languages); } @@ -27,3 +52,4 @@ setInterval(updateAllTimes, 60 * 1000); })(); })(); +//# sourceMappingURL=timestamps.js.map \ No newline at end of file diff --git a/webserver/web/static/js/timestamps.js.map b/webserver/web/static/js/timestamps.js.map new file mode 100644 index 00000000..9e461639 --- /dev/null +++ b/webserver/web/static/js/timestamps.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/js/timestamps.js"],"names":["updateTime","elem","ts","dataset","timestamp","undefined","m","moment","utc","local","innerHTML","fromNow","title","format","updateAllTimes","document","getElementsByClassName","navigator","languages","locale","setInterval"],"mappings":";;AAAA;;AAEA,CAAC,YAAW;AACV,WAASA,UAAT,CAAoBC,IAApB,EAA0B;AACxB,QAAMC,KAAKD,KAAKE,OAAL,CAAaC,SAAxB;AACA,QAAIF,OAAOG,SAAX,EAAsB;AACpB;AACD;;AAED,QAAMC,IAAIC,OAAOC,GAAP,CAAWN,EAAX,EAAeO,KAAf,EAAV;;AAEAR,SAAKS,SAAL,GAAiBJ,EAAEK,OAAF,EAAjB;AACAV,SAAKW,KAAL,GAAaN,EAAEO,MAAF,CAAS,KAAT,CAAb;AACD;;AAED,WAASC,cAAT,GAA0B;AAAA;AAAA;AAAA;;AAAA;AACxB,2BAAiBC,SAASC,sBAAT,CAAgC,WAAhC,CAAjB,8HAA+D;AAAA,YAApDd,EAAoD;;AAC7DF,mBAAWE,EAAX;AACD;AAHuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIzB;;AAED,GAAC,YAAW;AACV,QAAIe,UAAUC,SAAd,EAAyB;AACvBX,aAAOY,MAAP,CAAcF,UAAUC,SAAxB;AACD;;AAEDJ;;AAEAM,gBAAYN,cAAZ,EAA4B,KAAK,IAAjC;AACD,GARD;AASD,CA5BD","file":"timestamps.js","sourcesContent":["/* global moment */\n\n(function() {\n function updateTime(elem) {\n const ts = elem.dataset.timestamp;\n if (ts === undefined) {\n return;\n }\n\n const m = moment.utc(ts).local();\n\n elem.innerHTML = m.fromNow();\n elem.title = m.format('LLL');\n }\n\n function updateAllTimes() {\n for (const ts of document.getElementsByClassName('timestamp')) {\n updateTime(ts);\n }\n }\n\n (function() {\n if (navigator.languages) {\n moment.locale(navigator.languages);\n }\n\n updateAllTimes();\n\n setInterval(updateAllTimes, 60 * 1000);\n })();\n})();\n"]} \ No newline at end of file diff --git a/webserver/web/templates/account/index.html.tera b/webserver/web/templates/account/index.html.tera index c6b2fbd5..8d2e4235 100644 --- a/webserver/web/templates/account/index.html.tera +++ b/webserver/web/templates/account/index.html.tera @@ -9,7 +9,7 @@ + integrity="sha384-/X0bG33G/+qdcdtMZRL6gWteDKzsAOMlMd+vmLlk0aEUaErn2y9Nce/m1JuI2bux"> {% endblock head %} {% block title %}Account{% endblock title %} diff --git a/webserver/web/templates/account/reset_password.html.tera b/webserver/web/templates/account/reset_password.html.tera index 71d0c59e..8e43b6fc 100644 --- a/webserver/web/templates/account/reset_password.html.tera +++ b/webserver/web/templates/account/reset_password.html.tera @@ -9,7 +9,7 @@ + integrity="sha384-/X0bG33G/+qdcdtMZRL6gWteDKzsAOMlMd+vmLlk0aEUaErn2y9Nce/m1JuI2bux"> {% endblock head %} {% block title %} diff --git a/webserver/web/templates/auth/register.html.tera b/webserver/web/templates/auth/register.html.tera index 2e87332d..d8516052 100644 --- a/webserver/web/templates/auth/register.html.tera +++ b/webserver/web/templates/auth/register.html.tera @@ -9,11 +9,11 @@ + integrity="sha384-IF+WRbsZQr5oU5hfhCPvBCMSdXtqctB0TpELdSoJcRPf1leOFQQbjz8InzLgpgFD"> + integrity="sha384-/X0bG33G/+qdcdtMZRL6gWteDKzsAOMlMd+vmLlk0aEUaErn2y9Nce/m1JuI2bux"> + integrity="sha384-HTYvuZHY1AndfrAqn+dIGFE7QognotxeUaFecs+e2FA30FKkHLfMyyLvBufM+eSk"> + integrity="sha384-Lo/tAxQVxUqzV/F1Zz9jmad5085ugI5TUTcZZSPlraIB6Aq0Kdeh7nWXdskGxIAE"> + integrity="sha384-SpOHsKR6B3ZYO5uf/rzzNY1FKy8ocZINBHMcGUbYNOOTftqNAg25Me3hYeIlLCr3"> + integrity="sha384-gZTaRJZ75a+mYa/4QVi1Y/bcKoC8wzbJmPA9ZO7pD5c/fbw4xejov0ou0MjsiyuM"> {% endblock head %} {% block title %} diff --git a/webserver/web/templates/paste/edit.html.tera b/webserver/web/templates/paste/edit.html.tera index bf495f26..efded981 100644 --- a/webserver/web/templates/paste/edit.html.tera +++ b/webserver/web/templates/paste/edit.html.tera @@ -30,7 +30,7 @@ + integrity="sha384-gZTaRJZ75a+mYa/4QVi1Y/bcKoC8wzbJmPA9ZO7pD5c/fbw4xejov0ou0MjsiyuM"> + integrity="sha384-pUpaSeZxPJMNsyWP4KoOd3efZ7g9I9Bvpt4i4pVdMTtsdM1kQqelw2YKyf6CalmR"> {% endblock head %} {% block title %} diff --git a/webserver/web/templates/paste/index.html.tera b/webserver/web/templates/paste/index.html.tera index c22190f3..f8a8a27a 100644 --- a/webserver/web/templates/paste/index.html.tera +++ b/webserver/web/templates/paste/index.html.tera @@ -18,7 +18,7 @@ + integrity="sha384-IkuH2Y8uTm847UgH+yhDl+R/19AmQFNFdFq6ukQHE+vZC6FgdoDHv6Pz9ipEjD/w"> + integrity="sha384-wq2OjN8RLzqETA0Qtu+2qQQE7I2PUfJGO5pMc5AlfxGQcjWYcTi3mW3tSCe2Pmd3"> + integrity="sha384-pUpaSeZxPJMNsyWP4KoOd3efZ7g9I9Bvpt4i4pVdMTtsdM1kQqelw2YKyf6CalmR"> {% endblock head %} {% block title %} diff --git a/webserver/web/templates/paste/revisions.html.tera b/webserver/web/templates/paste/revisions.html.tera index e8f01b7b..0e96d3ca 100644 --- a/webserver/web/templates/paste/revisions.html.tera +++ b/webserver/web/templates/paste/revisions.html.tera @@ -18,7 +18,7 @@ + integrity="sha384-IkuH2Y8uTm847UgH+yhDl+R/19AmQFNFdFq6ukQHE+vZC6FgdoDHv6Pz9ipEjD/w"> + integrity="sha384-wq2OjN8RLzqETA0Qtu+2qQQE7I2PUfJGO5pMc5AlfxGQcjWYcTi3mW3tSCe2Pmd3"> + integrity="sha384-pUpaSeZxPJMNsyWP4KoOd3efZ7g9I9Bvpt4i4pVdMTtsdM1kQqelw2YKyf6CalmR"> {% endblock head %} {% block title %} diff --git a/webserver/web/templates/user/index.html.tera b/webserver/web/templates/user/index.html.tera index a3aa93f3..ef253226 100644 --- a/webserver/web/templates/user/index.html.tera +++ b/webserver/web/templates/user/index.html.tera @@ -23,7 +23,7 @@ + integrity="sha384-wq2OjN8RLzqETA0Qtu+2qQQE7I2PUfJGO5pMc5AlfxGQcjWYcTi3mW3tSCe2Pmd3"> + integrity="sha384-pUpaSeZxPJMNsyWP4KoOd3efZ7g9I9Bvpt4i4pVdMTtsdM1kQqelw2YKyf6CalmR"> {% endblock head %} {% block title %}