UNPKG

kdj_singlish

Version:

KDJ Singlish is an app which created to help people to type in sinhala without making any mistakes. This will save your time and fix all the issues you are getting when you type. Just use it and let me know the issues.

577 lines (508 loc) 16.8 kB
const { remote } = require('electron'); $(document).ready(function () { notification.innerHTML = `KDJ Singlish is Now Ready for 32 Bit & 64 Bit Operating Systems`; notification.opened = true; }); const appVersion = app.getVersion(); document.getElementById('appVersion').innerHTML = appVersion; document.getElementById('close').addEventListener('click', closeWindow); document.getElementById('minimize').addEventListener('click', minimizeWindow); document.getElementById('maximize').addEventListener('click', maximizeWindow); const electron = require('electron'); let { ipcRenderer } = electron; let minView = document.getElementById('minView'); minView.addEventListener('click', function (e) { if (document.getElementById("minViewBtn").classList.contains('icon-lock-open')) { e.preventDefault(); ipcRenderer.send('resize', 400, 600); ipcRenderer.send('reposition', 0, 0); ipcRenderer.send('resizablefalse'); ipcRenderer.send('alwaystop'); document.getElementById("minViewBtn").classList.add('icon-lock'); document.getElementById("minViewBtn").classList.remove('icon-lock-open'); document.getElementById("lockText").innerHTML = "&nbsp; Locked"; notification.innerHTML = `Your Form is Locked`; notification.opened = true; } else { ipcRenderer.send('resize', 700, 600); ipcRenderer.send('alwaystopfalse'); ipcRenderer.send('resizabletrue'); document.getElementById("minViewBtn").classList.add('icon-lock-open'); document.getElementById("minViewBtn").classList.remove('icon-lock'); document.getElementById("lockText").innerHTML = "&nbsp; Unlocked"; notification.innerHTML = `Your Form is Unlocked`; notification.opened = true; } }); function scrollToBottom() { $('#unicode_textarea').scrollTop($('#unicode_textarea')[0].scrollHeight); $('#fmabaya_textarea').scrollTop($('#fmabaya_textarea')[0].scrollHeight); } $("#input_textarea").keydown(function () { scrollToBottom(); }); //IPC RENDERS TO GOOGLE ANALYTICS $('#helpModal').on('shown.bs.modal', function () { ipcRenderer.send('helpClicked'); console.log('Help Modal Opened.'); }) $('#aboutModal').on('shown.bs.modal', function () { ipcRenderer.send('aboutClicked'); console.log('About Modal Opened.'); }) $('#settingsModal').on('shown.bs.modal', function () { ipcRenderer.send('settingsClicked'); console.log('Settings Modal Opened.'); }) //FUNCTIO TP AUTOSASVE function autoTempSave() { var basepath = app.getPath('userData'); const tempSaveFile = basepath + '\\tempSave.txt'; var textArea = document.getElementById('input_textarea'); var tempText = textArea.value; fs.appendFile(tempSaveFile, tempText, function (err) { if (err) { return console.log(err); } notification.innerHTML = `Text has been saved in a temporary file.`; notification.opened = true; }); } // RESET TEMPSAVE FILE WHEN OPEN function resetTempSave() { var basepath = app.getPath('userData'); const tempSaveFile = basepath + '\\tempSave.txt'; fs.writeFile(tempSaveFile, '', function (err) { if (err) { return console.log(err); } else {} // notification.innerHTML = `Temporary File has been Reset`; // notification.opened = true; }); } function closeWindow() { autoTempSave(); startAutoSave(); var window = remote.getCurrentWindow(); window.close(); } function minimizeWindow() { var window = remote.getCurrentWindow(); window.minimize(); } function maximizeWindow() { var window = remote.getCurrentWindow(); if (!window.isMaximized()) { window.maximize(); } else { window.unmaximize(); } } $(function () { $('#btnCopyUni').click(function () { let notification = document.querySelector('#notification'); $('#unicode_textarea').focus(); $('#unicode_textarea').select(); document.execCommand('copy'); notification.innerHTML = `Unicode Text has been copied to the clipboard`; notification.opened = true; }); }); $(function () { $('#btnCopyFont').click(function () { $('#fmabaya_textarea').focus(); $('#fmabaya_textarea').select(); document.execCommand('copy'); notification.innerHTML = `Font Text has been copied to the clipboard`; notification.opened = true; }); }); // WORD SUGESSIONS ACTIVATED function start() { var basepath = app.getPath('userData'); const suggestionsFile = basepath + '\\suggestions.txt'; var $radios = $('input:radio[name=optradio]'); if ($radios.is(':checked') === false) { $radios.filter('[value=offline]').prop('checked', true); $.get(suggestionsFile, function (data) { var suggests = data.split(','); // console.log(suggests); new Suggest.LocalMulti('input_textarea', 'suggest', suggests, { dispAllKey: false, dispMax: 6, interval: 500, classMouseOver: false, highlight: true }); return false; }); } $("input[name='optradio']").click(function () { if ($('#radio1').is(':checked')) { console.log('Online Suggessions Library Activated'); $.get(suggestionsFile, function (data) { var suggests = data.split(','); console.log(suggests); new Suggest.LocalMulti('input_textarea', 'suggest', suggests, { dispAllKey: false, dispMax: 6, interval: 500, highlight: true }); return false; }); } else { console.log('Online Suggessions Library Activated'); $.get('https://api.kdj.lk/KDJ Singlish/kdj_singlish_suggests.txt', function (data) { var suggests = data.split(','); console.log(suggests); new Suggest.LocalMulti('input_textarea', 'suggest', suggests, { dispAllKey: false, dispMax: 6, interval: 500 }); }); } }); // $('#radio1').change(function () { // if ($('#radio1').is(':checked')) { // alert("checked"); // console.log('Offline Suggessions Library Activated') // $.get('../sinhalaSuggessions.txt', function (data) { // var suggests = data.split(','); // console.log(suggests); // new Suggest.LocalMulti("input_textarea", "suggest", suggests, { // dispAllKey: false, // dispMax: 5, // interval: 500 // }); // }); // } // else if (s) { // alert('unchecked') // } // }); // $('#radio2').change(function () { // console.log('Online Suggessions Library Activated') // $.get('https://api.kdjguru.com/kdj_singlish_suggests.txt', function (data) { // var suggests = data.split(','); // console.log(suggests); // new Suggest.LocalMulti("input_textarea", "suggest", suggests, { // dispAllKey: false, // dispMax: 5, // interval: 500 // }); // }); // }); } window.addEventListener ? window.addEventListener('load', start, false) : window.attachEvent('onload', start); // $('#unicode_textarea').focus(function () { // var theVal = $(this).val(); // $(this).val(theVal); // }); var inputBox = document.getElementById('typeArea'); var unicodeScroll = document.getElementById('unicode_textarea'); var fontScroll = document.getElementById('fmabaya_textarea'); function hideUnicode() { // Get the checkbox var checkBox = document.getElementById('hideUnicode'); var unicodeArea = document.getElementById('unicodeArea'); if (checkBox.checked == true) { console.log('hello'); unicodeArea.classList.remove('hideArea'); } else { console.log('bello'); unicodeArea.classList.add('hideArea'); } } function hideFont() { // Get the checkbox var checkBox = document.getElementById('hideFont'); var fontArea = document.getElementById('fontArea'); if (checkBox.checked == true) { console.log('hello'); fontArea.classList.remove('hideArea'); } else { console.log('bello'); fontArea.classList.add('hideArea'); } } $('#input_textarea').on('keyup', function () { //console.log("ok"); $('#tick')[0].pause(); $('#tick')[0].currentTime = 0; $('#tick')[0].play(); $('#tick')[0].volume = 0.3; }); function muteTickSound() { if ($('#muteTickSound').prop('checked')) { console.log('current state: checked'); // AUDIO PLAYS $('#input_textarea').on('keyup', function () { //console.log("ok"); $('#tick')[0].pause(); $('#tick')[0].currentTime = 0; $('#tick')[0].play(); $('#tick')[0].volume = 0.3; }); } else { console.log('current state: unchecked'); $('#input_textarea').on('keyup', function () { //console.log("ok"); $('#tick')[0].volume = 0; }); } } function hideAdsSpace() { if ($('#hideAdsSpace').prop('checked')) { console.log('current state: checked'); $('#w3-content').show(); } else { console.log('current state: unchecked'); $('#w3-content').hide(); } } // Adds and removes body class depending on screen width. function screenClass() { if ($(window).innerWidth() < 790) { $('#typeArea').addClass('col-sm-12').removeClass('col'); $('#unicodeArea').addClass('col-sm-12').removeClass('col'); $('#fontArea').addClass('col-sm-12').removeClass('col'); } else { $('#typeArea').addClass('col').removeClass('col-sm-12'); $('#unicodeArea').addClass('col').removeClass('col-sm-12'); $('#fontArea').addClass('col').removeClass('col-sm-12'); } } // Fire. screenClass(); // And recheck when window gets resized. $(window).bind('resize', function () { screenClass(); }); function resizeText(multiplier) { var typeArea = document.getElementById('input_textarea'); var unicodeArea = document.getElementById('unicode_textarea'); var fontArea = document.getElementById('fmabaya_textarea'); var currentSize = typeArea.style.fontSize || 1; typeArea.style.fontSize = parseFloat(currentSize) + multiplier * 0.1 + 'em'; unicodeArea.style.fontSize = parseFloat(currentSize) + multiplier * 0.1 + 'em'; fontArea.style.fontSize = parseFloat(currentSize) + multiplier * 0.1 + 'em'; } // WORD SUGGESTIONS AUTO ADD function duplicateCheck() { var output = document.getElementById('Output'); output.innerHTML = ''; var textArea = document.getElementById('input_textarea'); var inputSerials = textArea.value.trim().split(" "); var outputSerials = new Object(); for (var i = 0; i < inputSerials.length; i++) { var serial = inputSerials[i]; //build an object whose properties are serials //if the serial exists, incremint a counter if (outputSerials[serial]) { outputSerials[serial]++; } else { outputSerials[serial] = 1; } } // For testing // output.innerHTML = // 'Serials: <br />'; // for (var i in outputSerials) { // output.innerHTML += i + " "; // } for (var i in outputSerials) { //check to see if we have any duplicates if (outputSerials[i] > 2) { output.innerHTML += "," + i; } } } $('#input_textarea').on('change', function () { if (!$(`#input_textarea`).val().length) { } else { resetTempSave(); autoTempSave(); } var output = document.getElementById('Output'); var test = Output.innerHTML; var suggession = test; if (Output.innerHTML.length > 2) { var basepath = app.getPath('userData'); const suggestionsFile = basepath + '\\suggestions.txt'; fs.readFile(suggestionsFile, 'utf8', function (err, contents) { var output = document.getElementById('Output'); var suggetionsList = contents; Output.innerHTML = contents; console.log(contents); // Bug Fix: Check 3 words together with diferent variations if (suggetionsList.indexOf(test) != -1) { console.log('It\'s in the list'); Output.innerHTML = ""; return false; } else { var basepath = app.getPath('userData'); const suggestionsFile = basepath + '\\suggestions.txt'; fs.appendFile(suggestionsFile, suggession, function (err) { if (err) { return console.log(err); } // alert('Your suggestion added to the database. Add more to fast up your process.'); notification.innerHTML = `A suggestion has identified automatically and added to the database.`; notification.opened = true; // console.log("Saved"); Output.innerHTML = ""; }); console.log('It\'s not in the list'); } }); } }); $(function () { $('#clearSuggest').click(function () { var suggestedWord = document.getElementById('suggestedWord'); suggestedWord.value = ""; }) }); $(function () { $('#loadSavedContent').click(function () { var basepath = app.getPath('userData'); const tempSaveFile = basepath + '\\tempSave.txt'; var textArea = document.getElementById('input_textarea'); fs.readFile(tempSaveFile, 'utf8', function (err, contents) { textArea.value = contents; $("#input_textarea").focus(); $("#input_textarea").select(); }); }) }); $(function () { $('#btnAddSuggest').click(function () { var suggestedWord = document.getElementById('suggestedWord'); var test = suggestedWord.value; var suggession = "," + test; if (suggestedWord.value.length > 0) { var basepath = app.getPath('userData'); const suggestionsFile = basepath + '\\suggestions.txt'; fs.readFile(suggestionsFile, 'utf8', function (err, contents) { var output = document.getElementById('Output'); var suggetionsList = contents; Output.innerHTML = contents; console.log(contents); if (suggetionsList.indexOf(test) > -1) { // console.log('It\'s in the list'); // alert('Sorry, That word has aready added to the list.'); notification.innerHTML = `Sorry, That word has aready added to the list.`; notification.opened = true; Output.innerHTML = ""; return false; } else { fs.appendFile(suggestionsFile, suggession, function (err) { if (err) { return console.log(err); } // alert('Your suggestion added to the database. Add more to fast up your process.'); // console.log("Saved"); notification.innerHTML = `Your suggestion has added to the database. Add more to fast up your process.`; notification.opened = true; Output.innerHTML = ""; }); console.log('It\'s not in the list'); } }); } else { // alert('Type your word or phrase first. Then try again.'); notification.innerHTML = `Type your word or phrase first. Then try again.`; notification.opened = true; } }); }); var shell = require('electron').shell; //open links externally by default $(document).on('click', 'a[href^="http"]', function (event) { event.preventDefault(); shell.openExternal(this.href); }); function startAutoSave() { setTimeout(() => { if (!$(`#input_textarea`).val().length) { startAutoSave(); } else { resetTempSave(); autoTempSave(); startAutoSave(); } console.log('automatic save done') }, 30600) } startAutoSave(); Offline.options = { checks: { xhr: { url: 'https://www.dropbox.com/s/clxzab4x9i2lgy2/XHR%20Check%20%28Never%20Delete%29.jpg?dl=0' } } }; var run = function () { if (Offline.state === 'up') { Offline.check(); console.log('System is online') } else { console.log('System is Offline') } } setInterval(run, 1000); if (Offline.state === 'up') { Offline.check(); $('#w3-content').load("https://ads.kdj.lk/ads/kdj_singlish_ads.html"); $('#main_banner_ad').load("https://ads.kdj.lk/ads/kdj_singlish_large_banner.html"); // $('#LargeBannerModal').modal('show'); } $.ajax({ url: 'https://www.bing.com/aJyfYidjSlA' + new Date().getTime() + '.html', dataType: 'jsonp', timeout: 5000, error: function (xhr) { if (xhr.status == 404) { //internet connection working } else { //internet is down (xhr.status == 0) } } }); $(document).ready(function () { if (navigator.onLine) { setTimeout(() => { if ($(window).width() > 451) { $('#LargeBannerModal').modal('show'); ipcRenderer.send('largeBannerShown'); }else{ return false; } }, 3000); return true; } else { } }); Offline.on('up', function () { // alert('up'); // var w3_content = document.getElementById('w3-content'); // w3_content.innerHTML = ""; $('#w3-content').load("https://ads.kdj.lk/ads/kdj_singlish_ads.html"); $('#main_banner_ad').load("https://ads.kdj.lk/ads/kdj_singlish_large_banner.html"); }); Offline.on('down', function () { // alert('down') // if not connected to the internet // w3_content.innerHTML = ""; var w3_content = document.getElementById('w3-content'); var main_banner_ad = document.getElementById('main_banner_ad'); w3_content.innerHTML = `<img src="../img/banner1.jpg" style="width:100%">`; main_banner_ad.innerHTML = ''; });