diff --git a/index.html b/index.html new file mode 100644 index 0000000..5662bc5 --- /dev/null +++ b/index.html @@ -0,0 +1,479 @@ + + + + + + + Voice Accounting + + + + + + + + + +
+
+

Voice Accounting

+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ Accounting History +
+
+ + + +
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..9fc694e --- /dev/null +++ b/script.js @@ -0,0 +1,533 @@ + +var myContent=""; + +/* +function myLoad() { + var myContent = localStorage.getItem("myContent"); + console.log(myContent); + document.getElementById("calc-history-box").innerHTML = myContent; + } +*/ + +// Get reference to the "canvas" +var can = document.getElementById("calc-history-box"); + +// Save the content of the canvas to localStorage +function saveData(){ + localStorage.setItem("canvas", can.innerHTML); +} + +// Get localStorage data +function restoreData(){ + can.innerHTML = localStorage.getItem("canvas"); +} + +$(document).ready(function() { + +restoreData(); + + // A database of the symbols and functions of every operand. Order of operators determines precedence. + var operators = [ + { + id: "op-power", + numOperands: 2, + symbol: " ^ ", + calc: function(a, b) { + return Math.pow(a, b); + } + }, + { + id: "op-negate", + numOperands: 1, + symbol: " -", + calc: function(a) { + return -a; + } + }, + { + id: "op-square-root", + numOperands: 1, + symbol: " √", + calc: function(a) { + return Math.sqrt(a); + } + }, + { + id: "op-log", + numOperands: 1, + symbol: " log ", + calc: function(a) { + return Math.log10(a); + } + }, + { + id: "op-natural-log", + numOperands: 1, + symbol: " ln ", + calc: function(a) { + return Math.log(a); + } + }, + { + id: "op-sin", + numOperands: 1, + symbol: " sin ", + calc: function(a) { + return Math.sin(a); + } + }, + { + id: "op-cos", + numOperands: 1, + symbol: " cos ", + calc: function(a) { + return Math.cos(a); + } + }, + { + id: "op-tan", + numOperands: 1, + symbol: " tan ", + calc: function(a) { + return Math.tan(a); + } + }, + { + id: "op-inverse-sin", + numOperands: 1, + symbol: " sin-1 ", + calc: function(a) { + return Math.asin(a); + } + }, + { + id: "op-inverse-cos", + numOperands: 1, + symbol: " cos-1 ", + calc: function(a) { + return Math.acos(a); + } + }, + { + id: "op-inverse-tan", + numOperands: 1, + symbol: " tan-1 ", + calc: function(a) { + return Math.atan(a); + } + }, + { + id: "op-e", + numOperands: 1, + symbol: " e ^ ", + calc: function(a) { + return Math.exp(a); + } + }, + { + id: "op-nth-root", + numOperands: 2, + symbol: "*√", + calc: function(a, b) { + return Math.pow(b, 1/a); + } + }, + { + id: "op-multiply", + numOperands: 2, + symbol: " x ", + calc: function(a, b) { + return a * b; + } + }, + { + id: "op-divide", + numOperands: 2, + symbol: " ÷ ", + calc: function(a, b) { + return a / b; + } + }, + { + id: "op-add", + numOperands: 2, + symbol: " + ", + calc: function(a, b) { + return a + b; + } + }, + { + id: "op-subtract", + numOperands: 2, + symbol: " - ", + calc: function(a, b) { + return a - b; + } + } + ]; + + // The number of places to round to + const roundPlaces = 15; + + // Get the operator object for a given operator ID + function getOperator(opID) { + for(var i = 0; i < operators.length; i++) { + if(operators[i].id === opID) { + return operators[i]; + } + } + return undefined; + } + + // Get the precedence of an operator given its ID + function getOpPrecedence(opID) { + for(var i = 0; i < operators.length; i++) { + if(operators[i].id === opID) { + return i; + } + } + + // If the given ID does not return an operator, then return a large value that will always lose in precedence + return 1000; + } + + // Returns true if op1 ID has equal or higher precedence than op2 ID, false otherwise + function hasPrecedence(op1, op2) { + if(getOperator(op1) != undefined) { + return getOpPrecedence(op1) <= getOpPrecedence(op2); + } + } + + // Converts the given radian value to degrees + function toDegrees(radians) { + return radians * (180 / Math.PI); + } + + // Converts the given degrees value to radians + function toRadians(degrees) { + return degrees * (Math.PI / 180); + } + + // A list of every token (number or operator) currently in the expression + var tokenList = []; + + // A list of previous results and expressions in the form {out: output, expression: expression string, tokens: list of tokens in the expression} + var calcHistory = []; + + // Evaluates the expression and outputs the result + function calculate() { + // Check if brackets are balanced + var count = 0; + for(var i = 0; i < tokenList.length; i++) { + if(tokenList[i] === "bracket-left") { + count++; + } else if(tokenList[i] === "bracket-right") { + count--; + } + } + if(count != 0) { + output("Error: unbalanced brackets"); + return; + } + + // Evaluate the expression using a modified version of the shunting yard algorithm + var valStack = []; + var opStack = []; + + for(var i = 0; i < tokenList.length; i++) { + if(!isNaN(tokenList[i])) { + valStack.push(tokenList[i]); + } else if(tokenList[i] === "num-pi") { + valStack.push(Math.PI); + } else if(tokenList[i] === "bracket-left") { + opStack.push(tokenList[i]); + } else if(tokenList[i] === "bracket-right") { + while(opStack[opStack.length - 1] !== "bracket-left") { + var operator = getOperator(opStack.pop()); + if(operator.numOperands === 1) + valStack.push(applyOperator(operator, [valStack.pop()])); + else + valStack.push(applyOperator(operator, [valStack.pop(), valStack.pop()])); + } + opStack.pop(); + } else { + while(opStack.length > 0 && hasPrecedence(opStack[opStack.length - 1], tokenList[i])) { + var operator = getOperator(opStack.pop()); + if(operator.numOperands === 1) + valStack.push(applyOperator(operator, [valStack.pop()])); + else + valStack.push(applyOperator(operator, [valStack.pop(), valStack.pop()])); + } + opStack.push(tokenList[i]); + } + } + + while(opStack.length > 0) { + var operator = getOperator(opStack.pop()); + if(operator.numOperands === 1) + valStack.push(applyOperator(operator, [valStack.pop()])); + else + valStack.push(applyOperator(operator, [valStack.pop(), valStack.pop()])); + } + + // Output the calculated result and the original expression + output(valStack[0], $("#expression").html(), tokenList); + } + + // Returns the result of applying the given unary or binary operator on the top values of the value stack + function applyOperator(operator, vals) { + var valA = vals[0]; + var result; + + if(vals.length === 1) { + result = operator.calc(parseFloat(valA)); + } else { + var valB = vals[1]; + result = operator.calc(parseFloat(valB), parseFloat(valA)); + } + + return result; + } + + var textii = ""; + + // Updates the equation and calc history with the given output + function output(out, expression, tokens) { + out = +out.toFixed(roundPlaces); + $("#expression").html(out.toString()); + + calcHistory.push({out: out, expression: expression, tokens: tokens}); + // $("#calc-history-box").html(""); + for(var i = calcHistory.length - 1; i >= 0; i--) { + $("#calc-history-box").prepend("

