Skip to content

Commit

Permalink
recreated startpage
Browse files Browse the repository at this point in the history
  • Loading branch information
Yimche committed Oct 14, 2024
1 parent 37ebcf1 commit 2c5d62a
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 3 deletions.
25 changes: 25 additions & 0 deletions meta/scripts/lastfm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const request = new XMLHttpRequest();

request.open('GET', 'https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=yimche&api_key=c70ac96baa4d4d456b3d3de853a3e67b&format=json');
request.send();

request.onreadystatechange = () => {
if (request.status === 200) {

// look at the response
console.log(request.response);

const recenttracks = JSON.parse(request.response).recenttracks;

if (!recenttracks.track || !recenttracks.track.length) {
console.log('track is empty');
return;
}

const artist = recenttracks.track[0].artist['#text'];
const song = recenttracks.track[0].name;

console.log(song);
document.getElementById("now-playing").innerHTML = artist + ' - ' + song;
}
};
148 changes: 148 additions & 0 deletions meta/scripts/startpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
const firstName = "julian"; //Update your own name here.
var weekDays = [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
];
var months = [
"january",
"february",
"march",
"april",
"may",
"june",
"july",
"august",
"september",
"october",
"november",
"december",
];

function getWelcomeTime(hours) {
var welcomeString = "";
if (5 <= hours && hours < 12) welcomeString = "good morning, ";
else if (12 <= hours && hours < 16) welcomeString = "good afternoon, ";
else if (16 <= hours && hours < 19) welcomeString = "good evening, ";
else welcomeString = "good night, ";
return welcomeString;
}

function getNumSuffix(num) {
// 1st, 2nd, 3rd, 4th, 5th,
if (num == 1 || num == 21) return "st";
if (num == 2 || num == 22) return "nd";
if (num == 3 || num == 23) return "rd";
else return "th";
}

function updateTime() {
var curTime = new Date();
var hours = curTime.getHours();
var minutes = curTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
var day = weekDays[curTime.getDay()];
var month = months[curTime.getMonth()];
var dayNum = curTime.getDate();

var welcomeString = getWelcomeTime(hours) + firstName + ".";
var clockString = hours + ":" + minutes;
var dateString = day + ", " + month + " " + dayNum + getNumSuffix(dayNum);

document.getElementById("welcome").innerHTML = welcomeString;
document.getElementById("clock").innerHTML = clockString;
document.getElementById("date").innerHTML = dateString;
}

setInterval(updateTime, 10);

//function handleKeyPress(event) {
// if (event.key === 'Enter') {
// performSearch();
// }
//}
//
//function performSearch() {
// var searchTerm = document.querySelector('input').value;
// if (searchTerm.trim() !== '') {
// if (searchTerm.trim().includes('https://')) {
// window.location.href = searchTerm.trim();
// } else if (
// searchTerm.trim().includes('www.') ||
// searchTerm.trim().includes('.org') ||
// searchTerm.trim().includes('.com') ||
// searchTerm.trim().includes('.net') ||
// searchTerm.trim().includes('.gov') ||
// searchTerm.trim().includes('.edu') ||
// searchTerm.trim().includes('.co') ||
// searchTerm.trim().includes('.io')
// ) {
// window.location.href = 'https://' + encodeURI(searchTerm.trim());
// } else if (
// searchTerm.trim().includes('127.0.0.1') &&
// searchTerm.trim().includes('.html')
// ) {
// window.location.href = 'http://' + searchTerm;
// } else {
// // var googleSearchUrl = 'https://www.google.com/search?q=' + encodeURIComponent(searchTerm);
// var duckSearchUrl = 'https://duckduckgo.com/?q=' + encodeURIComponent(searchTerm)
// window.location.href = duckSearchUrl;
// }
// document.querySelector('input').value = '';
// }
//}

const search = document.getElementById('search');

search.addEventListener('input', function() {
const query = search.value.toLowerCase();
const allLists = document.querySelectorAll('.links');

allLists.forEach(linkList => {
const links = linkList.getElementsByTagName('li');

// Loop through the links and show/hide based on the filter
Array.from(links).forEach(link => {
const text = link.textContent || link.innerText;
if (text.toLowerCase().includes(query)) {
link.style.display = ""; // Show the link
} else {
link.style.display = "none"; // Hide the link
}
});
});
});

search.addEventListener('input', resizeInput);
function resizeInput() {
this.style.width = this.value.length + "ch";
}

