Skip to content

Commit

Permalink
Gemini داداشم، لاجیکشو درست کردم.
Browse files Browse the repository at this point in the history
  • Loading branch information
wayofmani committed May 29, 2024
1 parent 7799c15 commit 5687246
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 39 deletions.
8 changes: 4 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Takes playtime number and some other datas from users and sends to result page to show the result to user.
@amiradp @wayofmani
-->
<form action="result.html" method="GET" name="calcPlaytime" class="calcPlayTime">
<form action="result.html" id="submitData" method="GET" name="calcPlaytime" class="calcPlayTime">
<div class="formTitle">
<!--
Title
Expand All @@ -42,15 +42,15 @@ <h1>پلی تایم دوتا ۲</h1>

<div class="fields">
<!-- How many hours have you played this game -->
<input min="1" type="number" name="playtime_number" id="playtime_number" placeholder="تعداد ساعتی که بازی کردید" class="dota2-input state-available" autocomplete="false">
<input min="1" type="number" name="playtime_number" id="playtime_number" placeholder="تعداد ساعتی که بازی کردید" class="dota2-input state-available" autocomplete="false" id="total_PlaytimeHours">

<!-- Who Suggest this game to you -->
<input type="text" name="suggested_by" id="suggested_by" placeholder="کی بهتون معرفی کرد این بازیو؟ (به زودی...)" class="dota2-input state-disable" disabled>
</div>
</div>

<!-- Calc -->
<button type="submit" class="btn-primary">حساب کن</button>
<button type="submit" id="submitButton" class="btn-primary">حساب کن</button>

</form>

Expand Down Expand Up @@ -96,7 +96,7 @@ <h6>GabeN</h6>
<img src="../public/images/footer.png" alt="Better Call US Footer Logo">
</a>
</footer>

<script src="submit.js"></script>
</div>
</body>
</html>
35 changes: 2 additions & 33 deletions templates/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="calcPlayTime">
<div class="formTitle">
<!-- Result -->
<h1>
<h1 id="Result">
۲ سال و ۸ ماه و ۱۷ روز
</h1>
<span>
Expand Down Expand Up @@ -72,38 +72,7 @@ <h1>

</div>
</body>
<script type="text/javascript" lang="javascript">
// Calc
var total_hours = 'فعلا نمیدونم'
const day = total_hours / 24
const month = day / 12
const year = day / 365






// Copy Link Button
const copyButton = document.getElementById('copy-button');
const urlTextField = document.getElementById('url-text-field');

copyButton.addEventListener('click', () => {
// Get the URL from the text field
const urlToCopy = urlTextField.value;

// Copy the URL to clipboard (using Clipboard API)
navigator.clipboard.writeText(urlToCopy)
.then(() => {
// URL copied successfully
alert("لینک در صفحه کلید شما ذخیره شد!");
})
.catch(err => {
// Clipboard write failed
console.error('لینک کپی نشد!:', err);
alert("خطا در کپی کردن لینک");
});
});
<script type="text/javascript" lang="javascript" src="script.js">
</script>

</html>
57 changes: 57 additions & 0 deletions templates/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Calc
const urlParams = new URLSearchParams(window.location.search);
let total_hours = urlParams.get('total_hours');

var
days = total_hours / 24,
months = 0,
years = 0,
remainingDays = days,
resultElement = document.getElementById('Result')

// Years
while(remainingDays >= 365)
{
years++
remainingDays -= 365
}

// Months
while (remainingDays >= 30) {
months++;
remainingDays -= 30;
}
if(years==0)
resultElement.innerHTML = `${Math.floor(months)} ماه و ${Math.floor(remainingDays)} روز`;
else if(years==0 && months==0)
resultElement.innerHTML = `${Math.floor(remainingDays)} روز`;
else if(remainingDays==0)
resultElement.innerHTML = `${Math.floor(years)} سال و ${Math.floor(months)} ماه`;
else
resultElement.innerHTML = `${Math.floor(years)} سال و ${Math.floor(months)} ماه و ${Math.floor(remainingDays)} روز`;






// Copy Link Button
const copyButton = document.getElementById('copy-button');
const urlTextField = document.getElementById('url-text-field');

copyButton.addEventListener('click', () => {
// Get the URL from the text field
const urlToCopy = urlTextField.value;

// Copy the URL to clipboard (using Clipboard API)
navigator.clipboard.writeText(urlToCopy)
.then(() => {
// URL copied successfully
alert("لینک در صفحه کلید شما ذخیره شد!");
})
.catch(err => {
// Clipboard write failed
console.error('لینک کپی نشد!:', err);
alert("خطا در کپی کردن لینک");
});
});
9 changes: 9 additions & 0 deletions templates/styles/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,16 @@ input
right: 0;
margin: auto;
user-select: none;

}
@media only screen and (max-width: 600px)
{
.result img.upcoming
{
bottom: -25vh;
}
}

.result .container{
justify-content: space-between;
}
Expand Down
3 changes: 1 addition & 2 deletions templates/styles/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import url(variables.css);
@import url(typography.css);
@import url(components.css);
@import url(responsive.css);
@import url(components.css);
11 changes: 11 additions & 0 deletions templates/submit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const form = document.getElementById('submitData');

form.addEventListener('submit', (e) => {
e.preventDefault();
const defaultURL = window.location.href
const total_hours = document.getElementById('playtime_number').value;
const url = new URL('./result.html', defaultURL);
url.searchParams.append('total_hours', total_hours);

window.location.href = url.toString();
});

0 comments on commit 5687246

Please sign in to comment.