Files
tilde/index.html
T

217 lines
5.5 KiB
HTML

<!doctype html>
<title>~</title>
<meta charset="utf-8">
<meta name="robots" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>WebFontConfig={google:{families:['Lato:300:latin']}};</script>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js" async></script>
<style type="text/css">
* {
box-sizing: border-box;
}
body {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #fff;
color: #111;
font-family: 'Lato', sans-serif;
}
main {
position: absolute;
top: 50%;
width: 100%;
transform: translateY(-98px);
text-align: center;
}
time {
font-size: 5rem;
letter-spacing: 6px;
}
form {
margin-top: 2rem;
}
input {
width: 90%;
max-width: 310px;
padding: 10px 15px;
background-color: #222;
border-radius: 2px;
color: #fff;
font-family: 'Lato', sans-serif;
font-size: 1.1rem;
}
input,
input:focus {
border: 0;
outline: 0;
-webkit-appearance: none;
}
aside {
position: fixed;
left: -180px;
width: 100%;
max-width: 180px;
height: 100%;
padding: 15px 25px;
background-color: #fff;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.4);
transition: transform 700ms;
overflow: auto;
z-index: 1;
}
aside[data-toggled='true'] {
transform: translateX(180px);
}
h1 {
margin: 0 0 15px;
line-height: 1rem;
}
ul {
margin: 0;
padding: 0;
}
li {
list-style: none;
line-height: 1.5em;
}
span {
font-family: 'Courier New', monospace;
}
a {
color: #000;
font-size: 0.8rem;
}
</style>
<main>
<time id="js-clock"></time>
<form id="js-search-form" autocomplete="off">
<input id="js-search-input" type="text" autofocus>
</form>
</main>
<aside id="js-sidebar">
<h1>~</h1>
<ul id="js-help"></ul>
</aside>
<script>
'use strict';
(function() {
var clock = document.getElementById('js-clock');
function leftpad(num) {
return ('0' + num.toString()).slice(-2);
}
function setTime() {
var date = new Date();
var hours = leftpad(date.getHours());
var minutes = leftpad(date.getMinutes());
clock.innerHTML = hours + ' ' + minutes;
}
setTime();
setInterval(setTime, 1000);
})();
(function(opts) {
var sidebar = document.getElementById('js-sidebar');
var searchForm = document.getElementById('js-search-form');
var searchInput = document.getElementById('js-search-input');
var searchHelp = document.getElementById('js-help');
opts.commands.forEach(function(command) {
var li = document.createElement('li');
var key = document.createElement('span');
var link = document.createElement('a');
key.innerHTML = command.key + ': ';
link.href = command.url;
link.innerHTML = command.name;
li.appendChild(key);
li.appendChild(link);
searchHelp.appendChild(li);
});
searchForm.addEventListener('keyup', function() {
var q = searchInput.value;
if (q === '?') {
sidebar.setAttribute('data-toggled', true);
searchInput.value = '';
}
});
searchForm.addEventListener('submit', function(event) {
event.preventDefault();
if (searchInput.value === '') return false;
var redirect = opts.defaultCommand + encodeURIComponent(q);
var q = searchInput.value.split(opts.delimiter);
opts.commands.forEach(function(command) {
if (q[0] === command.key) {
if (q[1] && command.search) {
q.shift();
var search = encodeURIComponent(q.join(opts.delimiter).trim());
redirect = command.url + command.search + search;
} else {
redirect = command.url;
}
}
});
window.location.href = redirect;
}, false);
})({
delimiter: ' ',
defaultCommand: 'https://www.google.com/search?q=',
commands: [
{ key: 'a', name: 'Amazon', url: 'https://www.amazon.com', search: '/s/?field-keywords=' },
{ key: 'd', name: 'Drive', url: 'https://drive.google.com/drive', search: '/search?q=' },
{ key: 'e', name: 'Egghead', url: 'https://egghead.io', search: '/search?q=' },
{ key: 'f', name: 'Facebook', url: 'https://www.facebook.com', search: '/search/top/?q=' },
{ key: 'g', name: 'GitHub', url: 'https://github.com', search: '/search?q=' },
{ key: 'h', name: 'Hacker News', url: 'https://hn.algolia.com', search: '/?query=' },
{ key: 'i', name: 'Inbox', url: 'https://inbox.google.com', search: '/search/' },
{ key: 'k', name: 'Keep', url: 'https://keep.google.com', search: '/#search/text=' },
{ key: 'K', name: 'Khan Academy', url: 'https://www.khanacademy.org', search: '/search?page_search_query=' },
{ key: 'p', name: 'Product Hunt', url: 'https://www.producthunt.com', search: '/search?q=' },
{ key: 'r', name: 'Reddit', url: 'https://www.reddit.com', search: '/search?q=' },
{ key: 's', name: 'Stack Exchange', url: 'https://stackexchange.com', search: '/search?q=' },
{ key: 'S', name: 'SoundCloud', url: 'https://soundcloud.com', search: '/search?q=' },
{ key: 't', name: 'Twitter', url: 'https://twitter.com', search: '/search?q=' },
{ key: 'u', name: 'Unsplash', url: 'https://unsplash.com', search: '/search?keyword=' },
{ key: 'y', name: 'YouTube', url: 'https://www.youtube.com', search: '/results?search_query=' }
]
});
</script>