Refactoring Javascript.js

This commit is contained in:
j.lechner
2025-02-04 16:42:30 +01:00
parent 6eb5fa0806
commit fbbce028ea
7 changed files with 264 additions and 251 deletions
+7 -14
View File
@@ -8,11 +8,11 @@
<title>Julian Lechner</title>
<link rel="shortcut icon" type="image/png" href="favicon.ico" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
<link rel="stylesheet" type="text/css" href="../Resources/Style.css" />
<link rel="stylesheet" type="text/css" href="../Style.css" />
<script rel="preload" src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>
<script async rel="preload" src="../Resources/Javascript.js"></script>
</head>
<body>
@@ -32,13 +32,6 @@
<br>
<p>
<h4>Represented by:</h4>
Julian Lechner
</p>
<br>
<p>
<h4>Contact:</h4>
Phone: +43 (0) 660 9254001 <br>
@@ -49,7 +42,7 @@
<p>
<h4>Abuse Contact:</h4>
E-Mail: julian@lechner.top
E-Mail: abuse@fraujulian.xyz
</p>
<br>
@@ -133,9 +126,9 @@
<!-- SCRIPTS -->
<script defer data-domain="fraujulian.xyz" src="https://plausible.io/js/plausible.js"></script>
<script rel="preload" src="../Javascript.js"></script>
<script rel="preload" src="../Resources/Javascript.js"></script>
</footer>
</body>
</html>
</html>
-175
View File
@@ -1,175 +0,0 @@
var slideIndex = 0;
carousel();
function carousel() {
var items = [];
var bioContainer = document.getElementsByClassName("bio")[0];
bioContainer.style = "display: grid !important;";
document.getElementsByClassName("js-reminder")[0].style = "display: none !important;";
var rawListItems = bioContainer.getElementsByTagName("div");
for (var i = 1; i < rawListItems.length; i++) {
rawListItems[i].style = "display: none;";
}
slideIndex++;
if (slideIndex > rawListItems.length || slideIndex == 1) {
slideIndex = 2
}
rawListItems[slideIndex - 1].style.display = "block";
setTimeout(carousel, 1000);
}
window.onload = function () {
let script = document.createElement("script");
script.src = "https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js";
document.body.appendChild(script);
const sortOnKey = (key, desc) => {
return (a, b) => {
a = a[key];
b = b[key];
return desc ? b - a : a - b;
};
};
String.prototype.replaceAt = function (index, replacement) {
return (
this.substr(0, index) +
replacement +
this.substr(index + replacement.length)
);
};
fetch("https://api.github.com/users/fraujulian/repos?per_page=999")
.then((response) => response.json())
.then((projects) => {
projects = projects.sort(sortOnKey("stargazers_count", true));
let projectsDiv = document.getElementById("github_projects");
projectsDiv.innerHTML = "";
projectsDiv.classList = "";
for (let i = 0; i < 16; i++) {
let projectDiv = document.createElement("div");
projectDiv.classList = "card hoverable";
let project = projects[i];
if (project != undefined) {
if (project.description == null)
project.description = "";
if (project.language == null)
project.language = "";
project.name = project.name.replaceAll("_", " ").replaceAll("-", " ");
projectDiv.innerHTML = `
<div class="media">
<div class="media-body">
<a href="${project.html_url}" onclick="plausible('${project.name}')" target="_blank">
<strong class="d-block text-gray-dark">${project.name}</strong>
</a>
<div class="stars" style="float:right;">
${project.language}
<i class="far fa-star stargazers"></i>${project.stargazers_count}
</div>
</div>
<p>${project.description}</p>
</div>
`;
fetch(
`https://raw.githubusercontent.com/${project.full_name}/master/README.md`
)
.then((response) => response.text())
.then((text) => {
let converter = new showdown.Converter();
let html = converter.makeHtml(text);
let projectModal = document.createElement("div");
projectModal.classList = "modal github-modal hidden";
projectModal.innerHTML = `
<div class="card">
<a onclick="location.reload()" href="#" style="float: right"> ❌</a>
<a href="${project.html_url}" target="blank" style="float: left"> Visit on GitHub</a>
<br>
<br>
${html}
</div>
`;
projectDiv.onclick = function () {
projectModal.classList.remove("hidden");
document.body.scrollTop = 0; // Safari
document.documentElement.scrollTop = 0; // Chrome Firefox IE Opera
document.body.style.opacity = 0.2;
};
projectModal.onclick = function (evt) {
if (evt.target == projectModal) {
projectModal.classList.add("hidden");
document.body.style.opacity = 1;
}
};
document
.getElementsByTagName("html")[0]
.appendChild(projectModal);
});
projectsDiv.appendChild(projectDiv);
}
}
});
};
let bioBtn = document.getElementById('short-desc');
let bioModel = document.getElementsByClassName('bio-text')[0];
let leftArrow = document.getElementById("left-arrow");
let rightArrow = document.getElementById("right-arrow");
let hidden = true;
bioBtn.onclick = function () {
if (hidden) {
bioModel.classList.remove("hidden");
leftArrow.classList.remove("fa-arrow-right");
leftArrow.classList.add("fa-arrow-down");
rightArrow.classList.remove("fa-arrow-left");
rightArrow.classList.add("fa-arrow-down");
leftArrow.style.position = "relative";
rightArrow.style.position = "relative";
unfade(bioModel);
} else {
bioModel.classList.add("hidden");
leftArrow.classList.remove("fa-arrow-down");
leftArrow.classList.add("fa-arrow-right");
rightArrow.classList.remove("fa-arrow-down");
rightArrow.classList.add("fa-arrow-left");
leftArrow.style.position = "relative";
rightArrow.style.position = "relative";
fade(bioModel);
}
hidden = !hidden;
};
bioModel.onclick = function (evt) {
if (evt.target == bioModel) {
bioModel.classList.add("hidden");
document.body.style.opacity = 1;
}
};
function fade(element) {
var op = 1;
var timer = setInterval(function () {
if (op <= 0.1) {
clearInterval(timer);
element.style.display = 'none';
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op -= op * 0.1;
}, 5);
}
function unfade(element) {
var op = 0.1;
element.style.display = 'block';
var timer = setInterval(function () {
if (op >= 1) {
clearInterval(timer);
}
element.style.opacity = op;
element.style.filter = 'alpha(opacity=' + op * 100 + ")";
op += op * 0.1;
}, 5);
}

Before

Width:  |  Height:  |  Size: 937 KiB

After

Width:  |  Height:  |  Size: 937 KiB

+197
View File
@@ -0,0 +1,197 @@
let _todayDate = new Date();
if (window.location.pathname.endsWith("index.html")) {
LoadHomepage();
} else {
ReplaceCurrentYearPlaceholder();
}
function LoadHomepage() {
ReplacePlaceholders();
LoadGithubProjects(999, 16);
}
function ReplacePlaceholders() {
document.getElementById("loading-text").innerHTML = "Projekte werden geladen!";
ReplaceAgePlaceholder();
ReplaceCurrentYearPlaceholder();
}
function ReplaceAgePlaceholder() {
let birthDate = new Date('2009-03-03');
let diffTime = Math.abs(_todayDate - birthDate);
let diffTimeInYears = diffTime / (1000 * 60 * 60 * 24 * 365.25);
let age = diffTimeInYears.toFixed(1);
document.body.innerHTML = document.body.innerHTML.replace("%AGE%", age);
}
function ReplaceCurrentYearPlaceholder() {
let fullCurrentYear = _todayDate.getFullYear();
document.body.innerHTML = document.body.innerHTML.replace("%CURRENT_YEAR%", fullCurrentYear);
}
function LoadGithubProjects(numberOfLoadedRepositories, numberOfShownRepositories) {
const sortOnKey = (key, descending) => {
return (a, b) => {
a = a[key];
b = b[key];
return descending ? b - a : a - b;
};
}
fetch(`https://api.github.com/users/fraujulian/repos?per_page=${numberOfLoadedRepositories}`)
.then((rawResponse) => rawResponse.json())
.then((allProjects) => {
allProjects = allProjects.sort(sortOnKey("stargazers_count", true));
let projectsDiv = document.getElementById("github_projects");
projectsDiv.innerHTML = "";
projectsDiv.classList = "";
for (let currentProjectIndex = 0; currentProjectIndex < numberOfShownRepositories; currentProjectIndex++) {
let currentProjectDiv = document.createElement("div");
currentProjectDiv.classList = "card hoverable";
let currentProject = allProjects[currentProjectIndex];
if (currentProject !== undefined &&
currentProject.fork !== true) {
if (currentProject.description == null) currentProject.description = "";
if (currentProject.language == null) currentProject.language = "";
currentProject.name = currentProject.name
.replaceAll("_", " ")
.replaceAll("-", " ");
currentProjectDiv.innerHTML = `
<div class="media">
<div class="media-body">
<a href="${currentProject.html_url}">
<strong class="d-block text-gray-dark">${currentProject.name}</strong>
</a>
<div class="stars">
${currentProject.language}
<i class="far fa-star stargazers"></i>${currentProject.stargazers_count}
</div>
</div>
<p>${currentProject.description}</p>
</div>
`;
fetch(`https://raw.githubusercontent.com/${currentProject.full_name}/${currentProject.default_branch}/README.md`)
.then((rawResponse) => rawResponse.text())
.then((readmeText) => {
let markdownToHtmlConverter = new showdown.Converter();
let readmeInHtml = markdownToHtmlConverter.makeHtml(readmeText);
let projectReadmeModalDiv = document.createElement("div");
projectReadmeModalDiv.classList = "modal github-modal hidden";
projectReadmeModalDiv.innerHTML = `
<div class="card">
<a onclick="" id="projectReadmeModalDiv-Close" style="float: right"> ❌</a>
<a href="${currentProject.html_url}"> Visit on GitHub</a>
<br>
<br>
${readmeInHtml}
</div>
`;
currentProjectDiv.onclick = function () {
projectReadmeModalDiv.classList.remove("hidden");
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
document.body.style.opacity = 0.2.toString();
}
projectReadmeModalDiv.onclick = function (mouseClick) {
if (mouseClick.target === projectReadmeModalDiv ||
mouseClick.target === document.getElementById("projectReadmeModalDiv-Close")) {
projectReadmeModalDiv.classList.add("hidden");
document.body.style.opacity = 1.0.toString();
}
}
document
.getElementsByTagName("html")[0]
.appendChild(projectReadmeModalDiv);
});
projectsDiv.appendChild(currentProjectDiv);
}
}
});
}
let _shortBioTextButton = document.getElementById("short-bio-text");
let _longBioText = document.getElementsByClassName("long-bio-text")[0];
let _isLongBioTextShown = true;
_shortBioTextButton.onclick = function () {
let leftArrow = document.getElementById("left-arrow");
let rightArrow = document.getElementById("right-arrow");
if (_isLongBioTextShown) {
_longBioText.classList.remove("hidden");
leftArrow.classList.remove("fa-arrow-right");
leftArrow.classList.add("fa-arrow-down");
rightArrow.classList.remove("fa-arrow-left");
rightArrow.classList.add("fa-arrow-down");
leftArrow.style.position = "relative";
rightArrow.style.position = "relative";
FadeOut(_longBioText);
} else {
_longBioText.classList.add("hidden");
leftArrow.classList.remove("fa-arrow-down");
leftArrow.classList.add("fa-arrow-right");
rightArrow.classList.remove("fa-arrow-down");
rightArrow.classList.add("fa-arrow-left");
leftArrow.style.position = "relative";
rightArrow.style.position = "relative";
FadeIn(_longBioText);
}
_isLongBioTextShown = !_isLongBioTextShown;
};
_longBioText.onclick = function (mouseClick) {
if (mouseClick.target === _longBioText) {
_longBioText.classList.add("hidden");
document.body.style.opacity = 1.0.toString();
}
};
function FadeOut(element) {
let currentOpacity = 1;
const fadeInterval = setInterval(() => {
if (currentOpacity <= 0.1) {
clearInterval(fadeInterval);
element.style.display = 'none';
return;
}
setElementOpacity(element, currentOpacity);
currentOpacity *= 0.9;
}, 5);
}
function FadeIn(element) {
let currentOpacity = 0.1;
element.style.display = 'block';
const fadeInterval = setInterval(() => {
if (currentOpacity >= 1) {
clearInterval(fadeInterval);
return;
}
setElementOpacity(element, currentOpacity);
currentOpacity *= 1.1;
}, 5);
}
function setElementOpacity(element, opacity) {
const opacityPercentage = opacity * 100;
element.style.opacity = opacity;
element.style.filter = `alpha(opacity=${opacityPercentage})`;
}
+11 -10
View File
@@ -44,7 +44,7 @@ html {
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
background-image: url("../img/background.webp");
background-image: url("Images/background.webp");
/*background-color: #2f3136; */
height: 100%;
}
@@ -133,6 +133,7 @@ ul.nav li.left {
#github_projects .stars {
color: var(--main-txt-color) !important;
float: right;
}
#github_projects a {
@@ -167,7 +168,7 @@ ul.nav li.left {
backdrop-filter: blur(150px);
}
.bio-text {
.long-bio-text {
font-size: 20px;
opacity: 0;
width: 60%;
@@ -276,11 +277,11 @@ ul.nav li.left {
cursor: pointer;
}
.icon-area a {
.contact-area a {
color: var(#9ee700);
}
.icon-area i {
.contact-area i {
justify-content: space-between;
width: var(--main-icon-width);
padding-top: var(--main-padding);
@@ -288,12 +289,12 @@ ul.nav li.left {
border-radius: var(--main-border-radius);
}
.icon-area i:hover {
.contact-area i:hover {
cursor: pointer;
backdrop-filter: blur(150px);
}
.js-reminder {
.warning-text {
font-style: normal;
font-weight: 900;
padding: var(--main-padding);
@@ -486,7 +487,7 @@ ul.nav li.left {
}
footer {
width: var(--main-container-width);
width: 90%;
}
ul.nav li,
@@ -508,7 +509,7 @@ ul.nav li.left {
margin-left: 10px;
}
.bio-text {
.long-bio-text {
width: 95% !important;
}
@@ -516,7 +517,7 @@ ul.nav li.left {
grid-template-columns: auto;
}
.icon-area i {
.contact-area i {
margin-top: var(--mobile-margin);
}
@@ -537,4 +538,4 @@ ul.nav li.left {
.short_desc {
width: var(--mobile-width);
}
}
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

+49 -52
View File
@@ -3,36 +3,33 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Julian Lechner</title>
<link rel="shortcut icon" type="image/png" href="favicon.ico" />
<link rel="icon" href="favicon.ico" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
<link rel="stylesheet" type="text/css" href="Resources/Style.css" />
<link rel="stylesheet" type="text/css" href="Style.css" />
<script rel="preload" src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script>
<script async rel="preload" src="Resources/Javascript.js"></script>
</head>
<body>
<div class="container">
<section class="container">
<div class="card profile">
<!-- BASIC INFORMATION -->
<img src="img/logo.png" width="200px" height="200px" fetchpriority="low">
<h1>Hii! 👋 I'm Julian Lechner!</h1>
<img src="Resources/Images/Logo.webp" width="200px" height="200px" fetchpriority="high" alt="Online Profilbild von Julian Lechner"/>
<h1>Hallo! 👋 I'm Julian Lechner!</h1>
<h3>📍 Austria, Vienna</h3>
<br>
<hr>
<!-- CLICKABLE TEXT > TO SEE BIO TEXT-->
<div class="max60">
<div id="short-desc" class="hover-items">
<div id="short-bio-text" class="hover-items">
<i id="left-arrow" class="fas fa-arrow-right"></i>
<a onclick="plausible('expandprofile')">
<a>
<u>
<h3>A young enthusiastic developer from Austria!</h3>
</u>
@@ -42,12 +39,9 @@
</div>
</div>
<!-- HIDDEN BIO TEXT -->
<div class="bio-text hidden">
<div class="long-bio-text hidden">
<p>
My name is Julian, many people also call me Julie. I'm
<script>let startDate = new Date('2009-03-03'); let today = new Date(); let diffTime = Math.abs(today - startDate); let diffYears = diffTime / (1000 * 60 * 60 * 24 * 365.25); document.write(diffYears.toFixed(1));</script>
years old and come from beautiful Austria. I spend most of my time in front of the computer.
My name is Julian, many people also call me Julie. I'm %AGE% years old and come from beautiful Austria. I spend most of my time in front of the computer.
<br />
<br />
My biggest hobby apart from software development is diving. Floating in deep water and only thinking
@@ -63,7 +57,7 @@
game servers etc. in various locations.
<br />
<br />
<a href="mailto:fraujulian@lechner.top" onclick="plausible('envelope')" target="_blank">
<a href="mailto:fraujulian@lechner.top">
<h3>Just contact me!</h3>
</a>
</p>
@@ -72,13 +66,13 @@
<hr>
<br>
<!-- JAVASCRIPT REMINDER -->
<p class="js-reminder">Enable JavaScript to see what I do.</p>
<noscript>
<h2 class="warning-text">Enable JavaScript to see more.</h2>
</noscript>
<!-- TOOLS/LANGUAGES/FRAMEWORKS -->
<div class="bio grid-container">
<div class="grid-item-start">
<h1>I code with</h1>
<h1>I work with</h1>
</div>
<div class="grid-item">
<h1>NodeJS</h1>
@@ -105,54 +99,57 @@
<h1>WPF</h1>
</div>
<div class="grid-item">
<h1>Docker</h1>
<h1>Avalonia</h1>
</div>
<div class="grid-item">
<h1>Linux</h1>
<h1>Ubuntu</h1>
</div>
<div class="grid-item">
<h1>Jetbrains</h1>
<h1>WebStorm</h1>
</div>
<div class="grid-item">
<h1>Rider</h1>
</div>
<div class="grid-item">
<h1>SSMS</h1>
</div>
<div class="grid-item">
<h1>MySQL</h1>
</div>
<div class="grid-item">
<h1>Java</h1>
</div>
</div>
<!-- ICONS -->
<div class="icon-area">
<a href="mailto:contact@fraujulian.xyz" onclick="plausible('envelope')" target="_blank">
<i class="fa-solid fa-envelope fa-3x"></i></a>
<div class="contact-area">
<a href="mailto:fraujulian@lechner.top">
<i class="fa-solid fa-envelope fa-3x"></i>
</a>
<a href="tel:+436609254001" onclick="plausible('phone')" target="_blank">
<i class="fa-solid fa-phone fa-3x"></i></a>
<a href="tel:+436609254001">
<i class="fa-solid fa-phone fa-3x"></i>
</a>
<a href="https://discord.com/users/860206216893693973" onclick="plausible('discord')" target="_blank">
<i class="fab fa-discord fa-3x"></i></a>
<a href="https://discord.com/users/860206216893693973">
<i class="fab fa-discord fa-3x"></i>
</a>
<a href="https://github.com/fraujulian" onclick="plausible('github')" target="_blank">
<i class="fab fa-github fa-3x"></i></a>
<a href="https://github.com/fraujulian">
<i class="fab fa-github fa-3x"></i>
</a>
</div>
</div>
<!-- GITHUB PROJECTS -->
<div id="github_projects" class="card">
<h2>Loading...</h2>
<h2 id="loading-text" class="warning-text">Enable JavaScript to see more.</h2>
</div>
</div>
</section>
<footer>
<!-- FOOTER -->
<p>
<a href="/imprint/">Imprint</a>
|
&copy;
2023 -
<script>document.write(new Date().getFullYear())</script> Julian Lechner - All rights reserved.
<a href="/IMPRINT/">IMPRINT</a> | &copy; 2023 - %CURRENT_YEAR% Julian Lechner - All rights reserved.
</p>
<!-- SCRIPTS -->
<script defer data-domain="fraujulian.xyz" src="https://plausible.io/js/plausible.js"></script>
<script rel="preload" src="Javascript.js"></script>
</footer>
</body>
</html>
</html>