Skip to content
Permalink
ee6a06b16b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
100 lines (95 sloc) 2.94 KB
function $(query) {
return document.querySelector(query)
}
//Mapping time to text
var currentTod = $('#current-time');
var docTitle = $('title');
var date = new Date();
var hour = date.getHours();
var humanTime;
if (hour > 20 || hour <= 6) humanTime = "night";
else if (hour > 17) humanTime = "evening";
else if (hour > 12) humanTime = "afternoon";
else if (hour > 6) humanTime = "morning";
currentTod.innerHTML = humanTime;
// Current Time
var time = $('#time')
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function setTime() {
var d = new Date();
var h = d.getHours();
var amPm = 'AM'
if (h == 0) h = 12;
if (h >= 12) amPm = "PM"
if (h > 12) h -= 12;
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
time.innerHTML = h + ":" + m + ' ' + amPm;
}
setTime();
var currentTime = setInterval(setTime, 1000)
// Unsplash Fun Times
var background = $('body');
var imageCred = $('#unsplash-author')
function getBg() {
fetch(`https://source.unsplash.com/1600x900/?${humanTime}`)
.then((response) => {
background.style.backgroundImage = `linear-gradient(90deg, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0.4) 100%),url('${response.url}')`;
imageCred.href = response.url;
})
}
getBg();
//saving name to local storage
var name = $('#name');
name.addEventListener('input', setName)
function setName(e) {
let userName = e.target.textContent
localStorage.setItem('name', userName)
}
var lsName = localStorage.getItem('name')
if (lsName) name.innerHTML = lsName;
// Radio Button
var page;
var tod = $('#tod');
var todSection = $('#tod-section')
var prod = $('#prod')
var prodSection = $('#productivity')
var notes = $('#notes')
var notesSection = $('#notes-section')
tod.addEventListener('click', switchTabs)
notes.addEventListener('click', switchTabs)
if (localStorage.getItem('activeTab') == null) localStorage.setItem('activeTab', 'tod')
$(`#${localStorage.getItem('activeTab')}`).classList.add('active')
$(`#${localStorage.getItem('activeTab')}-section`).classList.remove('hidden')
function switchTabs(e) {
let id = e.srcElement.id
if (id == 'tod') {
tod.classList.add('active')
todSection.classList.remove('hidden')
//prod.classList.remove('active')
//prodSection.classList.add('hidden')
notes.classList.remove('active')
notesSection.classList.add('hidden')
localStorage.setItem('activeTab', 'tod')
} else if (id == "notes") {
tod.classList.remove('active')
todSection.classList.add('hidden')
notes.classList.add('active')
notesSection.classList.remove('hidden')
localStorage.setItem('activeTab', 'notes')
}
}
// Notepad
var notepad = $('textarea')
notepad.addEventListener('input', saveNotes)
var lsNotes = localStorage.getItem('notes')
if (lsNotes) notepad.innerHTML = lsNotes;
function saveNotes(e) {
console.log(e);
localStorage.setItem('notes', e.target.value);
}