search.addEventListener('keypress', handleKeyPress);
function handleKeyPress(event) {
if (event.key === 'Enter') {
const allLists = document.querySelectorAll('.links');
let visibleLinks = [];

allLists.forEach(linkList => {
const links = linkList.getElementsByTagName('li');

// Collect visible links
Array.from(links).forEach(link => {
if (link.style.display !== "none") {
visibleLinks.push(link);
}
});
});
if (visibleLinks.length === 1) {
const url = visibleLinks[0].querySelector('a').href; // Assuming each li contains an <a> tag
window.location.href = url; // Navigate to the link
}
}
}
59 changes: 59 additions & 0 deletions st.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>~/Startpage</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/style.css"> <!-- fix this -->
<link rel="alternate" type="application/atom+xml" href="/en.atom">
</head>
<body id="startpage">
<main>
<div class="search-container">
<span>> </span>
<input type="text" id="search" placeholder="" autofocus/>
<span class="blinking">_</span>
</div>
<div id="welcome"></div>
<div class="time">
<span id="clock"></span>
<span id="date"></span>
</div>

<div class="bookmarks">
<div class="category">
<div class="scroll">
<div class="links">
<span class="title-uni">uni</span>
<li><a href="https://wattlecourses.anu.edu.au">wattle</a></li>
<li><a href="https://programsandcourses.anu.edu.au/">p and c</a></li>
<li><a href="https://gitlab.cecs.anu.edu.au/">gitlab</a></li>
<li><a href="https://echo360.net.au/courses">echo360</a></li>
</div>
</div>
</div>

<div class="category">
<div class="scroll">
<div class="links">
<span class="title-dev">dev</span>
<li><a href="https://github.com/">github</a></li>
<li><a href="https://wiki.archlinux.org">arch wiki</a></li>
<li><a href="https://hoogle.haskell.org">hoogle</a></li>
</div>
</div>
</div>

<div class="category">
<div class="scroll">
<div class="links">
<span class="title-play">play</span>
<li><a href="https://youtube.com/feed/subscriptions">youtube</a></li>
<li><a href="https://instagram.com/direct">instagram</a></li>
<li><a href="https://last.fm/user/Yimche">last.fm</a></li>
<li><a href="https://www.webtoons.com/en/favorite">webtoons</a></li>
</div>
</div>
</div>
<script src="/meta/scripts/startpage.js"></script>
</main></body></html>
113 changes: 110 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
@font-face {
font-family: "Iosevka";
src: url("/meta/fonts/IosevkaNerdFont-Medium.ttf") format("truetype");
src: url( "/meta/fonts/IosevkaTermNerdFontMono-Medium.ttf") format("truetype");
}

@font-face {
font-family: "JetBrains Mono Medium";
src: url("/meta/fonts/JetBrainsMono-Medium.ttf") format("truetype");
}



:root{
--font: "Iosevka";
--rosewater: #f4dbd6;
Expand Down Expand Up @@ -90,3 +88,112 @@ li{
font-family:var(--font);
}

/* startpage */
body#startpage{
max-width:60em;
margin:auto;
padding:5px;
padding-top: 15px;
font-family:var(--font);
font-size:2em;
line-height:1.5em;
background-color:var(base);
color:var(--text);
}
body#startpage main{
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
display:block;
}
body#startpage input{
border: none;
background: transparent;
font-family: "JetBrains Mono Medium";
font-size: 1em;
color: var(--text);
outline: none;
caret-color: transparent;
box-sizing: unset;
padding-left: 1ch;
width: 0px;
}
body#startpage div{
display: flex;
align-items: center;
justify-content: center;
}
body#startpage div.search-container{
flex-direction: row;
}
body#startpage .time{
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
body#startpage #clock{
color: var(--text);
margin-right: 10px;
}
body#startpage #date{
color: var(--text);
margin-left: 10px;
}
body#startpage .bookmarks{
display: flex;
align-items: start;
font-size: 1em;
line-height: 1.25em;
}
body#startpage .category{
margin: 15px;
height: 5em;
width: 5em;
padding: 15px;
background-color: var(--mantle);
overflow: hidden;
}
body#startpage .scroll{
height: inherit;
width: inherit;
align-items: initial;
overflow: scroll;
}
body#startpage .title-uni{
color: var(--red);
}
body#startpage .title-dev{
color: var(--sapphire);
}
body#startpage .title-play{
color: var(--green);
}
body#startpage .links{
display:block;
}
body#startpage li{
list-style-type: none;
}
body#startpage a{
color: var(--text);
}
.blinking {
animation: opacity 1s ease-in-out infinite;
opacity: 1;
}
@keyframes opacity {
0% {
opacity: 1;
}

50% {
opacity: 0;
}

100% {
opacity: 1;
}
}

0 comments on commit 2c5d62a

Please sign in to comment.