From ee3f5cd8eaa08cd1ec036806a41d74188ad98330 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Wed, 6 Jul 2016 17:10:29 -0600 Subject: [PATCH] Fixed markdown rendering that I accidentally broke. --- js/dictionaryBuilder.js | 14 +++++++------- js/helpers.js | 12 ++++++++++++ js/min/dictionaryBuilder.js | 2 +- js/min/helpers.js | 2 +- js/min/publicView.js | 2 +- js/min/ui.js | 2 +- js/publicView.js | 14 +++++++------- js/ui.js | 2 +- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index d6410cb..dec352a 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -234,7 +234,7 @@ function ShowDictionary() { } var dictionaryDescriptionArea = document.getElementById("dictionaryDescription"); - dictionaryDescriptionArea.innerHTML = marked(currentDictionary.description); + dictionaryDescriptionArea.innerHTML = marked(htmlEntitiesParseForMarkdown(currentDictionary.description)); var dictionaryArea = document.getElementById("theDictionary"); var dictionaryText = ""; @@ -256,7 +256,7 @@ function ShowDictionary() { } } } else { - dictionaryText = "There are no entries in the dictionary." + dictionaryText = "There are no entries in the dictionary."; } dictionaryArea.innerHTML = dictionaryText; @@ -277,14 +277,14 @@ function DictionaryEntry(itemIndex) { if (searchTerm != "" && searchByWord) { // Parse HTML Entities while searching so the regex can search actual characters instead of HTML. - wordName += htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].name).replace(searchRegEx, "$1")); + wordName += htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].name).replace(searchRegEx, "$1")).replace(/<(\/?)searchterm>/g, '<$1searchterm>'); } else { // Don't need to parse if not searching because HTML displays correctly anyway! wordName += currentDictionary.words[itemIndex].name.toString(); // Use toString() to prevent using a reference instead of the value. } if (currentDictionary.words[itemIndex].pronunciation != "") { - wordPronunciation += marked(currentDictionary.words[itemIndex].pronunciation).replace("

","").replace("

",""); + wordPronunciation += marked(htmlEntitiesParseForMarkdown(currentDictionary.words[itemIndex].pronunciation)).replace(/<\/?p>/g,""); } if (currentDictionary.words[itemIndex].partOfSpeech != " " && currentDictionary.words[itemIndex].partOfSpeech != "") { @@ -293,7 +293,7 @@ function DictionaryEntry(itemIndex) { if (currentDictionary.words[itemIndex].simpleDefinition != "") { if (searchTerm != "" && searchBySimple) { - wordSimpleDefinition += htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "$1")); + wordSimpleDefinition += htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "$1")).replace(/<(\/?)searchterm>/g, '<$1searchterm>'); } else { wordSimpleDefinition += currentDictionary.words[itemIndex].simpleDefinition.toString(); } @@ -301,9 +301,9 @@ function DictionaryEntry(itemIndex) { if (currentDictionary.words[itemIndex].longDefinition != "") { if (searchTerm != "" && searchByLong) { - wordLongDefinition += marked(htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "$1"))); + wordLongDefinition += marked(htmlEntitiesParseForMarkdown(htmlEntities(htmlEntitiesParse(currentDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "$1")))).replace(/<(\/?)searchterm>\;/g, '<$1searchterm>'); } else { - wordLongDefinition += marked(currentDictionary.words[itemIndex].longDefinition); + wordLongDefinition += marked(htmlEntitiesParseForMarkdown(currentDictionary.words[itemIndex].longDefinition)); } } diff --git a/js/helpers.js b/js/helpers.js index 83a2879..e534d42 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -6,6 +6,14 @@ function ready(fn) { } } +// Set Marked.js settings +marked.setOptions({ + gfm: true, + tables: true, + breaks: true, + sanitize: true +}); + // Get Keycode based on key name function keyCodeFor(keyName) { if (keyName == "backspace") return 8; @@ -190,6 +198,10 @@ function htmlEntitiesParse(string) { return String(string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/
/g, '\n'); } +function htmlEntitiesParseForMarkdown(string) { + return String(string).replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/
/g, '\n'); +} + function stripHtmlEntities(string) { // This is for the export name. return String(string).replace(/&/g, '').replace(/</g, '').replace(/>/g, '').replace(/"/g, '').replace(/'/g, "").replace(/\/g, '').replace(/
/g, ''); diff --git a/js/min/dictionaryBuilder.js b/js/min/dictionaryBuilder.js index bb1b198..f645d60 100644 --- a/js/min/dictionaryBuilder.js +++ b/js/min/dictionaryBuilder.js @@ -1 +1 @@ -function AddWord(){var e=htmlEntities(document.getElementById("word").value).trim(),t=htmlEntities(document.getElementById("pronunciation").value).trim(),n=htmlEntities(document.getElementById("partOfSpeech").value).trim(),i=htmlEntities(document.getElementById("simpleDefinition").value).trim(),r=htmlEntities(document.getElementById("longDefinition").value),o=document.getElementById("errorMessage"),a="",c=document.getElementById("updateConflict");if(""==e||""==i&&""==r)""==e?(a+="Word cannot be blank",a+=""==i&&""==r?" and you need at least one definition.":"."):""==i&&""==r&&(a+="You need at least one definition.");else{var s=currentDictionary.settings.allowDuplicates?-1:WordIndex(e);if(s>=0)if(WordAtIndexWasChanged(s,e,t,n,i,r)){document.getElementById("newWordButtonArea").style.display="none",DisableForm(""),c.style.display="block";var d="\""+e+'" is already in the dictionary';d+=currentDictionary.words[s].name!=e?' as "'+currentDictionary.words[s].name+'", and your dictionary is set to ignore case.':".",d+="
Do you want to update it to what you have set above?
",d+='",d+=' ',c.innerHTML=d}else a='"'+e+'" is already in the dictionary exactly as it is written above',currentDictionary.words[s].name!=e&&(a+=". (Your dictionary is currently set to ignore case.)");else currentDictionary.words.push({name:e,pronunciation:t,partOfSpeech:n.length>0?n:" ",simpleDefinition:i,longDefinition:r,wordId:currentDictionary.nextWordId++}),SaveAndUpdateWords("new"),FocusAfterAddingNewWord(),NewWordNotification(e);o.innerHTML=""}o.innerHTML=a}function ShowWordEditForm(e){var t=e.toString(),n=currentDictionary.words[e],i='

Editing '+htmlEntitiesParse(n.name)+'

';document.getElementById("entry"+t).innerHTML=i,SetPartsOfSpeech("partOfSpeech"+t),document.getElementById("partOfSpeech"+t).value=htmlEntitiesParse(n.partOfSpeech)}function CancelEditForm(e){document.getElementById("entry"+e.toString()).innerHTML=DictionaryEntry(e).replace("","").replace("","")}function EditWord(e){var t=htmlEntities(document.getElementById("word"+e).value).trim(),n=htmlEntities(document.getElementById("pronunciation"+e).value).trim(),i=htmlEntities(document.getElementById("partOfSpeech"+e).value).trim(),r=htmlEntities(document.getElementById("simpleDefinition"+e).value).trim(),o=htmlEntities(document.getElementById("longDefinition"+e).value),a=document.getElementById("errorMessage"+e),c="",s=document.getElementById("updateConflict"+e);WordAtIndexWasChanged(e,t,n,i,r,o)?(document.getElementById("editWordButtonArea"+e).style.display="none",DisableForm(e),s.style.display="block",s.innerHTML="Do you really want to change the word \""+currentDictionary.words[parseInt(e)].name+'" to what you have set above?
',s.innerHTML+='",s.innerHTML+='"):(c='No change has been made to "'+t+'"',currentDictionary.words[parseInt(e)].name!=t&&(c+=". (Your dictionary is currently set to ignore case.)")),a.innerHTML=c}function UpdateWord(e,t,n,i,r,o){currentDictionary.words[e].name=t,currentDictionary.words[e].pronunciation=n,currentDictionary.words[e].partOfSpeech=i.length>0?i:" ",currentDictionary.words[e].simpleDefinition=r,currentDictionary.words[e].longDefinition=o,SaveAndUpdateWords("update",e),window.scroll(savedScroll.x,savedScroll.y),wordFormIsLocked()||FocusAfterAddingNewWord()}function DeleteWord(e){var t=new XMLHttpRequest;t.open("POST","/php/ajax_dictionarymanagement.php?action=worddelete"),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){return 4==t.readyState&&200==t.status?("deleted successfully"!=t.responseText&&"not signed in"!=t.responseText||(currentDictionary.words.splice(e,1),SaveWords(!1)),console.log(t.responseText),!0):!1},t.send("dict="+currentDictionary.externalID.toString()+"&word="+currentDictionary.words[e].wordId.toString())}function ShowDictionary(){var e=GetSelectedFilters(),t=[],n=htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value),i=document.getElementById("searchOptionWord").checked,r=document.getElementById("searchOptionSimple").checked,o=document.getElementById("searchOptionLong").checked,a=!document.getElementById("searchCaseSensitive").checked,c=document.getElementById("searchIgnoreDiacritics").checked;if(""!=n&&(i||r||o)){var s=[],d=htmlEntitiesParseForSearch(JSON.stringify(currentDictionary));a&&(n=n.toLowerCase()),c&&(n=removeDiacritics(n),d=removeDiacritics(d)),i&&s.push("contains("+(a?"name":'translate(name, "", "")')+', "'+n+'")'),r&&s.push("contains("+(a?"simpleDefinition":'translate(simpleDefinition, "", "")')+', "'+n+'")'),o&&s.push("contains("+(a?"longDefinition":'translate(longDefinition, "", "")')+', "'+n+'")');var l=JSON.parse(d);t=JSON.search(l,"//words["+s.join(" or ")+"]/wordId")}var u=document.getElementById("dictionaryName");u.innerHTML=htmlEntitiesParse(currentDictionary.name)+" Dictionary",loggedIn&¤tDictionary.settings.isPublic&&(u.innerHTML+="");var p=document.getElementById("dictionaryDescription");p.innerHTML=marked(htmlEntitiesParse(currentDictionary.description));var y=document.getElementById("theDictionary"),m="",D=0;if(currentDictionary.words.length>0)for(var g=0;g0&&e.indexOf(currentDictionary.words[g].partOfSpeech)>-1)&&(""==n||""!=n&&(i||r||o)&&t.indexOf(currentDictionary.words[g].wordId)>=0)&&(currentDictionary.words[g].hasOwnProperty("pronunciation")||(currentDictionary.words[g].pronunciation=""),currentDictionary.words[g].hasOwnProperty("wordId")||(currentDictionary.words[g].wordId=g+1),m+=DictionaryEntry(g),D++);else m="There are no entries in the dictionary.";y.innerHTML=m,ShowFilterWordCount(D)}function DictionaryEntry(e){var t=regexParseForSearch(document.getElementById("searchBox").value),n=document.getElementById("searchOptionWord").checked,i=document.getElementById("searchOptionSimple").checked,r=document.getElementById("searchOptionLong").checked,o=!document.getElementById("searchCaseSensitive").checked,a=document.getElementById("searchIgnoreDiacritics").checked,c=new RegExp("("+(a?removeDiacritics(t)+"|"+t:t)+")","g"+(o?"i":"")),s=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return s+=""!=t&&n?htmlEntitiesParse(currentDictionary.words[e].name).replace(c,"$1"):currentDictionary.words[e].name.toString(),""!=currentDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParse(currentDictionary.words[e].pronunciation)).replace("

","").replace("

",""))," "!=currentDictionary.words[e].partOfSpeech&&""!=currentDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=currentDictionary.words[e].partOfSpeech.toString()),""!=currentDictionary.words[e].simpleDefinition&&(""!=t&&i?wordSimpleDefinition+=htmlEntitiesParse(currentDictionary.words[e].simpleDefinition).replace(c,"$1"):wordSimpleDefinition+=currentDictionary.words[e].simpleDefinition.toString()),""!=currentDictionary.words[e].longDefinition&&(""!=t&&r?wordLongDefinition+=marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition).replace(c,"$1")):wordLongDefinition+=marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition))),DictionaryEntryTemplate({name:s,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:currentDictionary.words[e].wordId.toString()},currentDictionary.settings.isComplete?!1:e)}function ManagementArea(e){var t="
";return t+="Edit",t+="Delete',t+="",t+="
"}function DictionaryEntryTemplate(e,t){t="undefined"!=typeof t?t:!1;var n="",loggedIn&¤tDictionary.settings.isPublic&&(n+=""),n+="🔗",n+=""+e.name+"",""!=e.pronunciation&&(n+=""+e.pronunciation+""),""!=e.partOfSpeech&&(n+=""+e.partOfSpeech+""),n+="
",""!=e.simpleDefinition&&(n+=""+e.simpleDefinition+""),""!=e.longDefinition&&(n+=""+e.longDefinition+""),t!==!1&&(n+=ManagementArea(t)),n+="
"}function SaveSettings(){""!=htmlEntities(document.getElementById("dictionaryNameEdit").value)&&(currentDictionary.name=htmlEntities(document.getElementById("dictionaryNameEdit").value)),currentDictionary.description=htmlEntities(document.getElementById("dictionaryDescriptionEdit").value),CheckForPartsOfSpeechChange(),currentDictionary.settings.allowDuplicates=document.getElementById("dictionaryAllowDuplicates").checked,currentDictionary.settings.caseSensitive=document.getElementById("dictionaryCaseSensitive").checked,currentDictionary.settings.sortByEquivalent=document.getElementById("dictionarySortByEquivalent").checked,currentDictionary.settings.isComplete=document.getElementById("dictionaryIsComplete").checked,document.getElementById("dictionaryIsPublic")&&(currentDictionary.settings.isPublic=document.getElementById("dictionaryIsPublic").checked),HideSettingsWhenComplete(),SaveAndUpdateDictionary(!0),LoadUserDictionaries()}function EmptyWholeDictionary(){confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")&&CreateNewDictionary()}function CreateNewDictionary(){ResetDictionaryToDefault(),SaveAndUpdateDictionary(!1),SetPartsOfSpeech(),HideSettings(),ShowSettings(),document.getElementById("dictionaryNameEdit").focus()}function DeleteCurrentDictionary(){if(confirm("This will delete the current dictionary from the database. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")){ResetDictionaryToDefault();var e=new XMLHttpRequest;e.open("POST","/php/ajax_dictionarymanagement.php?action=delete"),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){return 4==e.readyState&&200==e.status?(e.responseText.length<31?(console.log(e.responseText),CreateNewDictionary()):(HideSettings(),ShowDictionaryDeleteMenu(e.responseText),0==document.getElementById("loadAfterDelete").options.length&&(document.getElementById("loadAfterDeleteScreen").style.display="none",CreateNewDictionary())),!0):!1},e.send()}}function ResetDictionaryToDefault(){currentDictionary=JSON.parse(defaultDictionaryJSON)}function SaveAndUpdateWords(e,t){var n="";"all"==e?n=JSON.stringify(currentDictionary.words):"update"==e?n=JSON.stringify(currentDictionary.words[t]):"new"==e&&(n=JSON.stringify(currentDictionary.words[currentDictionary.words.length-1]));var i=new XMLHttpRequest;i.open("POST","/php/ajax_dictionarymanagement.php?action=word"+e+"&dict="+currentDictionary.externalID.toString()+"&nextwordid="+currentDictionary.nextWordId.toString()),i.setRequestHeader("Content-Type","application/json; charset=UTF-8"),i.onreadystatechange=function(){return 4==i.readyState&&200==i.status?(SaveWords(),ClearForm(),console.log(i.responseText),!0):!1},i.send(n)}function SaveWords(){currentDictionary.settings.sortByEquivalent?currentDictionary.words.sort(dynamicSort(["simpleDefinition","partOfSpeech"])):currentDictionary.words.sort(dynamicSort(["name","partOfSpeech"])),SaveDictionary(!1),ProcessLoad()}function SaveAndUpdateDictionary(e){SaveDictionary(!0),ShowDictionary(),e||ClearForm(),CloseUpdateConflictArea("")}function SaveDictionary(e){e&&SendDictionary(),localStorage.setItem("dictionary",JSON.stringify(currentDictionary)),SavePreviousDictionary()}function SendDictionary(){var e="",t="";currentDictionary.externalID>0?(e="update",t=DataToSend(!1)):(e="new",t=DataToSend(!0));var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action="+e),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){return 4==n.readyState&&200==n.status?("updated successfully"==n.responseText?(console.log(n.responseText),LoadUserDictionaries(),ProcessLoad()):isNaN(parseInt(n.responseText))?console.log(n.responseText):(currentDictionary.externalID=parseInt(n.responseText),currentDictionary.words.length>0&&SaveAndUpdateWords("all"),LoadUserDictionaries(),ProcessLoad(),console.log("saved "+parseInt(n.responseText).toString()+" successfully")),!0):!1},n.send(t)}function DataToSend(e){e="undefined"!=typeof e&&null!=e?e:!1;var t="";return 0==currentDictionary.externalID?(t="name="+encodeURIComponent(currentDictionary.name)+"&description="+encodeURIComponent(currentDictionary.description)+"&words="+encodeURIComponent(JSON.stringify(currentDictionary.words)),t+="&nextwordid="+currentDictionary.nextWordId+"&allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")+"&casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0"),t+="&partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)+"&sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")+"&iscomplete="+(currentDictionary.settings.isComplete?"1":"0")+"&ispublic="+(currentDictionary.settings.isPublic?"1":"0")):((e||currentDictionary.name!=previousDictionary.name)&&(t+="name="+encodeURIComponent(currentDictionary.name)),(e||currentDictionary.description!=previousDictionary.description)&&(t+=(""==t?"":"&")+"description="+encodeURIComponent(currentDictionary.description)),(e||currentDictionary.nextWordId!=previousDictionary.nextWordId)&&(t+=(""==t?"":"&")+"nextwordid="+currentDictionary.nextWordId),(e||currentDictionary.settings.allowDuplicates!=previousDictionary.allowDuplicates)&&(t+=(""==t?"":"&")+"allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")),(e||currentDictionary.settings.caseSensitive!=previousDictionary.caseSensitive)&&(t+=(""==t?"":"&")+"casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0")),(e||currentDictionary.settings.partsOfSpeech!=previousDictionary.partsOfSpeech)&&(t+=(""==t?"":"&")+"partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)),(e||currentDictionary.settings.sortByEquivalent!=previousDictionary.sortByEquivalent)&&(t+=(""==t?"":"&")+"sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")),(e||currentDictionary.settings.isComplete!=previousDictionary.isComplete)&&(t+=(""==t?"":"&")+"iscomplete="+(currentDictionary.settings.isComplete?"1":"0")),(e||currentDictionary.settings.isPublic!=previousDictionary.isPublic)&&(t+=(""==t?"":"&")+"ispublic="+(currentDictionary.settings.isPublic?"1":"0"))),t}function LoadDictionary(){LoadLocalDictionary();var e=new XMLHttpRequest;e.open("GET","/php/ajax_dictionarymanagement.php?action=load"),e.onreadystatechange=function(){4==e.readyState&&200==e.status&&("no dictionaries"==e.responseText?(currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SendDictionary(!0)):e.responseText.length<60?console.log(e.responseText):(currentDictionary=JSON.parse(e.responseText),SaveDictionary(!1))),ProcessLoad()},e.send()}function ChangeDictionary(e){e="undefined"!=typeof e&&null!=e?e:document.getElementById("userDictionaries"),currentDictionary.externalID!=e.value&&e.options.length>0&&(ShowInfoWithText("

Loading "+e.options[e.selectedIndex].text+"...

"),HideSettings(),ChangeDictionaryToId(e.value,function(e){"no dictionaries"==e?(console.log(e),SendDictionary(!1)):e.length<60?console.log(e):(currentDictionary=JSON.parse(e),SaveDictionary(!1),ProcessLoad(),LoadUserDictionaries(),HideInfo())}))}function ChangeDictionaryToId(e,t){var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action=switch"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded");var i="newdictionaryid="+e.toString();n.onreadystatechange=function(){4==n.readyState&&200==n.status&&t(n.responseText)},n.send(i)}function LoadLocalDictionary(){if(localStorage.getItem("dictionary")){var e=JSON.parse(localStorage.getItem("dictionary"));(e.words.length>0||"A new dictionary."!=e.description||"New"!=e.name)&&(currentDictionary=JSON.parse(localStorage.getItem("dictionary"))),e=null}}function ProcessLoad(){currentDictionary.hasOwnProperty("nextWordId")||(currentDictionary.nextWordId=currentDictionary.words.length+1),HideSettingsWhenComplete(),ShowDictionary(),SetPartsOfSpeech(),currentDictionary.settings.isComplete&&(document.getElementById("wordEntryForm").style.display="none"),SavePreviousDictionary()}function SavePreviousDictionary(){previousDictionary={name:currentDictionary.name,description:currentDictionary.description,nextWordId:currentDictionary.nextWordId,allowDuplicates:currentDictionary.settings.allowDuplicates,caseSensitive:currentDictionary.settings.caseSensitive,partsOfSpeech:currentDictionary.settings.partsOfSpeech,sortByEquivalent:currentDictionary.settings.sortByEquivalent,isComplete:currentDictionary.settings.isComplete,isPublic:currentDictionary.settings.isPublic}}function ExportDictionary(){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),download(e+".dict",localStorage.getItem("dictionary"))}function ExportWords(){if(currentDictionary.words.length>0){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),e+="_words";for(var t="word,pronunciation,part of speech,equivalent,explanation\n",n=0;n0||confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;var e=new FileReader;if(document.getElementById("importFile").files.length>0){var t=document.getElementById("importFile").files[0];e.readAsText(t),e.onloadend=function(){if(e.result&&e.result.length){var t=JSON.parse(e.result);if(t.hasOwnProperty("name")&&t.hasOwnProperty("description")&&t.hasOwnProperty("words")&&t.hasOwnProperty("settings"))currentDictionary=JSON.parse(e.result),currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SaveDictionary(!0),ProcessLoad(),HideInfo(),HideSettings(),document.getElementById("importFile").value="",NewNotification('Successfully Imported the "'+currentDictionary.name+'" Dictionary.');else{var n="File is missing:";t.hasOwnProperty("name")||(n+=" name"),t.hasOwnProperty("description")||(n+=" description"),t.hasOwnProperty("words")||(n+=" words"),t.hasOwnProperty("settings")||(n+=" settings"),alert("Uploaded file is not compatible.\n\n"+n)}t=null}else alert("Upload Failed");e=null}}else alert("You must add a file to import.")}}function ImportWords(){if(currentDictionary.externalID>0||confirm("This will add words in a correctly formatted CSV file to your currently loaded dictionary. Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;if(document.getElementById("importWordsCSV").files.length>0){var e=document.getElementById("importWordsCSV").files[0],t=document.getElementById("importOptions");t.innerHTML="

Importing Words...

";var n=0,i=0;Papa.parse(e,{header:!0,step:function(e,r){if(n++,e.data[0].word.trim().length>0&&(e.data[0].equivalent.trim().length>0||e.data[0].explanation.trim().length>0)||0==e.errors.length){var o=htmlEntities(e.data[0].word).trim(),a=htmlEntities(e.data[0].pronunciation).trim(),c=htmlEntities(e.data[0]["part of speech"]).trim().length>0?htmlEntities(e.data[0]["part of speech"]).trim():" ",s=htmlEntities(e.data[0].equivalent).trim(),d=htmlEntities(e.data[0].explanation).trim(),l=currentDictionary.nextWordId++;currentDictionary.words.push({name:o,pronunciation:a,partOfSpeech:c,simpleDefinition:s,longDefinition:d,wordId:l});var u=DictionaryEntryTemplate(currentDictionary.words[currentDictionary.words.length-1]);t.innerHTML+=u,i++}else if(e.data[0].word.trim().length>0)for(var p=0;pError on record #"+n.toString()+": "+e.errors[p].message+"

";document.getElementById("infoPage").scrollTop=document.getElementById("infoPage").scrollHeight},complete:function(e){SaveAndUpdateWords("all"),t.innerHTML+="

The file has finished importing "+i.toString()+" words.

",NewNotification("Imported "+i.toString()+" words."),document.getElementById("importOptions").scrollTop=document.getElementById("importOptions").scrollHeight,document.getElementById("numberOfWordsInDictionary").innerHTML=currentDictionary.words.length.toString()}})}else alert("You must add a file to import.")}}function WordIndex(e,t){for(var n=0;n=0)if(WordAtIndexWasChanged(s,e,t,n,i,r)){document.getElementById("newWordButtonArea").style.display="none",DisableForm(""),c.style.display="block";var d="\""+e+'" is already in the dictionary';d+=currentDictionary.words[s].name!=e?' as "'+currentDictionary.words[s].name+'", and your dictionary is set to ignore case.':".",d+="
Do you want to update it to what you have set above?
",d+='",d+=' ',c.innerHTML=d}else a='"'+e+'" is already in the dictionary exactly as it is written above',currentDictionary.words[s].name!=e&&(a+=". (Your dictionary is currently set to ignore case.)");else currentDictionary.words.push({name:e,pronunciation:t,partOfSpeech:n.length>0?n:" ",simpleDefinition:i,longDefinition:r,wordId:currentDictionary.nextWordId++}),SaveAndUpdateWords("new"),FocusAfterAddingNewWord(),NewWordNotification(e);o.innerHTML=""}o.innerHTML=a}function ShowWordEditForm(e){var t=e.toString(),n=currentDictionary.words[e],i='

Editing '+n.name+'

';document.getElementById("entry"+t).innerHTML=i,SetPartsOfSpeech("partOfSpeech"+t),document.getElementById("partOfSpeech"+t).value=htmlEntitiesParse(n.partOfSpeech)}function CancelEditForm(e){document.getElementById("entry"+e.toString()).innerHTML=DictionaryEntry(e).replace("","").replace("","")}function EditWord(e){var t=htmlEntities(document.getElementById("word"+e).value).trim(),n=htmlEntities(document.getElementById("pronunciation"+e).value).trim(),i=htmlEntities(document.getElementById("partOfSpeech"+e).value).trim(),r=htmlEntities(document.getElementById("simpleDefinition"+e).value).trim(),o=htmlEntities(document.getElementById("longDefinition"+e).value),a=document.getElementById("errorMessage"+e),c="",s=document.getElementById("updateConflict"+e);WordAtIndexWasChanged(e,t,n,i,r,o)?(document.getElementById("editWordButtonArea"+e).style.display="none",DisableForm(e),s.style.display="block",s.innerHTML="Do you really want to change the word \""+currentDictionary.words[parseInt(e)].name+'" to what you have set above?
',s.innerHTML+='",s.innerHTML+='"):(c='No change has been made to "'+t+'"',currentDictionary.words[parseInt(e)].name!=t&&(c+=". (Your dictionary is currently set to ignore case.)")),a.innerHTML=c}function UpdateWord(e,t,n,i,r,o){currentDictionary.words[e].name=t,currentDictionary.words[e].pronunciation=n,currentDictionary.words[e].partOfSpeech=i.length>0?i:" ",currentDictionary.words[e].simpleDefinition=r,currentDictionary.words[e].longDefinition=o,SaveAndUpdateWords("update",e),window.scroll(savedScroll.x,savedScroll.y),wordFormIsLocked()||FocusAfterAddingNewWord()}function DeleteWord(e){var t=new XMLHttpRequest;t.open("POST","/php/ajax_dictionarymanagement.php?action=worddelete"),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){return 4==t.readyState&&200==t.status?("deleted successfully"!=t.responseText&&"not signed in"!=t.responseText||(currentDictionary.words.splice(e,1),SaveWords(!1)),console.log(t.responseText),!0):!1},t.send("dict="+currentDictionary.externalID.toString()+"&word="+currentDictionary.words[e].wordId.toString())}function ShowDictionary(){var e=GetSelectedFilters(),t=[],n=htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value),i=document.getElementById("searchOptionWord").checked,r=document.getElementById("searchOptionSimple").checked,o=document.getElementById("searchOptionLong").checked,a=!document.getElementById("searchCaseSensitive").checked,c=document.getElementById("searchIgnoreDiacritics").checked;if(""!=n&&(i||r||o)){var s=[],d=htmlEntitiesParseForSearch(JSON.stringify(currentDictionary));a&&(n=n.toLowerCase()),c&&(n=removeDiacritics(n),d=removeDiacritics(d)),i&&s.push("contains("+(a?"name":'translate(name, "", "")')+', "'+n+'")'),r&&s.push("contains("+(a?"simpleDefinition":'translate(simpleDefinition, "", "")')+', "'+n+'")'),o&&s.push("contains("+(a?"longDefinition":'translate(longDefinition, "", "")')+', "'+n+'")');var l=JSON.parse(d);t=JSON.search(l,"//words["+s.join(" or ")+"]/wordId")}var u=document.getElementById("dictionaryName");u.innerHTML=currentDictionary.name+" Dictionary",loggedIn&¤tDictionary.settings.isPublic&&(u.innerHTML+="");var p=document.getElementById("dictionaryDescription");p.innerHTML=marked(htmlEntitiesParseForMarkdown(currentDictionary.description));var y=document.getElementById("theDictionary"),m="",D=0;if(currentDictionary.words.length>0)for(var g=0;g0&&e.indexOf(currentDictionary.words[g].partOfSpeech)>-1)&&(""==n||""!=n&&(i||r||o)&&t.indexOf(currentDictionary.words[g].wordId)>=0)&&(currentDictionary.words[g].hasOwnProperty("pronunciation")||(currentDictionary.words[g].pronunciation=""),currentDictionary.words[g].hasOwnProperty("wordId")||(currentDictionary.words[g].wordId=g+1),m+=DictionaryEntry(g),D++);else m="There are no entries in the dictionary.";y.innerHTML=m,ShowFilterWordCount(D)}function DictionaryEntry(e){var t=regexParseForSearch(document.getElementById("searchBox").value),n=document.getElementById("searchOptionWord").checked,i=document.getElementById("searchOptionSimple").checked,r=document.getElementById("searchOptionLong").checked,o=!document.getElementById("searchCaseSensitive").checked,a=document.getElementById("searchIgnoreDiacritics").checked,c=new RegExp("("+(a?removeDiacritics(t)+"|"+t:t)+")","g"+(o?"i":"")),s=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return s+=""!=t&&n?htmlEntities(htmlEntitiesParse(currentDictionary.words[e].name).replace(c,"$1")).replace(/<(\/?)searchterm>/g,"<$1searchterm>"):currentDictionary.words[e].name.toString(),""!=currentDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParseForMarkdown(currentDictionary.words[e].pronunciation)).replace(/<\/?p>/g,""))," "!=currentDictionary.words[e].partOfSpeech&&""!=currentDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=currentDictionary.words[e].partOfSpeech.toString()),""!=currentDictionary.words[e].simpleDefinition&&(""!=t&&i?wordSimpleDefinition+=htmlEntities(htmlEntitiesParse(currentDictionary.words[e].simpleDefinition).replace(c,"$1")).replace(/<(\/?)searchterm>/g,"<$1searchterm>"):wordSimpleDefinition+=currentDictionary.words[e].simpleDefinition.toString()),""!=currentDictionary.words[e].longDefinition&&(""!=t&&r?wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(htmlEntities(htmlEntitiesParse(currentDictionary.words[e].longDefinition).replace(c,"$1")))).replace(/<(\/?)searchterm>\;/g,"<$1searchterm>"):wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(currentDictionary.words[e].longDefinition))),DictionaryEntryTemplate({name:s,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:currentDictionary.words[e].wordId.toString()},currentDictionary.settings.isComplete?!1:e)}function ManagementArea(e){var t="
";return t+="Edit",t+="Delete',t+="",t+="
"}function DictionaryEntryTemplate(e,t){t="undefined"!=typeof t?t:!1;var n="",loggedIn&¤tDictionary.settings.isPublic&&(n+=""),n+="🔗",n+=""+e.name+"",""!=e.pronunciation&&(n+=""+e.pronunciation+""),""!=e.partOfSpeech&&(n+=""+e.partOfSpeech+""),n+="
",""!=e.simpleDefinition&&(n+=""+e.simpleDefinition+""),""!=e.longDefinition&&(n+=""+e.longDefinition+""),t!==!1&&(n+=ManagementArea(t)),n+="
"}function SaveSettings(){""!=htmlEntities(document.getElementById("dictionaryNameEdit").value)&&(currentDictionary.name=htmlEntities(document.getElementById("dictionaryNameEdit").value)),currentDictionary.description=htmlEntities(document.getElementById("dictionaryDescriptionEdit").value),CheckForPartsOfSpeechChange(),currentDictionary.settings.allowDuplicates=document.getElementById("dictionaryAllowDuplicates").checked,currentDictionary.settings.caseSensitive=document.getElementById("dictionaryCaseSensitive").checked,currentDictionary.settings.sortByEquivalent=document.getElementById("dictionarySortByEquivalent").checked,currentDictionary.settings.isComplete=document.getElementById("dictionaryIsComplete").checked,document.getElementById("dictionaryIsPublic")&&(currentDictionary.settings.isPublic=document.getElementById("dictionaryIsPublic").checked),HideSettingsWhenComplete(),SaveAndUpdateDictionary(!0),LoadUserDictionaries()}function EmptyWholeDictionary(){confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")&&CreateNewDictionary()}function CreateNewDictionary(){ResetDictionaryToDefault(),SaveAndUpdateDictionary(!1),SetPartsOfSpeech(),HideSettings(),ShowSettings(),document.getElementById("dictionaryNameEdit").focus()}function DeleteCurrentDictionary(){if(confirm("This will delete the current dictionary from the database. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")){ResetDictionaryToDefault();var e=new XMLHttpRequest;e.open("POST","/php/ajax_dictionarymanagement.php?action=delete"),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){return 4==e.readyState&&200==e.status?(e.responseText.length<31?(console.log(e.responseText),CreateNewDictionary()):(HideSettings(),ShowDictionaryDeleteMenu(e.responseText),0==document.getElementById("loadAfterDelete").options.length&&(document.getElementById("loadAfterDeleteScreen").style.display="none",CreateNewDictionary())),!0):!1},e.send()}}function ResetDictionaryToDefault(){currentDictionary=JSON.parse(defaultDictionaryJSON)}function SaveAndUpdateWords(e,t){var n="";"all"==e?n=JSON.stringify(currentDictionary.words):"update"==e?n=JSON.stringify(currentDictionary.words[t]):"new"==e&&(n=JSON.stringify(currentDictionary.words[currentDictionary.words.length-1]));var i=new XMLHttpRequest;i.open("POST","/php/ajax_dictionarymanagement.php?action=word"+e+"&dict="+currentDictionary.externalID.toString()+"&nextwordid="+currentDictionary.nextWordId.toString()),i.setRequestHeader("Content-Type","application/json; charset=UTF-8"),i.onreadystatechange=function(){return 4==i.readyState&&200==i.status?(SaveWords(),ClearForm(),console.log(i.responseText),!0):!1},i.send(n)}function SaveWords(){currentDictionary.settings.sortByEquivalent?currentDictionary.words.sort(dynamicSort(["simpleDefinition","partOfSpeech"])):currentDictionary.words.sort(dynamicSort(["name","partOfSpeech"])),SaveDictionary(!1),ProcessLoad()}function SaveAndUpdateDictionary(e){SaveDictionary(!0),ShowDictionary(),e||ClearForm(),CloseUpdateConflictArea("")}function SaveDictionary(e){e&&SendDictionary(),localStorage.setItem("dictionary",JSON.stringify(currentDictionary)),SavePreviousDictionary()}function SendDictionary(){var e="",t="";currentDictionary.externalID>0?(e="update",t=DataToSend(!1)):(e="new",t=DataToSend(!0));var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action="+e),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){return 4==n.readyState&&200==n.status?("updated successfully"==n.responseText?(console.log(n.responseText),LoadUserDictionaries(),ProcessLoad()):isNaN(parseInt(n.responseText))?console.log(n.responseText):(currentDictionary.externalID=parseInt(n.responseText),currentDictionary.words.length>0&&SaveAndUpdateWords("all"),LoadUserDictionaries(),ProcessLoad(),console.log("saved "+parseInt(n.responseText).toString()+" successfully")),!0):!1},n.send(t)}function DataToSend(e){e="undefined"!=typeof e&&null!=e?e:!1;var t="";return 0==currentDictionary.externalID?(t="name="+encodeURIComponent(currentDictionary.name)+"&description="+encodeURIComponent(currentDictionary.description)+"&words="+encodeURIComponent(JSON.stringify(currentDictionary.words)),t+="&nextwordid="+currentDictionary.nextWordId+"&allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")+"&casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0"),t+="&partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)+"&sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")+"&iscomplete="+(currentDictionary.settings.isComplete?"1":"0")+"&ispublic="+(currentDictionary.settings.isPublic?"1":"0")):((e||currentDictionary.name!=previousDictionary.name)&&(t+="name="+encodeURIComponent(currentDictionary.name)),(e||currentDictionary.description!=previousDictionary.description)&&(t+=(""==t?"":"&")+"description="+encodeURIComponent(currentDictionary.description)),(e||currentDictionary.nextWordId!=previousDictionary.nextWordId)&&(t+=(""==t?"":"&")+"nextwordid="+currentDictionary.nextWordId),(e||currentDictionary.settings.allowDuplicates!=previousDictionary.allowDuplicates)&&(t+=(""==t?"":"&")+"allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")),(e||currentDictionary.settings.caseSensitive!=previousDictionary.caseSensitive)&&(t+=(""==t?"":"&")+"casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0")),(e||currentDictionary.settings.partsOfSpeech!=previousDictionary.partsOfSpeech)&&(t+=(""==t?"":"&")+"partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)),(e||currentDictionary.settings.sortByEquivalent!=previousDictionary.sortByEquivalent)&&(t+=(""==t?"":"&")+"sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")),(e||currentDictionary.settings.isComplete!=previousDictionary.isComplete)&&(t+=(""==t?"":"&")+"iscomplete="+(currentDictionary.settings.isComplete?"1":"0")),(e||currentDictionary.settings.isPublic!=previousDictionary.isPublic)&&(t+=(""==t?"":"&")+"ispublic="+(currentDictionary.settings.isPublic?"1":"0"))),t}function LoadDictionary(){LoadLocalDictionary();var e=new XMLHttpRequest;e.open("GET","/php/ajax_dictionarymanagement.php?action=load"),e.onreadystatechange=function(){4==e.readyState&&200==e.status&&("no dictionaries"==e.responseText?(currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SendDictionary(!0)):e.responseText.length<60?console.log(e.responseText):(currentDictionary=JSON.parse(e.responseText),SaveDictionary(!1))),ProcessLoad()},e.send()}function ChangeDictionary(e){e="undefined"!=typeof e&&null!=e?e:document.getElementById("userDictionaries"),currentDictionary.externalID!=e.value&&e.options.length>0&&(ShowInfoWithText("

Loading "+e.options[e.selectedIndex].text+"...

"),HideSettings(),ChangeDictionaryToId(e.value,function(e){"no dictionaries"==e?(console.log(e),SendDictionary(!1)):e.length<60?console.log(e):(currentDictionary=JSON.parse(e),SaveDictionary(!1),ProcessLoad(),LoadUserDictionaries(),HideInfo())}))}function ChangeDictionaryToId(e,t){var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action=switch"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded");var i="newdictionaryid="+e.toString();n.onreadystatechange=function(){4==n.readyState&&200==n.status&&t(n.responseText)},n.send(i)}function LoadLocalDictionary(){if(localStorage.getItem("dictionary")){var e=JSON.parse(localStorage.getItem("dictionary"));(e.words.length>0||"A new dictionary."!=e.description||"New"!=e.name)&&(currentDictionary=JSON.parse(localStorage.getItem("dictionary"))),e=null}}function ProcessLoad(){currentDictionary.hasOwnProperty("nextWordId")||(currentDictionary.nextWordId=currentDictionary.words.length+1),HideSettingsWhenComplete(),ShowDictionary(),SetPartsOfSpeech(),currentDictionary.settings.isComplete&&(document.getElementById("wordEntryForm").style.display="none"),SavePreviousDictionary()}function SavePreviousDictionary(){previousDictionary={name:currentDictionary.name,description:currentDictionary.description,nextWordId:currentDictionary.nextWordId,allowDuplicates:currentDictionary.settings.allowDuplicates,caseSensitive:currentDictionary.settings.caseSensitive,partsOfSpeech:currentDictionary.settings.partsOfSpeech,sortByEquivalent:currentDictionary.settings.sortByEquivalent,isComplete:currentDictionary.settings.isComplete,isPublic:currentDictionary.settings.isPublic}}function ExportDictionary(){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),download(e+".dict",localStorage.getItem("dictionary"))}function ExportWords(){if(currentDictionary.words.length>0){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),e+="_words";for(var t="word,pronunciation,part of speech,definition,explanation\n",n=0;n0||confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;var e=new FileReader;if(document.getElementById("importFile").files.length>0){var t=document.getElementById("importFile").files[0];e.readAsText(t),e.onloadend=function(){if(e.result&&e.result.length){var t=JSON.parse(e.result);if(t.hasOwnProperty("name")&&t.hasOwnProperty("description")&&t.hasOwnProperty("words")&&t.hasOwnProperty("settings"))currentDictionary=JSON.parse(e.result),currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SaveDictionary(!0),ProcessLoad(),HideInfo(),HideSettings(),document.getElementById("importFile").value="",NewNotification('Successfully Imported the "'+currentDictionary.name+'" Dictionary.');else{var n="File is missing:";t.hasOwnProperty("name")||(n+=" name"),t.hasOwnProperty("description")||(n+=" description"),t.hasOwnProperty("words")||(n+=" words"),t.hasOwnProperty("settings")||(n+=" settings"),alert("Uploaded file is not compatible.\n\n"+n)}t=null}else alert("Upload Failed");e=null}}else alert("You must add a file to import.")}}function ImportWords(){if(currentDictionary.externalID>0||confirm("This will add words in a correctly formatted CSV file to your currently loaded dictionary. Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;if(document.getElementById("importWordsCSV").files.length>0){var e=document.getElementById("importWordsCSV").files[0],t=document.getElementById("importOptions");t.innerHTML="

Importing Words...

";var n=0,i=0;Papa.parse(e,{header:!0,step:function(e,r){if(n++,e.data[0].word.trim().length>0&&(e.data[0].definition.trim().length>0||e.data[0].explanation.trim().length>0)||0==e.errors.length){var o=htmlEntities(e.data[0].word).trim(),a=htmlEntities(e.data[0].pronunciation).trim(),c=htmlEntities(e.data[0]["part of speech"]).trim().length>0?htmlEntities(e.data[0]["part of speech"]).trim():" ",s=htmlEntities(e.data[0].definition).trim(),d=htmlEntities(e.data[0].explanation).trim(),l=currentDictionary.nextWordId++;currentDictionary.words.push({name:o,pronunciation:a,partOfSpeech:c,simpleDefinition:s,longDefinition:d,wordId:l});var u=DictionaryEntryTemplate(currentDictionary.words[currentDictionary.words.length-1]);t.innerHTML+=u,i++}else if(e.data[0].word.trim().length>0)for(var p=0;pError on record #"+n.toString()+": "+e.errors[p].message+"

";document.getElementById("infoPage").scrollTop=document.getElementById("infoPage").scrollHeight},complete:function(e){SaveAndUpdateWords("all"),t.innerHTML+="

The file has finished importing "+i.toString()+" words.

",NewNotification("Imported "+i.toString()+" words."),document.getElementById("importOptions").scrollTop=document.getElementById("importOptions").scrollHeight,document.getElementById("numberOfWordsInDictionary").innerHTML=currentDictionary.words.length.toString()}})}else alert("You must add a file to import.")}}function WordIndex(e,t){for(var n=0;n-1?o=l=a:(o=-r.moveStart("character",-a),o+=t.slice(0,o).split("\n").length-1,r.compareEndPoints("EndToEnd",c)>-1?l=a:(l=-r.moveEnd("character",-a),l+=t.slice(0,l).split("\n").length-1)))),{start:o,end:l}}function setSelectionRange(e,t,n){if(e.setSelectionRange)e.focus(),e.setSelectionRange(t,n);else if(e.createTextRange){var r=e.createTextRange();r.collapse(!0),r.moveEnd("character",n),r.moveStart("character",t),r.select()}}function SaveScroll(){var e=document.documentElement,t=(window.pageXOffset||e.scrollLeft)-(e.clientLeft||0),n=(window.pageYOffset||e.scrollTop)-(e.clientTop||0);savedScroll.x=t,savedScroll.y=n}function htmlEntities(e){return String(e).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\\/g,"\").replace(/\n/g,"
")}function htmlEntitiesParse(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/\/g,"\\").replace(/
/g,"\n")}function stripHtmlEntities(e){return String(e).replace(/&/g,"").replace(/</g,"").replace(/>/g,"").replace(/"/g,"").replace(/'/g,"").replace(/\/g,"").replace(/
/g,"")}function htmlEntitiesParseForSearchEntry(e){return String(e).replace(/"/g,"%%%%").replace(/'/g,"````")}function htmlEntitiesParseForSearch(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"%%%%").replace(/'/g,"````")}function regexParseForSearch(e){return String(e).replace(/([\[\\\^\$\.\|\?\*\+\(\)\{\}\]])/g,"\\$1")}function dynamicSort(e){return function(t,n){return e.map(function(e){var r=1;return"-"===e[0]&&(r=-1,e=e.substring(1)),removeDiacritics(t[e]).toLowerCase()>removeDiacritics(n[e]).toLowerCase()?r:removeDiacritics(t[e]).toLowerCase()-1?o=l=a:(o=-n.moveStart("character",-a),o+=t.slice(0,o).split("\n").length-1,n.compareEndPoints("EndToEnd",c)>-1?l=a:(l=-n.moveEnd("character",-a),l+=t.slice(0,l).split("\n").length-1)))),{start:o,end:l}}function setSelectionRange(e,t,r){if(e.setSelectionRange)e.focus(),e.setSelectionRange(t,r);else if(e.createTextRange){var n=e.createTextRange();n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n.select()}}function SaveScroll(){var e=document.documentElement,t=(window.pageXOffset||e.scrollLeft)-(e.clientLeft||0),r=(window.pageYOffset||e.scrollTop)-(e.clientTop||0);savedScroll.x=t,savedScroll.y=r}function htmlEntities(e){return String(e).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\\/g,"\").replace(/\n/g,"
")}function htmlEntitiesParse(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/\/g,"\\").replace(/
/g,"\n")}function htmlEntitiesParseForMarkdown(e){return String(e).replace(/"/g,'"').replace(/'/g,"'").replace(/\/g,"\\").replace(/
/g,"\n")}function stripHtmlEntities(e){return String(e).replace(/&/g,"").replace(/</g,"").replace(/>/g,"").replace(/"/g,"").replace(/'/g,"").replace(/\/g,"").replace(/
/g,"")}function htmlEntitiesParseForSearchEntry(e){return String(e).replace(/"/g,"%%%%").replace(/'/g,"````")}function htmlEntitiesParseForSearch(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"%%%%").replace(/'/g,"````")}function regexParseForSearch(e){return String(e).replace(/([\[\\\^\$\.\|\?\*\+\(\)\{\}\]])/g,"\\$1")}function dynamicSort(e){return function(t,r){return e.map(function(e){var n=1;return"-"===e[0]&&(n=-1,e=e.substring(1)),removeDiacritics(t[e]).toLowerCase()>removeDiacritics(r[e]).toLowerCase()?n:removeDiacritics(t[e]).toLowerCase()Note: This dictionary is not yet complete and is likely to change.");var h=document.getElementById("dictionaryDescription");h.innerHTML=marked(htmlEntitiesParse(publicDictionary.description));var D=document.getElementById("theDictionary"),f="",g=0;if(publicDictionary.words.length>0)for(var w=0;w0&&i.indexOf(publicDictionary.words[w].partOfSpeech)>-1)&&(""==t||""!=t&&(r||o||c)&&n.indexOf(publicDictionary.words[w].wordId)>=0)&&(publicDictionary.words[w].hasOwnProperty("pronunciation")||(publicDictionary.words[w].pronunciation=""),publicDictionary.words[w].hasOwnProperty("wordId")||(publicDictionary.words[w].wordId=w+1),f+=PublicDictionaryEntry(w,e),g++);else f="There are no entries in the dictionary.";D.innerHTML=f,e||ShowFilterWordCount(g)}else document.getElementById("dictionaryContainer").innerHTML=publicDictionary}function PublicDictionaryEntry(e,i){var n=i?"":regexParseForSearch(document.getElementById("searchBox").value),t=i?!1:document.getElementById("searchOptionWord").checked,r=i?!1:document.getElementById("searchOptionSimple").checked,o=i?!1:document.getElementById("searchOptionLong").checked,c=i?!1:!document.getElementById("searchCaseSensitive").checked,a=i?!1:document.getElementById("searchIgnoreDiacritics").checked,l=new RegExp("("+(a?removeDiacritics(n)+"|"+n:n)+")","g"+(c?"i":"")),d=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return d+=""!=n&&t?htmlEntitiesParse(publicDictionary.words[e].name).replace(l,"$1"):publicDictionary.words[e].name.toString(),""!=publicDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParse(publicDictionary.words[e].pronunciation)).replace("

","").replace("

","")),""!=publicDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=publicDictionary.words[e].partOfSpeech.toString()),""!=publicDictionary.words[e].simpleDefinition&&(""!=n&&r?wordSimpleDefinition+=htmlEntitiesParse(publicDictionary.words[e].simpleDefinition).replace(l,"$1"):wordSimpleDefinition+=publicDictionary.words[e].simpleDefinition.toString()),""!=publicDictionary.words[e].longDefinition&&(""!=n&&o?wordLongDefinition+=marked(htmlEntitiesParse(publicDictionary.words[e].longDefinition).replace(l,"$1")):wordLongDefinition+=marked(htmlEntitiesParse(publicDictionary.words[e].longDefinition))),PublicDictionaryEntryTemplate({name:d,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:publicDictionary.words[e].wordId.toString()},!1)}function PublicDictionaryEntryTemplate(e,i){i="undefined"!=typeof i?i:!1;var n="",n+=""+e.name+"",""!=e.pronunciation&&(n+=""+e.pronunciation+""),""!=e.partOfSpeech&&(n+=""+e.partOfSpeech+""),n+="
",""!=e.simpleDefinition&&(n+=""+e.simpleDefinition+""),""!=e.longDefinition&&(n+=""+e.longDefinition+""),i!==!1&&(n+=ManagementArea(i)),n+="
"}function SetPublicPartsOfSpeech(){for(var e=document.getElementById("filterOptions"),i=htmlEntitiesParse(publicDictionary.settings.partsOfSpeech).trim().split(","),n=0;nNote: This dictionary is not yet complete and is likely to change.");var y=document.getElementById("dictionaryDescription");y.innerHTML=marked(htmlEntitiesParseForMarkdown(publicDictionary.description));var D=document.getElementById("theDictionary"),f="",g=0;if(publicDictionary.words.length>0)for(var w=0;w0&&i.indexOf(publicDictionary.words[w].partOfSpeech)>-1)&&(""==t||""!=t&&(r||o||c)&&n.indexOf(publicDictionary.words[w].wordId)>=0)&&(publicDictionary.words[w].hasOwnProperty("pronunciation")||(publicDictionary.words[w].pronunciation=""),publicDictionary.words[w].hasOwnProperty("wordId")||(publicDictionary.words[w].wordId=w+1),f+=PublicDictionaryEntry(w,e),g++);else f="There are no entries in the dictionary.";D.innerHTML=f,e||ShowFilterWordCount(g)}else document.getElementById("dictionaryContainer").innerHTML=publicDictionary}function PublicDictionaryEntry(e,i){var n=i?"":regexParseForSearch(document.getElementById("searchBox").value),t=i?!1:document.getElementById("searchOptionWord").checked,r=i?!1:document.getElementById("searchOptionSimple").checked,o=i?!1:document.getElementById("searchOptionLong").checked,c=i?!1:!document.getElementById("searchCaseSensitive").checked,a=i?!1:document.getElementById("searchIgnoreDiacritics").checked,l=new RegExp("("+(a?removeDiacritics(n)+"|"+n:n)+")","g"+(c?"i":"")),d=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return d+=""!=n&&t?htmlEntities(htmlEntitiesParse(publicDictionary.words[e].name).replace(l,"$1")).replace(/<(\/?)searchterm>/g,"<$1searchterm>"):publicDictionary.words[e].name.toString(),""!=publicDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParseForMarkdown(publicDictionary.words[e].pronunciation)).replace(/<\/?p>/g,""))," "!=publicDictionary.words[e].partOfSpeech&&""!=publicDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=publicDictionary.words[e].partOfSpeech.toString()),""!=publicDictionary.words[e].simpleDefinition&&(""!=n&&r?wordSimpleDefinition+=htmlEntities(htmlEntitiesParse(publicDictionary.words[e].simpleDefinition).replace(l,"$1")).replace(/<(\/?)searchterm>/g,"<$1searchterm>"):wordSimpleDefinition+=publicDictionary.words[e].simpleDefinition.toString()),""!=publicDictionary.words[e].longDefinition&&(""!=n&&o?wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(htmlEntities(htmlEntitiesParse(publicDictionary.words[e].longDefinition).replace(l,"$1")))).replace(/<(\/?)searchterm>\;/g,"<$1searchterm>"):wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(publicDictionary.words[e].longDefinition))),PublicDictionaryEntryTemplate({name:d,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:publicDictionary.words[e].wordId.toString()},!1)}function PublicDictionaryEntryTemplate(e,i){i="undefined"!=typeof i?i:!1;var n="",n+=""+e.name+"",""!=e.pronunciation&&(n+=""+e.pronunciation+""),""!=e.partOfSpeech&&(n+=""+e.partOfSpeech+""),n+="
",""!=e.simpleDefinition&&(n+=""+e.simpleDefinition+""),""!=e.longDefinition&&(n+=""+e.longDefinition+""),i!==!1&&(n+=ManagementArea(i)),n+="
"}function SetPublicPartsOfSpeech(){for(var e=document.getElementById("filterOptions"),i=htmlEntitiesParse(publicDictionary.settings.partsOfSpeech).trim().split(","),n=0;n0)for(var n=e.options.length-1;n>=0;n--)e.removeChild(e.options[n]);for(var o=t.split("_DICTIONARYSEPARATOR_"),i=0;i0?currentDictionary.externalID:""}function GetTextFile(e,t,n){n="undefined"!=typeof n?n:!1;var o=new XMLHttpRequest;o.open("GET",e),o.onreadystatechange=function(){4==o.readyState&&200==o.status&&(window[t]=n?marked(o.responseText):o.responseText)},o.send()}function ValidateLogin(){var e=document.getElementById("loginError"),t=document.getElementById("loginEmailField").value,n=document.getElementById("loginPasswordField").value;return""==t?(e.innerHTML="Email cannot be blank!",!1):/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t)?""==n?(e.innerHTML="Password cannot be blank!",!1):void document.getElementById("loginForm").submit():(e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1)}function ValidateCreateAccount(){var e=document.getElementById("createAccountError"),t=document.getElementById("createAccountEmailField").value,n=document.getElementById("createAccountPasswordField").value,o=document.getElementById("createAccountPasswordConfirmField").value,i=document.getElementById("createAccountPublicNameField").value;if(""==t)return e.innerHTML="Email cannot be blank!",!1;if(!/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t))return e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1;if(""==n)return e.innerHTML="Password cannot be blank!",!1;if(n!=o)return e.innerHTML="Passwords do not match!",!1;if(""==i)return e.innerHTML="Public Name cannot be blank!",!1;var r=new XMLHttpRequest;r.open("GET","/php/ajax_createaccountemailcheck.php?email="+t),r.onreadystatechange=function(){if(4==r.readyState&&200==r.status){if("ok"!=r.responseText)return e.innerHTML="The email address entered is already being used. Try logging in or using a different email address instead.",!1;document.getElementById("createAccountForm").submit()}},r.send()}function ValidateAccountSettings(){var e=document.getElementById("accountSettingsError"),t=document.getElementById("accountSettingsEmailField").value,n=document.getElementById("accountSettingsPublicNameField").value;return""==t?(e.innerHTML="Email cannot be blank!",!1):/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t)?""==n?(e.innerHTML="Public Name cannot be blank!",!1):void document.getElementById("createAccountForm").submit():(e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1)}function ValidateForgotPassword(){var e=document.getElementById("forgotError"),t=document.getElementById("forgotEmailField").value;if(""==t)return e.innerHTML="Email cannot be blank!",!1;if(!/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t))return e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1;var n=new XMLHttpRequest;n.open("GET","/php/ajax_passwordresetemailcheck.php?email="+t),n.onreadystatechange=function(){if(4==n.readyState&&200==n.status){if("email exists"!=n.responseText)return e.innerHTML="The email address entered is not in use and therefore can't have its password reset. Try creating an account instead!",!1;document.getElementById("forgotForm").submit()}},n.send()}function ValidateResetPassword(){var e=document.getElementById("resetPasswordError"),t=document.getElementById("newPasswordField").value,n=document.getElementById("newPasswordConfirmField").value;return""==t?(e.innerHTML="Password cannot be blank!",!1):t!=n?(e.innerHTML="Passwords do not match!",!1):void document.getElementById("resetPasswordForm").submit()}function WarnEmailChange(){var e=document.getElementById("accountSettingsEmailChangeWarning"),t=document.getElementById("accountSettingsEmailField").value,n=document.getElementById("accountSettingsPreviousEmailField").value;t!=n?e.style.display="block":e.style.display="none"}function LoggedInResetPassword(){var e=new XMLHttpRequest;e.open("GET","/php/ajax_setnewpassword.php"),e.onreadystatechange=function(){if(4==e.readyState&&200==e.status){if("done"!=e.responseText)return console.log(e.responseText),alert("Error resetting password.\n\nTry again later."),!1;window.location="./"}},e.send()}function ExplainPublicName(){alert("This is the name we greet you with. It's also the name displayed if you ever decide to share any of your dictionaries.\n\nNote: this is not a username, and as such is not guaranteed to be unique. Use something people will recognize you as to differentiate from other people who might use the same name!")}function ExplainAllowEmails(){alert("We'll make sure that you're the first to hear about any new features that get added or if any of our policies change for any reason. We'll never spam you or sell your information, but you may need to mark emails from lexicon.ga as not spam to receive them.\nNOTE: Password reset emails will be sent regardless of your choice.")}function wordFormIsLocked(){return"🔒"==document.getElementById("formLockButton").innerHTML}function ToggleWordFormLock(){wordFormIsLocked()?UnlockWordForm():LockWordForm()}function UnlockWordForm(){var e=document.getElementById("formLockButton"),t=document.getElementById("leftColumn"),n=document.getElementById("wordEntryForm"),o=n.offsetWidth-20,i=t.offsetWidth,r=t.offsetHeight;e.innerHTML="🔓",n.style.position="fixed",n.style.top=document.getElementsByTagName("header")[0].offsetHeight.toString()+"px",n.style.width=o.toString()+"px",t.style.width=i.toString()+"px",t.style.height=r.toString()+"px"}function LockWordForm(){var e=document.getElementById("formLockButton"),t=document.getElementById("leftColumn"),n=document.getElementById("wordEntryForm");e.innerHTML="🔒",t.removeAttribute("style"),n.removeAttribute("style")}function CloseUpdateConflictArea(e){""==e?document.getElementById("newWordButtonArea").style.display="block":document.getElementById("editWordButtonArea"+e).style.display="block",document.getElementById("updateConflict"+e).style.display="none",EnableForm(e)}function DisableForm(e){document.getElementById("word"+e).disabled=!0,document.getElementById("pronunciation"+e).disabled=!0,document.getElementById("partOfSpeech"+e).disabled=!0,document.getElementById("simpleDefinition"+e).disabled=!0,document.getElementById("longDefinition"+e).disabled=!0}function EnableForm(e){document.getElementById("word"+e).disabled=!1,document.getElementById("pronunciation"+e).disabled=!1,document.getElementById("partOfSpeech"+e).disabled=!1,document.getElementById("simpleDefinition"+e).disabled=!1,document.getElementById("longDefinition"+e).disabled=!1}function ClearForm(){document.getElementById("wordEntryForm")&&(document.getElementById("word").value="",document.getElementById("pronunciation").value="",document.getElementById("partOfSpeech").value="",document.getElementById("simpleDefinition").value="",document.getElementById("longDefinition").value="",document.getElementById("editIndex").value="",document.getElementById("newWordButtonArea").style.display="block",document.getElementById("editWordButtonArea").style.display="none",document.getElementById("errorMessage").innerHTML="",document.getElementById("updateConflict").style.display="none",EnableForm(""))}function ToggleDescription(){var e=document.getElementById("descriptionToggle"),t=document.getElementById("dictionaryDescription");"none"==t.style.display?(t.style.display="block",e.innerHTML="Hide Description"):(t.style.display="none",e.innerHTML="Show Description")}function ToggleSearchFilter(){var e=document.getElementById("searchFilterToggle"),t=document.getElementById("searchFilterArea");"none"==t.style.display?(t.style.display="block",e.innerHTML="Hide Search/Filter Options"):(t.style.display="none",e.innerHTML="Search/Filter Options")}function ShowInfo(e){ShowInfoWithText(window[e]),"loginForm"==e&&(currentDictionary.words.length>0||"New"!=currentDictionary.name||"A new dictionary."!=currentDictionary.description)&&(document.getElementById("dictionaryWarn").innerHTML="If your current dictionary is not already saved to your account, be sure to export it before logging in so you don't lose anything!")}function ShowInfoWithText(e){document.getElementById("infoText").innerHTML=e,document.getElementById("infoScreen").style.display="block",document.getElementById("infoPage").scrollTop=0,HideAccountSettings()}function HideInfo(){document.getElementById("infoScreen").style.display="none"}function ToggleAccountSettings(){if(document.getElementById("accountSettingsScreen")){var e=document.getElementById("accountSettingsScreen");"block"==e.style.display?HideAccountSettings():ShowAccountSettings()}}function ShowAccountSettings(e){document.getElementById("accountSettingsScreen")&&(document.getElementById("accountSettingsScreen").style.display="block"),HideInfo()}function HideAccountSettings(){document.getElementById("accountSettingsScreen")&&(document.getElementById("accountSettingsScreen").style.display="none")}function ToggleSettingsScreen(e){var t=document.getElementById("settingsScreen");"block"==t.style.display?(e&&SaveSettings(),HideSettings()):ShowSettings()}function ShowSettings(){document.getElementById("settingsScreen").style.display="block",document.getElementById("dictionaryNameEdit").value=htmlEntitiesParse(currentDictionary.name),document.getElementById("dictionaryDescriptionEdit").value=htmlEntitiesParse(currentDictionary.description),document.getElementById("dictionaryPartsOfSpeechEdit").value=htmlEntitiesParse(currentDictionary.settings.partsOfSpeech),document.getElementById("dictionaryAllowDuplicates").checked=currentDictionary.settings.allowDuplicates,document.getElementById("dictionaryCaseSensitive").checked=currentDictionary.settings.caseSensitive,document.getElementById("dictionarySortByEquivalent").checked=currentDictionary.settings.sortByEquivalent,document.getElementById("dictionaryIsComplete").checked=currentDictionary.settings.isComplete,document.getElementById("dictionaryIsPublic")&&(document.getElementById("dictionaryIsPublic").checked=currentDictionary.settings.isPublic,TogglePublicLink()),document.getElementById("numberOfWordsInDictionary").innerHTML=currentDictionary.words.length.toString()}function HideSettings(){document.getElementById("settingsScreen").style.display="none",currentDictionary.settings.isComplete?(LockWordForm(),document.getElementById("wordEntryForm").style.display="none"):document.getElementById("wordEntryForm").style.display="block"}function HideSettingsWhenComplete(){document.getElementById("settingsScreen")&&(currentDictionary.settings.isComplete?document.getElementById("hideIfComplete").style.display="none":document.getElementById("hideIfComplete").style.display="block")}function ShowFullScreenTextbox(e,t){var n=document.getElementById(e),o=document.getElementById("fullScreenTextbox");document.getElementById("fullScreenTextboxLabel").innerHTML=t;var i=getInputSelection(n);document.getElementById("expandedTextboxId").innerHTML=e,o.value=n.value,document.getElementById("fullScreenTextboxScreen").style.display="block",setSelectionRange(o,i.start,i.end)}function HideFullScreenTextbox(){var e=document.getElementById("expandedTextboxId").innerHTML,t=document.getElementById("fullScreenTextbox"),n=document.getElementById(e),o=getInputSelection(t);n.value=t.value,document.getElementById("fullScreenTextboxScreen").style.display="none",setSelectionRange(n,o.start,o.end)}function ShowDictionaryDeleteMenu(e){document.getElementById("loadAfterDeleteScreen").style.display="block",ParseUserDictionariesIntoSelect(document.getElementById("loadAfterDelete"),e),ParseUserDictionariesIntoSelect(document.getElementById("userDictionaries"),e)}function ToggleCaseSensitiveOption(){document.getElementById("dictionaryAllowDuplicates").checked?document.getElementById("dictionaryCaseSensitive").disabled=!0:document.getElementById("dictionaryCaseSensitive").disabled=!1}function TogglePublicLink(){if(document.getElementById("dictionaryIsPublic").checked){var e="http://lexicon.ga/"+currentDictionary.externalID;document.getElementById("publicLink").innerHTML="Public Link:
"+e}else document.getElementById("publicLink").innerHTML=""}function SetPartsOfSpeech(e){e="undefined"!=typeof e?e:"partOfSpeech";var t=document.getElementById(e),n=document.getElementById("filterOptions"),o=GetSelectedFilters();t.innerHTML="",n.innerHTML="";var i=document.createElement("option");i.appendChild(document.createTextNode("")),i.value=" ",t.appendChild(i);for(var r=htmlEntitiesParse(currentDictionary.settings.partsOfSpeech).trim().split(","),d=0;d-1&&(s.checked=!0),a.appendChild(s),n.appendChild(a)}var u=document.createElement("label");u.appendChild(document.createTextNode("Blanks ")),u["part-of-speech"]=" ",u.className="filterOption";var m=document.createElement("input");m.type="checkbox",m.onchange=function(){ShowDictionary()},o.indexOf(" ")>-1&&(m.checked=!0),u.appendChild(m),n.appendChild(u)}function GetSelectedFilters(){for(var e=document.getElementById("filterOptions"),t=[],n=0;n0||""!=n?o.innerHTML="Showing "+e.toString()+" result"+(1!=e?"s":""):o.innerHTML=""}function NewWordNotification(e){var t=currentDictionary.nextWordId-1;NewNotification("New Word Added: "+e+"")}function NewNotification(e){var t=document.getElementById("notificationArea"),n=document.getElementById("notificationMessage");t.style.display="block",n.innerHTML=e}function FocusAfterAddingNewWord(){document.getElementById("word").focus()} \ No newline at end of file +function Initialize(){LoadDictionary(),ClearForm(),LoadUserDictionaries(),GetTextFile("/README.md","aboutText",!0),GetTextFile("/TERMS.md","termsText",!0),GetTextFile("/PRIVACY.md","privacyText",!0),GetTextFile("/LOGIN.form","loginForm",!1),GetTextFile("/FORGOT.form","forgotForm",!1),GetTextFile("/EXPORT.form","exportForm",!1),GetTextFile("/IMPORT.form","importForm",!1),SetKeyboardShortcuts()}function SetKeyboardShortcuts(){document.addEventListener("keydown",function(e){var t=e.which?e.which:e.keyCode;if(t==keyCodeFor("escape"))"block"==document.getElementById("infoScreen").style.display?HideInfo():"block"==document.getElementById("fullScreenTextboxScreen").style.display?HideFullScreenTextbox():"block"==document.getElementById("settingsScreen").style.display?HideSettings():document.getElementById("accountSettingsScreen")&&"block"==document.getElementById("accountSettingsScreen").style.display&&HideAccountSettings();else if(e.ctrlKey)if("none"==document.getElementById("fullScreenTextboxScreen").style.display)if(t==keyCodeFor("m"))"longDefinition"==document.activeElement.id?(e.preventDefault(),ShowFullScreenTextbox("longDefinition","Explanation/Long Definition")):"dictionaryDescriptionEdit"==document.activeElement.id?(e.preventDefault(),ShowFullScreenTextbox("dictionaryDescriptionEdit","Dictionary Details")):"fullScreenTextbox"==document.activeElement.id&&(e.preventDefault(),HideFullScreenTextbox());else if(t==keyCodeFor("u"))e.preventDefault(),ToggleWordFormLock();else if(t==keyCodeFor("d"))e.preventDefault(),ToggleDescription();else if(e.shiftKey&&t==keyCodeFor("s")||t==keyCodeFor("e"))e.preventDefault(),ExportDictionary();else if(t==keyCodeFor("s")){e.preventDefault();var n=document.getElementById("searchFilterToggle"),o=document.getElementById("searchFilterArea");"none"==o.style.display&&(o.style.display="block",n.innerHTML="Hide Search/Filter Options"),document.getElementById("searchBox").focus()}else t==keyCodeFor("h")&&(e.preventDefault(),ShowInfo("aboutText"));else t==keyCodeFor("m")?(e.preventDefault(),HideFullScreenTextbox()):t==keyCodeFor("u")?e.preventDefault():t==keyCodeFor("d")?e.preventDefault():e.shiftKey&&t==keyCodeFor("s")||t==keyCodeFor("e")?e.preventDefault():t==keyCodeFor("s")?e.preventDefault():t==keyCodeFor("h")&&e.preventDefault();else e.altKey&&"none"==document.getElementById("fullScreenTextboxScreen").style.display&&(t==keyCodeFor("s")?(e.preventDefault(),ToggleSettingsScreen(!0)):t==keyCodeFor("a")&&(e.preventDefault(),ToggleAccountSettings()))},!1)}function SubmitWordOnCtrlEnter(e){var t=event.which?event.which:event.keyCode;(t===keyCodeFor("ctrlEnter")||t==keyCodeFor("enter")&&event.ctrlKey)&&(event.preventDefault(),AddWord(),"none"==document.getElementById("newWordButtonArea").style.display&&"none"==document.getElementById("editWordButtonArea").style.display&&document.getElementById("updateConfirmButton").focus())}function LoadUserDictionaries(){var e=new XMLHttpRequest,t=document.getElementById("userDictionaries");null!=t&&(e.open("GET","/php/ajax_dictionarymanagement.php?action=getall"),e.onreadystatechange=function(){4==e.readyState&&200==e.status&&ParseUserDictionariesIntoSelect(t,e.responseText)},e.send())}function ParseUserDictionariesIntoSelect(e,t){if(e.options.length>0)for(var n=e.options.length-1;n>=0;n--)e.removeChild(e.options[n]);for(var o=t.split("_DICTIONARYSEPARATOR_"),i=0;i0?currentDictionary.externalID:""}function GetTextFile(e,t,n){n="undefined"!=typeof n?n:!1;var o=new XMLHttpRequest;o.open("GET",e),o.onreadystatechange=function(){4==o.readyState&&200==o.status&&(window[t]=n?marked(o.responseText,{sanitize:!1}):o.responseText)},o.send()}function ValidateLogin(){var e=document.getElementById("loginError"),t=document.getElementById("loginEmailField").value,n=document.getElementById("loginPasswordField").value;return""==t?(e.innerHTML="Email cannot be blank!",!1):/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t)?""==n?(e.innerHTML="Password cannot be blank!",!1):void document.getElementById("loginForm").submit():(e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1)}function ValidateCreateAccount(){var e=document.getElementById("createAccountError"),t=document.getElementById("createAccountEmailField").value,n=document.getElementById("createAccountPasswordField").value,o=document.getElementById("createAccountPasswordConfirmField").value,i=document.getElementById("createAccountPublicNameField").value;if(""==t)return e.innerHTML="Email cannot be blank!",!1;if(!/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t))return e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1;if(""==n)return e.innerHTML="Password cannot be blank!",!1;if(n!=o)return e.innerHTML="Passwords do not match!",!1;if(""==i)return e.innerHTML="Public Name cannot be blank!",!1;var r=new XMLHttpRequest;r.open("GET","/php/ajax_createaccountemailcheck.php?email="+t),r.onreadystatechange=function(){if(4==r.readyState&&200==r.status){if("ok"!=r.responseText)return e.innerHTML="The email address entered is already being used. Try logging in or using a different email address instead.",!1;document.getElementById("createAccountForm").submit()}},r.send()}function ValidateAccountSettings(){var e=document.getElementById("accountSettingsError"),t=document.getElementById("accountSettingsEmailField").value,n=document.getElementById("accountSettingsPublicNameField").value;return""==t?(e.innerHTML="Email cannot be blank!",!1):/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t)?""==n?(e.innerHTML="Public Name cannot be blank!",!1):void document.getElementById("createAccountForm").submit():(e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1)}function ValidateForgotPassword(){var e=document.getElementById("forgotError"),t=document.getElementById("forgotEmailField").value;if(""==t)return e.innerHTML="Email cannot be blank!",!1;if(!/[^\s@]+@[^\s@]+\.[^\s@]+/.test(t))return e.innerHTML="Your email address looks fake. Email addresses look like this: name@email.com.",!1;var n=new XMLHttpRequest;n.open("GET","/php/ajax_passwordresetemailcheck.php?email="+t),n.onreadystatechange=function(){if(4==n.readyState&&200==n.status){if("email exists"!=n.responseText)return e.innerHTML="The email address entered is not in use and therefore can't have its password reset. Try creating an account instead!",!1;document.getElementById("forgotForm").submit()}},n.send()}function ValidateResetPassword(){var e=document.getElementById("resetPasswordError"),t=document.getElementById("newPasswordField").value,n=document.getElementById("newPasswordConfirmField").value;return""==t?(e.innerHTML="Password cannot be blank!",!1):t!=n?(e.innerHTML="Passwords do not match!",!1):void document.getElementById("resetPasswordForm").submit()}function WarnEmailChange(){var e=document.getElementById("accountSettingsEmailChangeWarning"),t=document.getElementById("accountSettingsEmailField").value,n=document.getElementById("accountSettingsPreviousEmailField").value;t!=n?e.style.display="block":e.style.display="none"}function LoggedInResetPassword(){var e=new XMLHttpRequest;e.open("GET","/php/ajax_setnewpassword.php"),e.onreadystatechange=function(){if(4==e.readyState&&200==e.status){if("done"!=e.responseText)return console.log(e.responseText),alert("Error resetting password.\n\nTry again later."),!1;window.location="./"}},e.send()}function ExplainPublicName(){alert("This is the name we greet you with. It's also the name displayed if you ever decide to share any of your dictionaries.\n\nNote: this is not a username, and as such is not guaranteed to be unique. Use something people will recognize you as to differentiate from other people who might use the same name!")}function ExplainAllowEmails(){alert("We'll make sure that you're the first to hear about any new features that get added or if any of our policies change for any reason. We'll never spam you or sell your information, but you may need to mark emails from lexicon.ga as not spam to receive them.\nNOTE: Password reset emails will be sent regardless of your choice.")}function wordFormIsLocked(){return"🔒"==document.getElementById("formLockButton").innerHTML}function ToggleWordFormLock(){wordFormIsLocked()?UnlockWordForm():LockWordForm()}function UnlockWordForm(){var e=document.getElementById("formLockButton"),t=document.getElementById("leftColumn"),n=document.getElementById("wordEntryForm"),o=n.offsetWidth-20,i=t.offsetWidth,r=t.offsetHeight;e.innerHTML="🔓",n.style.position="fixed",n.style.top=document.getElementsByTagName("header")[0].offsetHeight.toString()+"px",n.style.width=o.toString()+"px",t.style.width=i.toString()+"px",t.style.height=r.toString()+"px"}function LockWordForm(){var e=document.getElementById("formLockButton"),t=document.getElementById("leftColumn"),n=document.getElementById("wordEntryForm");e.innerHTML="🔒",t.removeAttribute("style"),n.removeAttribute("style")}function CloseUpdateConflictArea(e){""==e?document.getElementById("newWordButtonArea").style.display="block":document.getElementById("editWordButtonArea"+e).style.display="block",document.getElementById("updateConflict"+e).style.display="none",EnableForm(e)}function DisableForm(e){document.getElementById("word"+e).disabled=!0,document.getElementById("pronunciation"+e).disabled=!0,document.getElementById("partOfSpeech"+e).disabled=!0,document.getElementById("simpleDefinition"+e).disabled=!0,document.getElementById("longDefinition"+e).disabled=!0}function EnableForm(e){document.getElementById("word"+e).disabled=!1,document.getElementById("pronunciation"+e).disabled=!1,document.getElementById("partOfSpeech"+e).disabled=!1,document.getElementById("simpleDefinition"+e).disabled=!1,document.getElementById("longDefinition"+e).disabled=!1}function ClearForm(){document.getElementById("wordEntryForm")&&(document.getElementById("word").value="",document.getElementById("pronunciation").value="",document.getElementById("partOfSpeech").value="",document.getElementById("simpleDefinition").value="",document.getElementById("longDefinition").value="",document.getElementById("editIndex").value="",document.getElementById("newWordButtonArea").style.display="block",document.getElementById("editWordButtonArea").style.display="none",document.getElementById("errorMessage").innerHTML="",document.getElementById("updateConflict").style.display="none",EnableForm(""))}function ToggleDescription(){var e=document.getElementById("descriptionToggle"),t=document.getElementById("dictionaryDescription");"none"==t.style.display?(t.style.display="block",e.innerHTML="Hide Description"):(t.style.display="none",e.innerHTML="Show Description")}function ToggleSearchFilter(){var e=document.getElementById("searchFilterToggle"),t=document.getElementById("searchFilterArea");"none"==t.style.display?(t.style.display="block",e.innerHTML="Hide Search/Filter Options"):(t.style.display="none",e.innerHTML="Search/Filter Options")}function ShowInfo(e){ShowInfoWithText(window[e]),"loginForm"==e&&(currentDictionary.words.length>0||"New"!=currentDictionary.name||"A new dictionary."!=currentDictionary.description)&&(document.getElementById("dictionaryWarn").innerHTML="If your current dictionary is not already saved to your account, be sure to export it before logging in so you don't lose anything!")}function ShowInfoWithText(e){document.getElementById("infoText").innerHTML=e,document.getElementById("infoScreen").style.display="block",document.getElementById("infoPage").scrollTop=0,HideAccountSettings()}function HideInfo(){document.getElementById("infoScreen").style.display="none"}function ToggleAccountSettings(){if(document.getElementById("accountSettingsScreen")){var e=document.getElementById("accountSettingsScreen");"block"==e.style.display?HideAccountSettings():ShowAccountSettings()}}function ShowAccountSettings(e){document.getElementById("accountSettingsScreen")&&(document.getElementById("accountSettingsScreen").style.display="block"),HideInfo()}function HideAccountSettings(){document.getElementById("accountSettingsScreen")&&(document.getElementById("accountSettingsScreen").style.display="none")}function ToggleSettingsScreen(e){var t=document.getElementById("settingsScreen");"block"==t.style.display?(e&&SaveSettings(),HideSettings()):ShowSettings()}function ShowSettings(){document.getElementById("settingsScreen").style.display="block",document.getElementById("dictionaryNameEdit").value=htmlEntitiesParse(currentDictionary.name),document.getElementById("dictionaryDescriptionEdit").value=htmlEntitiesParse(currentDictionary.description),document.getElementById("dictionaryPartsOfSpeechEdit").value=htmlEntitiesParse(currentDictionary.settings.partsOfSpeech),document.getElementById("dictionaryAllowDuplicates").checked=currentDictionary.settings.allowDuplicates,document.getElementById("dictionaryCaseSensitive").checked=currentDictionary.settings.caseSensitive,document.getElementById("dictionarySortByEquivalent").checked=currentDictionary.settings.sortByEquivalent,document.getElementById("dictionaryIsComplete").checked=currentDictionary.settings.isComplete,document.getElementById("dictionaryIsPublic")&&(document.getElementById("dictionaryIsPublic").checked=currentDictionary.settings.isPublic,TogglePublicLink()),document.getElementById("numberOfWordsInDictionary").innerHTML=currentDictionary.words.length.toString()}function HideSettings(){document.getElementById("settingsScreen").style.display="none",currentDictionary.settings.isComplete?(LockWordForm(),document.getElementById("wordEntryForm").style.display="none"):document.getElementById("wordEntryForm").style.display="block"}function HideSettingsWhenComplete(){document.getElementById("settingsScreen")&&(currentDictionary.settings.isComplete?document.getElementById("hideIfComplete").style.display="none":document.getElementById("hideIfComplete").style.display="block")}function ShowFullScreenTextbox(e,t){var n=document.getElementById(e),o=document.getElementById("fullScreenTextbox");document.getElementById("fullScreenTextboxLabel").innerHTML=t;var i=getInputSelection(n);document.getElementById("expandedTextboxId").innerHTML=e,o.value=n.value,document.getElementById("fullScreenTextboxScreen").style.display="block",setSelectionRange(o,i.start,i.end)}function HideFullScreenTextbox(){var e=document.getElementById("expandedTextboxId").innerHTML,t=document.getElementById("fullScreenTextbox"),n=document.getElementById(e),o=getInputSelection(t);n.value=t.value,document.getElementById("fullScreenTextboxScreen").style.display="none",setSelectionRange(n,o.start,o.end)}function ShowDictionaryDeleteMenu(e){document.getElementById("loadAfterDeleteScreen").style.display="block",ParseUserDictionariesIntoSelect(document.getElementById("loadAfterDelete"),e),ParseUserDictionariesIntoSelect(document.getElementById("userDictionaries"),e)}function ToggleCaseSensitiveOption(){document.getElementById("dictionaryAllowDuplicates").checked?document.getElementById("dictionaryCaseSensitive").disabled=!0:document.getElementById("dictionaryCaseSensitive").disabled=!1}function TogglePublicLink(){if(document.getElementById("dictionaryIsPublic").checked){var e="http://lexicon.ga/"+currentDictionary.externalID;document.getElementById("publicLink").innerHTML="Public Link:
"+e}else document.getElementById("publicLink").innerHTML=""}function SetPartsOfSpeech(e){e="undefined"!=typeof e?e:"partOfSpeech";var t=document.getElementById(e),n=document.getElementById("filterOptions"),o=GetSelectedFilters();t.innerHTML="",n.innerHTML="";var i=document.createElement("option");i.appendChild(document.createTextNode("")),i.value=" ",t.appendChild(i);for(var r=htmlEntitiesParse(currentDictionary.settings.partsOfSpeech).trim().split(","),d=0;d-1&&(s.checked=!0),a.appendChild(s),n.appendChild(a)}var u=document.createElement("label");u.appendChild(document.createTextNode("Blanks ")),u["part-of-speech"]=" ",u.className="filterOption";var m=document.createElement("input");m.type="checkbox",m.onchange=function(){ShowDictionary()},o.indexOf(" ")>-1&&(m.checked=!0),u.appendChild(m),n.appendChild(u)}function GetSelectedFilters(){for(var e=document.getElementById("filterOptions"),t=[],n=0;n0||""!=n?o.innerHTML="Showing "+e.toString()+" result"+(1!=e?"s":""):o.innerHTML=""}function NewWordNotification(e){var t=currentDictionary.nextWordId-1;NewNotification("New Word Added: "+e+"")}function NewNotification(e){var t=document.getElementById("notificationArea"),n=document.getElementById("notificationMessage");t.style.display="block",n.innerHTML=e}function FocusAfterAddingNewWord(){document.getElementById("word").focus()} \ No newline at end of file diff --git a/js/publicView.js b/js/publicView.js index 64b3f89..b3ed863 100644 --- a/js/publicView.js +++ b/js/publicView.js @@ -51,7 +51,7 @@ function ShowPublicDictionary(ignoreFilters) { } var dictionaryDescriptionArea = document.getElementById("dictionaryDescription"); - dictionaryDescriptionArea.innerHTML = marked(publicDictionary.description); + dictionaryDescriptionArea.innerHTML = marked(htmlEntitiesParseForMarkdown(publicDictionary.description)); var dictionaryArea = document.getElementById("theDictionary"); var dictionaryText = ""; @@ -97,22 +97,22 @@ function PublicDictionaryEntry(itemIndex, ignoreFilters) { var wordName = wordPronunciation = wordPartOfSpeech = wordSimpleDefinition = wordLongDefinition = ""; if (searchTerm != "" && searchByWord) { - wordName += htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].name).replace(searchRegEx, "$1")); + wordName += htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].name).replace(searchRegEx, "$1")).replace(/<(\/?)searchterm>/g, '<$1searchterm>'); } else { wordName += publicDictionary.words[itemIndex].name.toString(); // Use toString() to prevent using a reference instead of the value. } if (publicDictionary.words[itemIndex].pronunciation != "") { - wordPronunciation += marked(publicDictionary.words[itemIndex].pronunciation).replace("

","").replace("

",""); + wordPronunciation += marked(htmlEntitiesParseForMarkdown(publicDictionary.words[itemIndex].pronunciation)).replace(/<\/?p>/g,""); } - if (publicDictionary.words[itemIndex].partOfSpeech != "") { + if (publicDictionary.words[itemIndex].partOfSpeech != " " && publicDictionary.words[itemIndex].partOfSpeech != "") { wordPartOfSpeech += publicDictionary.words[itemIndex].partOfSpeech.toString(); } if (publicDictionary.words[itemIndex].simpleDefinition != "") { if (searchTerm != "" && searchBySimple) { - wordSimpleDefinition += htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "$1")); + wordSimpleDefinition += htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].simpleDefinition).replace(searchRegEx, "$1")).replace(/<(\/?)searchterm>/g, '<$1searchterm>'); } else { wordSimpleDefinition += publicDictionary.words[itemIndex].simpleDefinition.toString(); } @@ -120,9 +120,9 @@ function PublicDictionaryEntry(itemIndex, ignoreFilters) { if (publicDictionary.words[itemIndex].longDefinition != "") { if (searchTerm != "" && searchByLong) { - wordLongDefinition += marked(htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "$1"))); + wordLongDefinition += marked(htmlEntitiesParseForMarkdown(htmlEntities(htmlEntitiesParse(publicDictionary.words[itemIndex].longDefinition).replace(searchRegEx, "$1")))).replace(/<(\/?)searchterm>\;/g, '<$1searchterm>'); } else { - wordLongDefinition += marked(publicDictionary.words[itemIndex].longDefinition); + wordLongDefinition += marked(htmlEntitiesParseForMarkdown(publicDictionary.words[itemIndex].longDefinition)); } } diff --git a/js/ui.js b/js/ui.js index c5529e2..945af12 100644 --- a/js/ui.js +++ b/js/ui.js @@ -168,7 +168,7 @@ function GetTextFile(filename, variableName, parseMarkdown) { readmeFileRequest.open('GET', filename); readmeFileRequest.onreadystatechange = function() { if (readmeFileRequest.readyState == 4 && readmeFileRequest.status == 200) { - window[variableName] = (parseMarkdown) ? marked(readmeFileRequest.responseText) : readmeFileRequest.responseText; + window[variableName] = (parseMarkdown) ? marked(readmeFileRequest.responseText, {sanitize: false}) : readmeFileRequest.responseText; } } readmeFileRequest.send();