سلام
apache cordova را نصب کنید(آموزش نصب):
npm install -g cordova
سپس پروژه را با نام و باندل مورد نظر نصب کنید:
cordova create mashinhesab ir.gitrepo.mashinhesab
وارد پوشه ساخته شده برای نرم افزار خود شوید:
cd mashinhesab
پلتفرم مورد نظر خروجی نرم افزار را مطابق آموزش های قبلی نصب کنید. من اینجا Android و نسخه مرورگر Browser را نصب می کنم.
cordova platform add android
حال سورس نرم افزار را در پوشه www جایگزین کنید
شما اینجا سه فایل اصلی دارید:
index.html
<!DOCTYPE html>
<!--- www.gitrepo.ir--->
<html>
<head>
<meta charset="utf-8" />
<title>ماشین حساب پیشرفته</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="mashinhesab">
<h2 class="title">ماشین حساب</h2>
<input type="text" id="display" disabled />
<div class="buttons">
<button onclick="press('7')">7</button>
<button onclick="press('8')">8</button>
<button onclick="press('9')">9</button>
<button class="operator" onclick="press('/')">÷</button>
<button onclick="press('4')">4</button>
<button onclick="press('5')">5</button>
<button onclick="press('6')">6</button>
<button class="operator" onclick="press('*')">×</button>
<button onclick="press('1')">1</button>
<button onclick="press('2')">2</button>
<button onclick="press('3')">3</button>
<button class="operator" onclick="press('-')">−</button>
<button onclick="press('0')">0</button>
<button onclick="press('.')">.</button>
<button class="equal" onclick="calculate()">=</button>
<button class="operator" onclick="press('+')">+</button>
<button class="clear" onclick="clearDisplay()">C</button>
</div>
<button class="theme-toggle" onclick="toggleTheme()">🌓 تغییر رنگ</button>
<ul id="history" class="history"></ul>
<button class="clear-history" onclick="clearHistory()">🗑️ پاک کردن تاریخچه</button>
</div>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%20src%3D%22js%2Fapp.js%22%3E%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object mce-object-script" width="20" height="20" alt="<script>" />
</body>
</html>
فایل style.css
body {
font-family: 'Tahoma', sans-serif;
background: linear-gradient(to right, #dfe9f3, #ffffff);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.mashinhesab {
background-color: #ffffff;
padding: 20px 25px;
border-radius: 20px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
width: 260px;
text-align: center;
}
.mashinhesab h2 {
margin-bottom: 15px;
color: #333;
}
#display {
width: 100%;
height: 45px;
font-size: 22px;
margin-bottom: 15px;
text-align: right;
padding-right: 10px;
border: none;
border-bottom: 2px solid #ccc;
background: #f9f9f9;
border-radius: 8px;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
button {
height: 50px;
font-size: 20px;
border: none;
border-radius: 12px;
background-color: #f1f1f1;
color: #333;
transition: 0.2s;
cursor: pointer;
}
button:hover {
background-color: #e0e0e0;
}
.operator {
background-color: #ffb84d;
}
.operator:hover {
background-color: #ffa31a;
}
.equal {
background-color: #4CAF50;
color: white;
}
.equal:hover {
background-color: #45a049;
}
.clear {
grid-column: span 4;
background-color: #f44336;
color: white;
}
.clear:hover {
background-color: #d32f2f;
}
.title {
color: #333;
}
.dark-theme .title {
color: #eee;
}
.dark-theme {
background: linear-gradient(to right, #333, #222);
color: #eee;
}
.dark-theme .mashinhesab {
background-color: #2c2c2c;
box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}
.dark-theme #display {
background: #444;
color: #fff;
border-bottom: 2px solid #888;
}
.dark-theme button {
background-color: #555;
color: #eee;
}
.dark-theme button:hover {
background-color: #666;
}
.history {
margin-top: 15px;
text-align: right;
max-height: 100px;
overflow-y: auto;
font-size: 14px;
color: #666;
}
.dark-theme .history {
color: #ccc;
}
.theme-toggle {
margin-top: 10px;
background-color: #888;
color: white;
border: none;
padding: 8px 12px;
border-radius: 10px;
cursor: pointer;
}
.theme-toggle:hover {
background-color: #777;
}
.clear-history {
margin-top: 8px;
background-color: #b71c1c;
color: white;
border: none;
padding: 8px 12px;
border-radius: 10px;
cursor: pointer;
}
.clear-history:hover {
background-color: #a31414;
}
فایل app.js
let current = '';
let history = [];
function press(val) {
current += val;
document.getElementById('display').value = current;
}
function calculate() {
try {
const result = eval(current).toString();
history.push(current + ' = ' + result);
updateHistory();
current = result;
document.getElementById('display').value = current;
} catch (e) {
document.getElementById('display').value = 'Error';
current = '';
}
}
function clearDisplay() {
current = '';
document.getElementById('display').value = '';
}
function updateHistory() {
const historyList = document.getElementById('history');
historyList.innerHTML = '';
for (let i = history.length - 1; i >= 0 && i >= history.length - 5; i--) {
const item = document.createElement('li');
item.textContent = history[i];
historyList.appendChild(item);
}
}
function toggleTheme() {
document.body.classList.toggle('dark-theme');
}
function clearHistory() {
history = [];
updateHistory();
}
// صدا
const clickSound = new Audio('assets/click.mp3');
// بررسی ویبره پشتیبانی شده
function vibrate(ms = 50) {
if (navigator.vibrate) {
navigator.vibrate(ms);
}
}
// افزودن صدا و ویبره به رویدادهای کلیدی
document.querySelectorAll('button').forEach(btn => {
btn.addEventListener('click', () => {
clickSound.currentTime = 0;
clickSound.play();
vibrate();
});
});
حال پروژه را اجرا کنید:
cordova run Browser
برای آندروید
cordova run android