" + calcHistory[i].expression + "

= " + calcHistory[i].out + "

"); + + textii = calcHistory[i].out; + let textvi = calcHistory[i].out.toString(); + textiv="1248.64"; + console.log(textvi); + testi=textvi+",,,,I Repeat.,,,,"+textvi; + console.log(testi); + // responsiveVoice.speak(textvi,'UK English Female', parameters); + // responsiveVoice.speak(" I Repeat. ",'UK English Female', parameters); + responsiveVoice.speak( testi.toString(), 'UK English Female', {rate: 0.95, onend: () => location.reload()}); + + } + } + + // Adds a token to the token list and updates the display + function addToken(token) { + if(isNaN(token)) { + if((token === "bracket-left" || token === "num-pi") && !isNaN(tokenList[tokenList.length - 1])) { + tokenList.push("op-multiply"); + } + tokenList.push(token); + } else { + if(!isNaN(tokenList[tokenList.length - 1])) { + tokenList[tokenList.length - 1] = tokenList[tokenList.length - 1] + token; + } else { + if(!isNaN(token) && (tokenList[tokenList.length - 1] === "bracket-right" || tokenList[tokenList.length - 1] === "num-pi")) { + tokenList.push("op-multiply"); + } + tokenList.push(token); + } + } + + displayEquation(); + } + + // Updates the expression display's HTML + function displayEquation() { + var htmlString = ""; + for(var i = 0; i < tokenList.length; i++) { + if(isNaN(tokenList[i])) { + if(tokenList[i] === "bracket-left") { + htmlString += " ("; + } else if(tokenList[i] === "bracket-right") { + htmlString += ") "; + } else if(tokenList[i] === "num-pi") { + htmlString += " π "; + } else { + htmlString += getOperator(tokenList[i]).symbol; + } + } else { + htmlString += tokenList[i]; + } + } + $("#expression").html(htmlString); + } + + // Deletes the last entered token + function deleteLast() { + if(isNaN(tokenList[tokenList.length - 1])) { + tokenList.pop(); + } else { + tokenList[tokenList.length - 1] = tokenList[tokenList.length - 1].slice(0, -1); + if(tokenList[tokenList.length -1].length === 0) { + tokenList.pop(); + } + } + + displayEquation(); + } + + // Shows/hides the advanced operators panel + function toggleAdvanced() { + $("#advanced-buttons").toggle(); + if($("#advanced-buttons").is(":visible")) { + $("#toggle-advanced").removeClass("button-off"); + $("#toggle-advanced span").removeClass("glyphicon-triangle-bottom").addClass("glyphicon-triangle-top"); + } else { + $("#toggle-advanced").addClass("button-off"); + $("#toggle-advanced span").removeClass("glyphicon-triangle-top").addClass("glyphicon-triangle-bottom"); + } + } + + // Triggers the appropriate action for each button that can be pressed + function processButton(button) { + switch($(button).attr("id")) { + case "delete": + deleteLast(); + break; + case "clear": + if(tokenList.length === 0) { + // calcHistory.length = 0; + // $("#calc-history-box").html(""); + } else { + tokenList.length = 0; + displayEquation(); + } + break; + case "period": + if(isNaN(tokenList[tokenList.length - 1])) { + addToken("0."); + } else { + if(tokenList[tokenList.length - 1].indexOf(".") === -1) { + tokenList[tokenList.length - 1] += "."; + } + } + displayEquation(); + break; + case "equals": + calculate(); + break; + case "toggle-advanced": + toggleAdvanced(); + break; + case "num-pi": + addToken("num-pi"); + break; + default: + if($(button).hasClass("num")) { + addToken($(button).html()); + } else { + addToken($(button).attr("id")); + } + } + } + + // Catches all button clicks on the page + + $(".btn").off('click').click(function(event) { + event.stopPropagation(); + event.stopImmediatePropagation(); + $(event.target).blur(); + // console.log("i am called"); + processButton(event.target); + return false; + }); + + $(document).on("click", ".calc-history-eq", function(event) { + var tokens = calcHistory[parseInt($(event.target).attr("id").substring(2))].tokens; + console.log(parseInt($(event.target).attr("id").substring(2))); + console.log(calcHistory); + console.log(tokens); + tokenList = tokens; + displayEquation(); + }); + +}); + +/* +function mySave() { + myContent += document.getElementById("calc-history-box").innerHTML; + console.log(myContent); + localStorage.setItem("myContent", myContent); + // console.log('History Saved'); + } +*/ + +function speak() { +// $('#61')[0].play(); +console.log('i am called'); +document.getElementById('13').play(); +} + +var down = false; + + document.addEventListener("keydown", (e) => { + + if(down) return; + down = true; + +// console.log(e.key); + +if (e.key >= 0 && e.key <= 9) { + event.preventDefault(); + e.stopPropagation(); + document.getElementById("num-" + e.key).click(); + return false; +} else if (e.key == "Enter" || e.key == "=") { + event.preventDefault(); + // document.getElementById('61').play(); + // speak(); + // document.getElementById('13').play(); + + // var speech = new SpeechSynthesisUtterance("hello world"); + // Window.speechSynthesis.speak(speech); + + document.getElementById("equals").click(); + saveData(); + // window.location.reload(); + // document.getElementById("clear").click(); + +/* + document.onkeydown = function (e) { + return false; +} + + setTimeout(function() { + // Do something after 5 seconds + location.reload();//reload page + +document.onkeydown = function (e) { + return true; +} + +}, 10000); +*/ + + +} else if (e.key == ".") { + event.preventDefault(); + document.getElementById("period").click(); +} else if (e.key == "+") { + event.preventDefault(); + document.getElementById("op-add").click(); +} else if (e.key == "-") { + event.preventDefault(); + document.getElementById("op-subtract").click(); +} else if (e.key == "*") { + event.preventDefault(); + document.getElementById("op-multiply").click(); +} else if (e.key == "/") { + event.preventDefault(); + document.getElementById("op-divide").click(); +} else if (e.key == "Backspace") { + event.preventDefault(); + document.getElementById("delete").click(); +} +}, false); + +document.addEventListener('keyup', function () { + down = false; +}, false); diff --git a/sounds/100.mp3 b/sounds/100.mp3 new file mode 100644 index 0000000..801d58b Binary files /dev/null and b/sounds/100.mp3 differ diff --git a/sounds/101.mp3 b/sounds/101.mp3 new file mode 100644 index 0000000..d31f49b Binary files /dev/null and b/sounds/101.mp3 differ diff --git a/sounds/102.mp3 b/sounds/102.mp3 new file mode 100644 index 0000000..8e30699 Binary files /dev/null and b/sounds/102.mp3 differ diff --git a/sounds/103.mp3 b/sounds/103.mp3 new file mode 100644 index 0000000..2612efe Binary files /dev/null and b/sounds/103.mp3 differ diff --git a/sounds/104.mp3 b/sounds/104.mp3 new file mode 100644 index 0000000..6f7c9f3 Binary files /dev/null and b/sounds/104.mp3 differ diff --git a/sounds/105.mp3 b/sounds/105.mp3 new file mode 100644 index 0000000..2d18802 Binary files /dev/null and b/sounds/105.mp3 differ diff --git a/sounds/106.mp3 b/sounds/106.mp3 new file mode 100644 index 0000000..8df2bd6 Binary files /dev/null and b/sounds/106.mp3 differ diff --git a/sounds/107.mp3 b/sounds/107.mp3 new file mode 100644 index 0000000..686ba29 Binary files /dev/null and b/sounds/107.mp3 differ diff --git a/sounds/109.mp3 b/sounds/109.mp3 new file mode 100644 index 0000000..787e585 Binary files /dev/null and b/sounds/109.mp3 differ diff --git a/sounds/110.mp3 b/sounds/110.mp3 new file mode 100644 index 0000000..4e74575 Binary files /dev/null and b/sounds/110.mp3 differ diff --git a/sounds/111.mp3 b/sounds/111.mp3 new file mode 100644 index 0000000..dc74412 Binary files /dev/null and b/sounds/111.mp3 differ diff --git a/sounds/13.mp3 b/sounds/13.mp3 new file mode 100644 index 0000000..41babbf Binary files /dev/null and b/sounds/13.mp3 differ diff --git a/sounds/144.mp3 b/sounds/144.mp3 new file mode 100644 index 0000000..1b20706 Binary files /dev/null and b/sounds/144.mp3 differ diff --git a/sounds/39.mp3 b/sounds/39.mp3 new file mode 100644 index 0000000..656090e Binary files /dev/null and b/sounds/39.mp3 differ diff --git a/sounds/61.mp3 b/sounds/61.mp3 new file mode 100644 index 0000000..a0fe6f9 Binary files /dev/null and b/sounds/61.mp3 differ diff --git a/sounds/96.mp3 b/sounds/96.mp3 new file mode 100644 index 0000000..2f9a21a Binary files /dev/null and b/sounds/96.mp3 differ diff --git a/sounds/97.mp3 b/sounds/97.mp3 new file mode 100644 index 0000000..4f90fe6 Binary files /dev/null and b/sounds/97.mp3 differ diff --git a/sounds/98.mp3 b/sounds/98.mp3 new file mode 100644 index 0000000..d7d909c Binary files /dev/null and b/sounds/98.mp3 differ diff --git a/sounds/99.mp3 b/sounds/99.mp3 new file mode 100644 index 0000000..0da1a88 Binary files /dev/null and b/sounds/99.mp3 differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..628d08e --- /dev/null +++ b/style.css @@ -0,0 +1,140 @@ +body { + background-color: #121212; + color: white; +} + +h1 { + margin-bottom: 20px; + text-align: center; +} + +.btn { + box-shadow: 0px 5px 10px #222222; + font-size:18px; +} + +.btn:focus { + outline: none; +} + +.button-row div { + width: 60px; + height: 60px; + text-align: center; + line-height: 60px; + margin: 5px; +} + +.button-row .btn { + width: 60px; + height: 60px; + background-color: #636363; +} + +.button-row .btn:hover { + background-color: #858585; + color: white !important; +} + +.button-orange { + background-color: #FF8400 !important; +} + +.button-orange:hover { + background-color: #FFA647 !important; +} + +.button-blue { + background-color: #0099FF !important; +} + +.button-blue:hover { + background-color: #33ADFF !important; +} + +.button-off { + background-color: #454545 !important; +} + +.calc-history-eq { + color: #B0B0B0; + cursor: pointer; +} + +#container { + width: 600px; + background-color: #2E2E2E; + height: 100%; + border-radius: 10px; + margin-top: 8%; +} + +#expression { + height: 60px; + margin-bottom: 20px; + padding: 10px; + text-align: right; + background-color: #636363; + border-radius: 5px; + font-size: 30px; + box-shadow: 0px 5px 10px #444444 inset; +} + +#standard-buttons { + display: inline-block; + margin-left: -20px; + margin-bottom: 10px; +} + +#advanced-buttons { + display: inline-block; + display: none; + margin-left: -20px; +} + +#toggle-advanced:hover { + background-color: #858585 !important; +} + +#toggle-advanced span { + pointer-events: none; +} + +#calc-history { + float: right; + width: 200px; + height: 270px; + background-color: #636363; + border-radius: 5px; + margin-top: 6px; + padding: 10px; + box-shadow: 0px 5px 10px #444444 inset; + overflow:auto; + font-size:18px; +} + +#calc-history-box { + width: 180px !important; + height: 220px !important; + resize: none; + overflow: auto; + font-size:18px; +} + +#calc-history hr { + margin-top: 5px; + margin-bottom: 5px; +} + +#footer { + background-color: #262626; + margin-left: -15px; + margin-right: -15px; + margin-bottom: -15px; + margin-top: 15px; + padding: 10px; + padding-bottom: 1px; + color: #636363; + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; +} \ No newline at end of file