Math Multi-Tool Pro (TI-lite)

Calculator, quadratic solver, converter, complex math + smart word parser

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Math Multi-Tool Pro (TI-lite)
// @namespace    http://tampermonkey.net/
// @version      4.0
// @description  Calculator, quadratic solver, converter, complex math + smart word parser
// @match        *://*/*
// @grant        none
// @author       Valhalla_Vikings
// @license      All rights reserved. Copyright © 2026 Valhalla_Vikings
// ==/UserScript==

(function() {
'use strict';

/* ---------------- UI ---------------- */

const box = document.createElement("div");
Object.assign(box.style,{
  position:"fixed", top:"100px", right:"20px", width:"320px",
  background:"#1e1e1e", color:"#fff", padding:"12px",
  borderRadius:"10px", zIndex:9999, fontFamily:"Arial",
  boxShadow:"0 0 15px rgba(0,0,0,0.6)", cursor:"move"
});

box.innerHTML = `
<div style="display:flex; gap:5px; margin-bottom:10px; flex-wrap:wrap;">
<button class="tab" data="calc">Calc</button>
<button class="tab" data="quad">Quad</button>
<button class="tab" data="conv">Conv</button>
<button class="tab" data="complex">Cplx</button>
<button class="tab" data="word">Word</button>
</div>

<div id="calc">
<input id="expr" placeholder="2*(3+4)" style="width:100%">
<button id="evalBtn">=</button>
<p id="calcOut"></p>
</div>

<div id="quad" style="display:none;">
<input id="qa" placeholder="a">
<input id="qb" placeholder="b">
<input id="qc" placeholder="c">
<button id="solveQ">Solve</button>
<p id="qOut"></p>
</div>

<div id="conv" style="display:none;">
<input id="val" placeholder="value">
<select id="from"></select>
<select id="to"></select>
<button id="doConv">Convert</button>
<p id="convOut"></p>
</div>

<div id="complex" style="display:none;">
<b>z₁</b><br>
<input id="r1" placeholder="real">
<input id="i1" placeholder="imag"><br><br>

<b>z₂</b><br>
<input id="r2" placeholder="real">
<input id="i2" placeholder="imag"><br><br>

<select id="cop">
<option value="add">+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="div">/</option>
<option value="mag">|z₁|</option>
<option value="arg">arg(z₁)</option>
<option value="polar">→ polar</option>
<option value="pow">z₁^n</option>
<option value="root">n-th roots</option>
</select>

<input id="nVal" placeholder="n">
<button id="cRun">Compute</button>
<p id="cOut"></p>
</div>

<div id="word" style="display:none;">
<textarea id="wordInput" placeholder="Paste word problem..." style="width:100%; height:90px;"></textarea>
<button id="solveWord">Solve</button>
<p id="wordOut"></p>
</div>
`;

document.body.appendChild(box);

/* -------- Dragging -------- */
let isDown=false,ox,oy;
box.onmousedown=e=>{isDown=true;ox=e.offsetX;oy=e.offsetY;};
document.onmouseup=()=>isDown=false;
document.onmousemove=e=>{
  if(!isDown)return;
  box.style.left=(e.pageX-ox)+"px";
  box.style.top=(e.pageY-oy)+"px";
};

/* -------- Tabs -------- */
document.querySelectorAll(".tab").forEach(btn=>{
  btn.onclick=()=>{
    ["calc","quad","conv","complex","word"].forEach(id=>{
      document.getElementById(id).style.display="none";
    });
    document.getElementById(btn.dataset.data).style.display="block";
  };
});

/* ---------------- Calculator ---------------- */
evalBtn.onclick=()=>{
  try{
    let expr=exprInput();

    if(!expr.trim()) throw "";

    expr=expr
      .replace(/÷/g,"/")
      .replace(/×/g,"*")
      .replace(/\^/g,"**")
      .replace(/[^-()\d/*+.^]/g,"");

    calcOut.textContent=Function(`return (${expr})`)();
  }catch{
    calcOut.textContent="Error";
  }
};

function exprInput(){return document.getElementById("expr").value;}

/* ---------------- Quadratic ---------------- */
solveQ.onclick=()=>{
  const a=+qa.value,b=+qb.value,c=+qc.value;
  const d=b*b-4*a*c;

  if(d>0){
    qOut.textContent=
      ((-b+Math.sqrt(d))/(2*a))+", "+
      ((-b-Math.sqrt(d))/(2*a));
  }else if(d===0){
    qOut.textContent=-b/(2*a);
  }else{
    const re=(-b/(2*a)).toFixed(3);
    const im=(Math.sqrt(-d)/(2*a)).toFixed(3);
    qOut.textContent=`${re} ± ${im}i`;
  }
};

/* ---------------- Converter ---------------- */
const units={m:1,km:1000,cm:0.01,mm:0.001,ft:0.3048,in:0.0254,mi:1609.34,g:1,kg:1000};

Object.keys(units).forEach(u=>{
  from.innerHTML+=`<option>${u}</option>`;
  to.innerHTML+=`<option>${u}</option>`;
});

doConv.onclick=()=>{
  const v=+val.value;
  convOut.textContent=(v*units[from.value])/units[to.value];
};

/* ---------------- Complex ---------------- */
function C(r,i){return{r,i};}
const add=(a,b)=>C(a.r+b.r,a.i+b.i);
const sub=(a,b)=>C(a.r-b.r,a.i-b.i);
const mul=(a,b)=>C(a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r);
const div=(a,b)=>{const d=b.r*b.r+b.i*b.i;return C((a.r*b.r+a.i*b.i)/d,(a.i*b.r-a.r*b.i)/d);};
const mag=z=>Math.hypot(z.r,z.i);
const arg=z=>Math.atan2(z.i,z.r);

cRun.onclick=()=>{
  const z1=C(+r1.value||0,+i1.value||0);
  const z2=C(+r2.value||0,+i2.value||0);
  const op=cop.value,n=+nVal.value;

  let out="";
  switch(op){
    case"add":out=fmt(add(z1,z2));break;
    case"sub":out=fmt(sub(z1,z2));break;
    case"mul":out=fmt(mul(z1,z2));break;
    case"div":out=fmt(div(z1,z2));break;
    case"mag":out=mag(z1).toFixed(4);break;
    case"arg":out=arg(z1).toFixed(4)+" rad";break;
  }
  cOut.textContent=out;
};

function fmt(z){return `${z.r.toFixed(3)} ${z.i>=0?"+":"-"} ${Math.abs(z.i).toFixed(3)}i`;}

/* ---------------- Word Solver ---------------- */
solveWord.onclick=()=>{
  let t=wordInput.value.toLowerCase();

  try{
    // detect numbers + units
    const nums=[...t.matchAll(/(\d+(\.\d+)?)/g)].map(x=>+x[0]);

    // kg → g
    if(t.includes("kg")) nums[0]*=1000;

    // chocolate bar style (division)
    if(t.includes("how many")){
      const result=nums[0]/nums[1];
      wordOut.textContent=result;
      return;
    }

    // fallback basic math words
    t=t.replace(/plus/g,"+")
       .replace(/minus/g,"-")
       .replace(/times|multiplied/g,"*")
       .replace(/divided/g,"/");

    let expr=t.replace(/[^-()\d/*+.^]/g,"").replace(/\^/g,"**");

    wordOut.textContent=Function(`return (${expr})`)();

  }catch{
    wordOut.textContent="Couldn't solve";
  }
};

})();