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=htmlEntities(document.getElementById("editIndex").value),a=document.getElementById("errorMessage"),c="",s=document.getElementById("updateConflict");if(""==e||""==i&&""==r)""==e?(c+="Word cannot be blank",c+=""==i&&""==r?" and you need at least one definition.":"."):""==i&&""==r&&(c+="You need at least one definition.");else{var d=currentDictionary.settings.allowDuplicates?-1:WordIndex(e);if(""!=o)WordAtIndexWasChanged(o,e,t,n,i,r)?(document.getElementById("editWordButtonArea").style.display="none",DisableForm(),s.style.display="block",s.innerHTML="Do you really want to change the word \""+currentDictionary.words[parseInt(o)].name+'" to what you have set above?',s.innerHTML+='",s.innerHTML+=''):(c='No change has been made to "'+e+'"',currentDictionary.words[parseInt(o)].name!=e&&(c+=". (Your dictionary is currently set to ignore case.)"));else if(d>=0)if(WordAtIndexWasChanged(d,e,t,n,i,r)){document.getElementById("newWordButtonArea").style.display="none",DisableForm(),s.style.display="block";var l="\""+e+'" is already in the dictionary';l+=currentDictionary.words[d].name!=e?' as "'+currentDictionary.words[d].name+'", and your dictionary is set to ignore case.':".",l+="
Do you want to update it to what you have set above?
",l+='",l+=' ',s.innerHTML=l}else c='"'+e+'" is already in the dictionary exactly as it is written above',currentDictionary.words[d].name!=e&&(c+=". (Your dictionary is currently set to ignore case.)");else currentDictionary.words.push({name:e,pronunciation:t,partOfSpeech:n,simpleDefinition:i,longDefinition:r,wordId:currentDictionary.nextWordId++}),FocusAfterAddingNewWord(),NewWordNotification(e),SaveAndUpdateDictionary(!1);a.innerHTML=""}a.innerHTML=c}function EditWord(e){SaveScroll(),wordFormIsLocked()&&window.scroll(0,0),ClearForm(),document.getElementById("editIndex").value=e.toString(),document.getElementById("word").value=htmlEntitiesParse(currentDictionary.words[e].name),document.getElementById("pronunciation").value=htmlEntitiesParse(currentDictionary.words[e].pronunciation),document.getElementById("partOfSpeech").value=htmlEntitiesParse(currentDictionary.words[e].partOfSpeech),document.getElementById("simpleDefinition").value=htmlEntitiesParse(currentDictionary.words[e].simpleDefinition),document.getElementById("longDefinition").value=htmlEntitiesParse(currentDictionary.words[e].longDefinition),document.getElementById("newWordButtonArea").style.display="none",document.getElementById("editWordButtonArea").style.display="block"}function UpdateWord(e,t,n,i,r,o){currentDictionary.words[e].name=t,currentDictionary.words[e].pronunciation=n,currentDictionary.words[e].partOfSpeech=i,currentDictionary.words[e].simpleDefinition=r,currentDictionary.words[e].longDefinition=o,SaveAndUpdateDictionary(),window.scroll(savedScroll.x,savedScroll.y)}function DeleteWord(e){""!=document.getElementById("editIndex").value&&ClearForm(),currentDictionary.words.splice(e,1),SaveAndUpdateDictionary(!0)}function ShowDictionary(){var e=document.getElementById("wordFilter").value,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";var y=document.getElementById("dictionaryDescription");y.innerHTML=marked(htmlEntitiesParse(currentDictionary.description));var p=document.getElementById("theDictionary"),m="",D=0;if(currentDictionary.words.length>0)for(var g=0;g=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.";p.innerHTML=m,ShowFilterWordCount(D)}function DictionaryEntry(e){displayPublic="undefined"!=typeof displayPublic&&null!=displayPublic?displayPublic:!1;var t="🔗",n=regexParseForSearch(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,s=new RegExp("("+(c?removeDiacritics(n)+"|"+n:n)+")","g"+(a?"i":""));return t+="",t+=""!=n&&i?htmlEntitiesParse(currentDictionary.words[e].name).replace(s,"$1"):currentDictionary.words[e].name,t+="",""!=currentDictionary.words[e].pronunciation&&(t+="",t+=marked(htmlEntitiesParse(currentDictionary.words[e].pronunciation)).replace("

","").replace("

",""),t+="
"),""!=currentDictionary.words[e].partOfSpeech&&(t+="",t+=currentDictionary.words[e].partOfSpeech,t+=""),t+="
",""!=currentDictionary.words[e].simpleDefinition&&(t+="",t+=""!=n&&r?htmlEntitiesParse(currentDictionary.words[e].simpleDefinition).replace(s,"$1"):currentDictionary.words[e].simpleDefinition,t+=""),""!=currentDictionary.words[e].longDefinition&&(t+="",t+=""!=n&&o?marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition).replace(s,"$1")):marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition)),t+=""),currentDictionary.settings.isComplete||(t+=ManagementArea(e)),t+="
"}function ManagementArea(e){var t="
";return t+="Edit",t+="Delete',t+="",t+="
"}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()}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 SaveAndUpdateDictionary(e){currentDictionary.settings.sortByEquivalent?currentDictionary.words.sort(dynamicSort(["simpleDefinition","partOfSpeech"])):currentDictionary.words.sort(dynamicSort(["name","partOfSpeech"])),SaveDictionary(!0,!0),ShowDictionary(),e||ClearForm(),CloseUpdateConflictArea("newWordButtonArea")}function SaveDictionary(e,t){localStorage.setItem("dictionary",JSON.stringify(currentDictionary)),e&&(t="undefined"!=typeof t?t:!1,SendDictionary(t)),SavePreviousDictionary()}function SendDictionary(e){e="undefined"!=typeof e?e:!1;var t="",n="";currentDictionary.externalID>0?(t="update",n=DataToSend(e)):(t="new",n=DataToSend(!0,!0));var i=new XMLHttpRequest;i.open("POST","php/ajax_dictionarymanagement.php?action="+t),i.setRequestHeader("Content-type","application/x-www-form-urlencoded"),i.onreadystatechange=function(){return 4==i.readyState&&200==i.status?("updated successfully"==i.responseText?(console.log(i.responseText),LoadUserDictionaries(),ProcessLoad()):isNaN(parseInt(i.responseText))?console.log(i.responseText):(currentDictionary.externalID=parseInt(i.responseText),LoadUserDictionaries(),ProcessLoad(),console.log("saved successfully")),!0):!1},i.send(n)}function DataToSend(e,t){t="undefined"!=typeof t&&null!=t?t:!1;var n="";return 0==currentDictionary.externalID?(n="name="+encodeURIComponent(currentDictionary.name)+"&description="+encodeURIComponent(currentDictionary.description)+"&words="+encodeURIComponent(JSON.stringify(currentDictionary.words)),n+="&nextwordid="+currentDictionary.nextWordId+"&allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")+"&casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0"),n+="&partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)+"&sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")+"&iscomplete="+(currentDictionary.settings.isComplete?"1":"0")+"&ispublic="+(currentDictionary.settings.isPublic?"1":"0")):((t||currentDictionary.name!=previousDictionary.name)&&(n+="name="+encodeURIComponent(currentDictionary.name)),(t||currentDictionary.description!=previousDictionary.description)&&(n+=(""==n?"":"&")+"description="+encodeURIComponent(currentDictionary.description)),(t||e)&&(n+=(""==n?"":"&")+"words="+encodeURIComponent(JSON.stringify(currentDictionary.words))),(t||currentDictionary.nextWordId!=previousDictionary.nextWordId)&&(n+=(""==n?"":"&")+"nextwordid="+currentDictionary.nextWordId),(t||currentDictionary.settings.allowDuplicates!=previousDictionary.allowDuplicates)&&(n+=(""==n?"":"&")+"allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")),(t||currentDictionary.settings.caseSensitive!=previousDictionary.caseSensitive)&&(n+=(""==n?"":"&")+"casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0")),(t||currentDictionary.settings.partsOfSpeech!=previousDictionary.partsOfSpeech)&&(n+=(""==n?"":"&")+"partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)),(t||currentDictionary.settings.sortByEquivalent!=previousDictionary.sortByEquivalent)&&(n+=(""==n?"":"&")+"sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")),(t||currentDictionary.settings.isComplete!=previousDictionary.isComplete)&&(n+=(""==n?"":"&")+"iscomplete="+(currentDictionary.settings.isComplete?"1":"0")),(t||currentDictionary.settings.isPublic!=previousDictionary.isPublic)&&(n+=(""==n?"":"&")+"ispublic="+(currentDictionary.settings.isPublic?"1":"0"))),n}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,!1))),ProcessLoad()},e.send()}function ChangeDictionary(e){if(e="undefined"!=typeof e&&null!=e?e:document.getElementById("userDictionaries"),currentDictionary.externalID!=e.value&&e.options.length>0){var t=new XMLHttpRequest;t.open("POST","php/ajax_dictionarymanagement.php?action=switch"),t.setRequestHeader("Content-type","application/x-www-form-urlencoded");var n="newdictionaryid="+e.value.toString();t.onreadystatechange=function(){4==t.readyState&&200==t.status&&("no dictionaries"==t.responseText?(console.log(t.responseText),SendDictionary(!1)):t.responseText.length<60?console.log(t.responseText):(currentDictionary=JSON.parse(t.responseText),SaveDictionary(!1,!1),ProcessLoad(),LoadUserDictionaries(),HideSettings()))},t.send(n)}}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 ImportDictionary(){if(currentDictionary.externalID>0||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,!0),ProcessLoad(),HideSettings(),document.getElementById("importFile").value="";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 WordIndex(e){for(var t=0;t/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 i=1;return"-"===e[0]&&(i=-1,e=e.substring(1)),removeDiacritics(t[e])>removeDiacritics(n[e])?i:removeDiacritics(t[e])