// ==UserScript== // @name Gartic.io Advanced Calculator // @namespace http://tampermonkey.net/ // @version 1.0 // @author 《₁₈₇》 // @match https://gartic.io/* // @require https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.7.0/math.js // @grant none // @description Adds an advanced calculator to Gartic.io // @downloadURL none // ==/UserScript== (function() { 'use strict'; const math = window.math; let calcDiv = document.createElement('div'); calcDiv.id = 'advanced-calculator'; calcDiv.style.position = 'fixed'; calcDiv.style.bottom = '10px'; calcDiv.style.right = '10px'; calcDiv.style.backgroundColor = '#1e1e2e'; calcDiv.style.padding = '20px'; calcDiv.style.border = '2px solid #6272a4'; calcDiv.style.borderRadius = '12px'; calcDiv.style.zIndex = '9999'; calcDiv.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.3)'; calcDiv.style.fontFamily = "'Segoe UI', 'Arial', sans-serif"; calcDiv.style.width = '400px'; calcDiv.style.color = '#f8f8f2'; let title = document.createElement('div'); title.textContent = 'Gelişmiş Hesap Makinesi v2.0'; title.style.textAlign = 'center'; title.style.fontSize = '18px'; title.style.fontWeight = 'bold'; title.style.marginBottom = '15px'; title.style.color = '#bd93f9'; calcDiv.appendChild(title); let displayField = document.createElement('textarea'); displayField.id = 'calc-display'; displayField.style.width = '100%'; displayField.style.height = '80px'; displayField.style.backgroundColor = '#44475a'; displayField.style.color = '#f8f8f2'; displayField.style.padding = '15px'; displayField.style.fontSize = '24px'; displayField.style.border = '2px solid #6272a4'; displayField.style.borderRadius = '8px'; displayField.style.marginBottom = '15px'; displayField.style.resize = 'none'; displayField.style.fontFamily = "'Consolas', monospace"; displayField.style.boxSizing = 'border-box'; displayField.placeholder = 'Matematiksel ifade girin...'; displayField.value = ''; calcDiv.appendChild(displayField); let quickButtons = document.createElement('div'); quickButtons.style.display = 'flex'; quickButtons.style.gap = '5px'; quickButtons.style.marginBottom = '10px'; quickButtons.style.flexWrap = 'wrap'; const quickOps = [ { text: 'x²', value: '^2' }, { text: 'x³', value: '^3' }, { text: '√', value: 'sqrt(' }, { text: '³√', value: 'nthRoot(' }, { text: 'π', value: 'pi' }, { text: 'e', value: 'e' }, { text: '(', value: '(' }, { text: ')', value: ')' }, { text: 'log₁₀', value: 'log10(' }, { text: 'ln', value: 'log(' }, { text: 'sin', value: 'sin(' }, { text: 'cos', value: 'cos(' }, { text: 'tan', value: 'tan(' } ]; quickOps.forEach(op => { let btn = document.createElement('button'); btn.textContent = op.text; btn.style.padding = '8px 12px'; btn.style.backgroundColor = '#44475a'; btn.style.color = '#f8f8f2'; btn.style.border = '1px solid #6272a4'; btn.style.borderRadius = '4px'; btn.style.cursor = 'pointer'; btn.style.fontSize = '14px'; btn.style.flex = '1'; btn.style.minWidth = '60px'; btn.addEventListener('click', function() { insertAtCursor(displayField, op.value); displayField.focus(); }); quickButtons.appendChild(btn); }); calcDiv.appendChild(quickButtons); let buttonsContainer = document.createElement('div'); buttonsContainer.style.display = 'grid'; buttonsContainer.style.gridTemplateColumns = 'repeat(5, 1fr)'; buttonsContainer.style.gap = '8px'; buttonsContainer.style.marginBottom = '15px'; const buttons = [ { text: 'AC', class: 'clear', colspan: 1 }, { text: 'C', class: 'clear', colspan: 1 }, { text: '(', class: 'paren', colspan: 1 }, { text: ')', class: 'paren', colspan: 1 }, { text: '^', class: 'operator', colspan: 1 }, { text: '7', class: 'number', colspan: 1 }, { text: '8', class: 'number', colspan: 1 }, { text: '9', class: 'number', colspan: 1 }, { text: '÷', value: '/', class: 'operator', colspan: 1 }, { text: '√', value: 'sqrt(', class: 'function', colspan: 1 }, { text: '4', class: 'number', colspan: 1 }, { text: '5', class: 'number', colspan: 1 }, { text: '6', class: 'number', colspan: 1 }, { text: '×', value: '*', class: 'operator', colspan: 1 }, { text: 'sin', value: 'sin(', class: 'function', colspan: 1 }, { text: '1', class: 'number', colspan: 1 }, { text: '2', class: 'number', colspan: 1 }, { text: '3', class: 'number', colspan: 1 }, { text: '-', class: 'operator', colspan: 1 }, { text: 'cos', value: 'cos(', class: 'function', colspan: 1 }, { text: '0', class: 'number', colspan: 1 }, { text: '.', class: 'decimal', colspan: 1 }, { text: '=', class: 'equals', colspan: 2 }, { text: 'tan', value: 'tan(', class: 'function', colspan: 1 }, { text: '%', class: 'operator', colspan: 1 }, { text: 'log', value: 'log10(', class: 'function', colspan: 1 }, { text: 'ln', value: 'log(', class: 'function', colspan: 1 }, { text: '±', class: 'operator', colspan: 1 }, { text: 'π', value: 'pi', class: 'constant', colspan: 1 } ]; buttons.forEach(button => { let btn = document.createElement('button'); btn.textContent = button.text; btn.style.padding = '15px'; btn.style.border = 'none'; btn.style.borderRadius = '6px'; btn.style.cursor = 'pointer'; btn.style.fontSize = '18px'; btn.style.fontWeight = 'bold'; btn.style.gridColumn = `span ${button.colspan || 1}`; if (button.class === 'number') { btn.style.backgroundColor = '#6272a4'; btn.style.color = '#f8f8f2'; } else if (button.class === 'operator') { btn.style.backgroundColor = '#ff79c6'; btn.style.color = '#000'; } else if (button.class === 'function') { btn.style.backgroundColor = '#8be9fd'; btn.style.color = '#000'; } else if (button.class === 'clear') { btn.style.backgroundColor = '#ff5555'; btn.style.color = '#000'; } else if (button.class === 'equals') { btn.style.backgroundColor = '#50fa7b'; btn.style.color = '#000'; } else if (button.class === 'constant') { btn.style.backgroundColor = '#bd93f9'; btn.style.color = '#000'; } else if (button.class === 'paren') { btn.style.backgroundColor = '#f1fa8c'; btn.style.color = '#000'; } else if (button.class === 'decimal') { btn.style.backgroundColor = '#6272a4'; btn.style.color = '#f8f8f2'; } btn.addEventListener('click', function() { if (button.text === '=') { try { let expression = displayField.value; expression = expression.replace(/÷/g, '/').replace(/×/g, '*'); let result = math.evaluate(expression); displayField.value = result; } catch (e) { displayField.value = 'Hata: ' + e.message; } } else if (button.text === 'AC') { displayField.value = ''; } else if (button.text === 'C') { displayField.value = displayField.value.slice(0, -1); } else if (button.text === '±') { if (displayField.value.charAt(0) === '-') { displayField.value = displayField.value.slice(1); } else { displayField.value = '-' + displayField.value; } } else if (button.text === '%') { try { let currentValue = parseFloat(displayField.value); if (!isNaN(currentValue)) { displayField.value = (currentValue / 100).toString(); } } catch (e) { displayField.value = 'Hata'; } } else { let valueToAdd = button.value || button.text; insertAtCursor(displayField, valueToAdd); } displayField.focus(); }); buttonsContainer.appendChild(btn); }); calcDiv.appendChild(buttonsContainer); function insertAtCursor(textarea, text) { let start = textarea.selectionStart; let end = textarea.selectionEnd; textarea.value = textarea.value.substring(0, start) + text + textarea.value.substring(end); textarea.selectionStart = textarea.selectionEnd = start + text.length; textarea.dispatchEvent(new Event('input', { bubbles: true })); } let hideButton = document.createElement('button'); hideButton.textContent = 'Gizle'; hideButton.style.padding = '10px'; hideButton.style.backgroundColor = '#ffb86c'; hideButton.style.color = '#000'; hideButton.style.border = 'none'; hideButton.style.borderRadius = '4px'; hideButton.style.cursor = 'pointer'; hideButton.style.fontSize = '16px'; hideButton.style.marginTop = '10px'; hideButton.style.width = '100%'; hideButton.style.fontWeight = 'bold'; hideButton.addEventListener('click', function() { calcDiv.style.display = 'none'; bringBackButton.style.display = 'block'; }); calcDiv.appendChild(hideButton); let bringBackButton = document.createElement('button'); bringBackButton.textContent = 'Geri Getir'; bringBackButton.style.padding = '10px'; bringBackButton.style.backgroundColor = '#50fa7b'; bringBackButton.style.color = '#000'; bringBackButton.style.border = 'none'; bringBackButton.style.borderRadius = '4px'; bringBackButton.style.cursor = 'pointer'; bringBackButton.style.fontSize = '16px'; bringBackButton.style.display = 'none'; bringBackButton.style.position = 'absolute'; bringBackButton.style.left = '50%'; bringBackButton.style.transform = 'translateX(-50%)'; bringBackButton.style.top = '50%'; bringBackButton.style.zIndex = '9998'; bringBackButton.addEventListener('click', function() { calcDiv.style.display = 'block'; bringBackButton.style.display = 'none'; }); document.body.appendChild(calcDiv); document.body.appendChild(bringBackButton); displayField.addEventListener('keydown', function(e) { if (e.key === 'Enter') { e.preventDefault(); try { let expression = displayField.value; expression = expression.replace(/÷/g, '/').replace(/×/g, '*'); let result = math.evaluate(expression); displayField.value = result; } catch (error) { displayField.value = 'Hata: ' + error.message; } } }); document.addEventListener('keydown', function(e) { if (e.ctrlKey && e.key === 'k') { e.preventDefault(); if (calcDiv.style.display === 'none') { calcDiv.style.display = 'block'; bringBackButton.style.display = 'none'; } else { calcDiv.style.display = 'none'; bringBackButton.style.display = 'block'; } } }); })();