Compare commits

...

4 Commits

8 changed files with 92 additions and 4 deletions

View File

@ -113,7 +113,7 @@
<footer id="bottom">
<a href="https://liberapay.com/robbieantenesse" target="_blank" class="small button">Support Lexiconga</a>
<a href="https://blog.lexicon.ga" target="_blank" class="small button">Blog</a>
<a href="./" target="_blank" class="small button">Advertise</a>
<a href="." target="_blank" class="small button">Advertise</a>
<a href="https://github.com/Alamantus/Lexiconga/issues" target="_blank" class="small button">Issues</a>
<a href="https://github.com/Alamantus/Lexiconga/releases" target="_blank" class="small button">Updates</a>
<span class="separator">|</span>

View File

@ -16,8 +16,8 @@
"copy-php": "cpx \"src/php/**/{*,.*}\" dist",
"serve-frontend-only": "parcel template-index.html",
"clear": "npm run clear-dist && npm run clear-cache",
"clear-dist": "rimraf dist/*",
"clear-cache": "rimraf .cache/*"
"clear-dist": "rimraf dist/{*,.*}",
"clear-cache": "rimraf .cache/{*,.*}"
},
"devDependencies": {
"autoprefixer": "^9.5.1",

View File

@ -1,3 +1,4 @@
import migrate from './js/migration';
import setupListeners from './js/setupListeners';
import { renderAll } from './js/render';
import { hasToken, addMessage } from './js/utilities';
@ -10,6 +11,8 @@ function initialize() {
addMessage('<strong>You are using the Offline version of Lexiconga.</strong><br>Refresh the page while connected to the internet to enable using accounts.', 0);
}
migrate();
loadSettings();
loadDictionary();
setupListeners();

77
src/js/migration.js Normal file
View File

@ -0,0 +1,77 @@
import { LOCAL_STORAGE_KEY } from "../constants";
export default function migrate() {
if (window.location.pathname === '/') {
if (isNotSecure()) {
sendDictionaryToHTTPS();
} else {
checkForReceived();
}
}
}
function isNotSecure() {
return window.location.host !== 'localhost' && window.location.protocol !== 'https';
}
function sendDictionaryToHTTPS() {
const storedDictionary = window.localStorage.getItem(LOCAL_STORAGE_KEY);
const httpsURL = 'https://' + window.location.host;
if (storedDictionary) {
if (!dictionaryIsOldDefault(storedDictionary)) {
const form = document.createElement('form');
form.action = httpsURL;
form.method = 'POST';
form.hidden = true;
const field = document.createElement('input');
field.name = 'oldDictionaryFromHTTP';
field.value = storedDictionary;
form.appendChild(field);
const blackoutShield = document.createElement('div');
blackoutShield.classList.add('modal-background');
document.body.appendChild(form);
document.body.appendChild(blackoutShield);
alert('You are about to be redirected to the secure https version of Lexiconga. Please update your bookmarks.')
form.submit();
return;
}
}
window.location = httpsURL;
}
function dictionaryIsOldDefault(dictionaryJSON) {
const defaultDictionary = {
name: "New",
description: "A new dictionary.",
// createdBy: publicName,
words: [],
nextWordId: 1,
settings: {
allowDuplicates: false,
caseSensitive: false,
partsOfSpeech: "Noun,Adjective,Verb,Adverb,Preposition,Pronoun,Conjunction",
sortByEquivalent: false,
isComplete: false,
isPublic: false
},
externalID: 0
}
const dictionary = JSON.parse(dictionaryJSON);
delete dictionary.createdBy;
return JSON.stringify(defaultDictionary) === JSON.stringify(dictionary);
}
function checkForReceived() {
if (window.hasOwnProperty('dictionaryImportedFromHTTP')) {
let saveOld = true;
const storedDictionary = window.localStorage.getItem(LOCAL_STORAGE_KEY);
if (storedDictionary) {
saveOld = confirm('You have an old local dictionary to import. Would you like to overwrite your current local dictionary?');
}
if (saveOld) {
window.localStorage.setItem(LOCAL_STORAGE_KEY, window.dictionaryImportedFromHTTP);
delete window.dictionaryImportedFromHTTP;
}
}
}

View File

@ -1,4 +1,5 @@
<?php
require_once(realpath(dirname(__FILE__) . '/./config.php'));
require_once(realpath(dirname(__FILE__) . '/./Response.php'));
require_once(realpath(dirname(__FILE__) . '/./User.php'));

View File

@ -123,6 +123,12 @@ switch ($view) {
</script>";
$html = str_replace('{{upup_insert}}', $upup_insert, $html);
$imported_from_http = '';
if (isset($_POST['oldDictionaryFromHTTP'])) {
$imported_from_http = '<script>window.dictionaryImportedFromHTTP = "' . addslashes($_POST['oldDictionaryFromHTTP']) . '";</script>';
}
$html = str_replace('{{imported_from_http}}', $imported_from_http, $html);
return Response::html($html);
break;

View File

@ -2,7 +2,7 @@
#title {
display: inline-block;
margin: 3px $general-padding 3px 0;
width: auto;
width: 180px;
max-height: $header-height - $general-padding;
vertical-align: middle;
}

View File

@ -7,6 +7,7 @@
<title>Lexiconga</title>
<link rel="icon" href="src/images/favicon.png" type="image/x-icon" />
<link rel="stylesheet" href="src/main.scss" />
{{imported_from_http}}
<script src="src/index.js"></script>
</head>
<body id="defaultTheme">