forked from KorySchneider/tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (55 loc) · 10.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html><html>
<head>
<title>tab</title>
<meta charset="utf-8">
<link rel="icon" type="image/png" href="img/favicon.png">
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body, #app {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
}
#clock {
font-size: 120px;
font-weight: bold;
margin-top: -20vh;
margin-bottom: 30px;
display: none;
}
#input {
text-align: center;
font-size: 42px;
color: inherit;
background: transparent;
border: none;
outline: none;
width: 100%;
}
#message {
font-size: 16px;
margin-top: 42px;
text-align: center;
}
#clock,
#input,
#message {
font-family: "Helvetica Neue", Roboto, sans-serif;
}
</style>
</head>
<body>
<div id="app">
<div id="clock"></div>
<input id="input" type="text" autofocus autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
<div id="message"></div>
</div>
<script type="text/javascript">!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";!function(){var e={defaultCommand:"g",bgColor:"#282828",textColor:"#ebdbb2",showClock:!1,alwaysNewTab:!1,gistID:"",links:[]},t={cal:"gc",gk:"k",ddg:"dg","?":"help"},n=!1,o="",r=null;function a(){var r=document.querySelector("#input").value.trim();if(document.querySelector("#input").value="",document.querySelector("#message").innerHTML="",""!==r){o=r;for(var a=r.split(";"),s=a[0].toLowerCase(),c=0;c<a.length;c++)a[c]=a[c].trim();for(var l=Object.keys(p),u=Object.keys(t),g=!1,h=0;h<l.length;h++){if(s===l[h]){g=!0,a.shift();break}if(s===u[h]){g=!0,s=t[s],a.shift();break}}var d=!1;m(a[0])&&(d=!0,s=a.shift());var k=!1;if(!d&&!g)for(var v=0;v<e.links.length;v++)if(e.links[v].command==s){k=!0,s=a.shift();break}if("n"===a[a.length-1]&&(n=!0,a.pop()),d)i(f(s));else if(g)p[s](a);else if(k){var w=b(s);0==a.length?i(w.url):i(w.url+w.search+a.join(" "))}else p[e.defaultCommand](a);return!1}}function i(t){return n||e.alwaysNewTab?window.open(t,"_blank").focus():window.location.href=t,n=!1,!1}function s(){var t;Storage&&(null===localStorage.getItem("taabSettings")?localStorage.setItem("taabSettings",JSON.stringify(e)):e=JSON.parse(localStorage.getItem("taabSettings")),null!==localStorage.getItem("customCommands")&&((t=JSON.parse(localStorage.getItem("customCommands")))&&(e.links=t,l()),localStorage.removeItem("customCommands")))}function c(){document.querySelector("body").style.backgroundColor=e.bgColor,document.querySelector("body").style.color=e.textColor;var t=document.querySelector("#clock");e.showClock?t.style.display="inline":t.style.display="none"}function l(){localStorage.setItem("taabSettings",JSON.stringify(e))}function u(e,t){var n=document.querySelector("#message");r&&(n.innerHTML="",clearTimeout(r)),n.innerHTML=e,r=setTimeout(function(){n.innerHTML=""},t)}function f(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";return(/(http(s)?:\/\/.)/.test(e)?e:"http://"+e)+t+encodeURIComponent(n)}function g(){var e=new Date,t=e.getHours(),n=(t>12?t-12:t).toString(),o=("0"+e.getMinutes()).slice(-2);document.querySelector("#clock").innerText=n+":"+o,setTimeout(g,1e3)}function h(e){var t=e.which||e.keyCode;if(13===t)a();else if(38===t&&""!==o){var n=document.querySelector("#input");n.focus(),n.value=o,setTimeout(function(){n.setSelectionRange(n.value.length,n.value.length)},2)}}function d(t,n){var o=void 0;try{o=JSON.parse(t)}catch(e){return u("Error parsing config, see console for details",5e3),void console.log(e)}for(var r in o)e[r]=o[r];e.gistID=n,l(),c(),u("Config imported",5e3)}function m(e){return!(!/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(e)||e.includes(" "))}function b(t){for(var n=0;n<e.links.length;n++)if(t==e.links[n].command)return e.links[n];return null}window.onload=function(){s(),c(),document.querySelector("#input").focus(),document.querySelector("body").addEventListener("click",function(){document.querySelector("#input").focus()}),document.onkeydown=h,g()};var p={set:function(t){var n=function(e){return/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i.test(e)};switch(t[0]){case"defaultCommand":if(1===t.length){u("Default command: "+e.defaultCommand,5e3);break}Object.keys(p).includes(t[1])?(e.defaultCommand=t[1],u("Set default command to "+t[1],3e3)):u("Error: command "+t[1]+" not found; default command not changed",1e4);break;case"bgColor":if(1===t.length){u("Current background color: "+e.bgColor,8e3);break}n(t[1])?e.bgColor=t[1]:u("Error: invalid hex value",5e3);break;case"textColor":if(1===t.length){u("Current background color: "+e.textColor,8e3);break}n(t[1])?e.textColor=t[1]:u("Error: invalid hex value",5e3);break;case"newtab":case"alwaysNewTab":if(1===t.length){u("alwaysNewTab is "+(e.alwaysNewTab?"on":"off"),5e3);break}"on"===t[1]?e.alwaysNewTab=!0:"off"===t[1]?e.alwaysNewTab=!1:u("Must be set to either 'on' or 'off'",5e3);break;case"clock":if(1===t.length){u("Clock is "+(e.showClock?"on":"off"),5e3);break}"on"===t[1]?e.showClock=!0:"off"===t[1]?e.showClock=!1:u("Must be set to either 'on' or 'off'",5e3);break;case"defaults":localStorage.removeItem("taabSettings"),e={defaultCommand:"g",bgColor:"#282828",textColor:"#ebdbb2",showClock:!1,alwaysNewTab:!1,gistID:"",links:[]},s(),u("Settings reset to defaults",5e3);break;default:u('"'+t[0]+'" is not a valid setting',5e3)}l(),c()},link:function(n){switch(n.length){case 0:u('link is a builtin command<br>To search for "link" try g;link<br>',8e3);break;case 1:if("show"===n[0]){for(var o="",r=0;r<e.links.length;r++){var a=e.links[r];o+=a.command+" --\x3e "+a.url,""!==a.search&&(o+=" ("+a.search+")"),o+="<br>"}u(o,3e4);break}var i=b(n[0]);if(i){var s='"'+n[0]+'" links to '+i.url;""!==i.search&&(s+=" ("+i.search+")"),u(s,1e4)}break;case 2:case 3:if("delete"===n[1])for(var c=0;c<e.links.length;c++)n[0]==e.links[c].command&&(e.links.splice(c,1),u("Link "+n[0]+" deleted",5e3));else{for(var g=0;g<e.links.length;g++)if(e.links[g].command==n[0]){if(!confirm("Overwrite existing shortcut?"))return;for(var h=0;h<e.links.length;h++)e.links[h].command==n[0]&&e.links.splice(h,1)}if(Object.keys(p).includes(n[0])||Object.keys(t).includes(n[0]))return void u("Cannot override builtin command: "+n[0],5e3);var d=f(n[1]);if(!m(d))return void u("Invalid URL",5e3);e.links.push({command:n[0],url:d,search:n[2]||""})}}l()},config:function(t){switch(t[0]){case"export":u(localStorage.getItem("taabSettings"),25e3),window.getSelection().selectAllChildren(document.querySelector("#message"));break;case"import":d(t[1]);break;case"open":""!==e.gistID?(n=!0,p.gist([e.gistID])):u("Error: No gist ID found. Make sure you have fetched your config at least once.",8e3);break;case"fetch":var o=void 0;if(t.length>1)try{o=t[1].match(/([0-9A-Za-z]{32})/)[0]}catch(e){return void u("Error: unable to parse gist ID.<br>Try entering just the 32 character ID string.",8e3)}else{if(void 0==e.gistID){u("Error: no gist ID",5e3);break}o=e.gistID}u("Fetching gist...",2500),function(e){var t=new XMLHttpRequest,n="https://api.github.com/gists/"+e;t.onreadystatechange=function(){if(4==t.readyState&&200==t.status){var n=JSON.parse(t.responseText).files;if(n.length>1)return void u("Error: Multiple files found in gist. Please use a gist with only one file.",5e3);d(n[Object.keys(n)[0]].content,e)}},t.open("GET",n,!0),t.send(null)}(o)}},help:function(e){n=!0,i("https://github.com/koryschneider/tab#readme")},g:function(e){var t="https://google.com";0==e.length?i(t):i(f(t,"/search?q=",e))},dg:function(e){var t="https://duckduckgo.com";0==e.length?i(t):i(f(t,"/?q=",e))},r:function(e){var t,n="https://reddit.com",o=e.length>0?e[0]:"",r=function(e){return["hot","new","rising","controversial","top","gilded","wiki","promoted"].includes(e)};switch(e.length){case 0:i(n);break;case 1:i(f(n,"/r/",e[0]));break;case 2:i(n+"/r/"+(o+=r(e[1])?"/"+e[1]:""));break;case 3:["top","controversial"].includes(e[1])?o+=(t=e[2],["day","week","month","year","all"].includes(t)?"/"+e[1]+"?t="+e[2]:""):o+=r(e[1])?"/"+e[1]:"",i(n+"/r/"+o)}},hn:function(e){var t="https://news.ycombinator.com";if(0==e.length)i(t);else switch(e[0]){case"new":i(t+"/newest");break;case"comments":i(t+"/newcomments");break;case"show":i(t+"/show");break;case"ask":i(t+"/ask");break;case"jobs":i(t+"/jobs");break;case"submit":i(t+"/submit")}},y:function(e){var t="https://youtube.com";0==e.length?i(t):["subs","s"].includes(e[0])?i(t+"/feed/subscriptions"):i(f(t,"/results?search_query=",e[0]))},w:function(e){var t="https://wikipedia.org";0==e.length?i(t):i(f(t,"/w/index.php?title=Special:Search&search=",e.join(" ")))},gh:function(e){var t="https://github.com";0==e.length?i(t):i(t+"/"+e.join(""))},gist:function(e){var t="https://gist.github.com";0==e.length?i(t):i(t+"/"+e.join(""))},wa:function(e){var t="http://wolframalpha.com";0==e.length?i(t):i(f(t,"/input/?i=",e.join(" ")))},n:function(e){var t="https://netflix.com";0==e.length?i(t):i(f(t,"/search?q=",e.join(" ")))},imdb:function(e){var t="http://imdb.com";0==e.length?i(t):i(f(t,"/find?s=all&q=",e.join(" ")))},map:function(e){var t="https://google.com/maps";0==e.length?i(t):i(f(t,"/search/",e.join(" ")))},gd:function(e){var t="https://drive.google.com";0==e.length?i(t):i(f(t,"/drive/search?q=",e.join(" ")))},gc:function(e){i("https://calendar.google.com")},img:function(e){var t="https://google.com";0==e.length?i(t):i(f(t,"/search?tbm=isch&q=",e.join(" ")))},gm:function(e){var t="https://mail.google.com";0==e.length?i(t):i(f(t,"/mail/u/0/#search/",e.join(" ")))},k:function(e){var t="https://keep.google.com";0==e.length?i(t):i(f(t,"/#search/text=",e.join(" ")))},tr:function(e){var t="https://trello.com";0==e.length?i(t):i(f(t,"/search?q=",e.join(" ")))},dict:function(e){var t="http://dictionary.com";0==e.length?i(t):i(f(t,"/browse/",e.join(" ")))},thes:function(e){var t="http://thesaurus.com";0==e.length?i(t):i(f(t,"/browse/",e.join(" ")))},a:function(e){var t="https://amazon.com";0==e.length?i(t):i(f(t,"/s/?field-keywords=",e.join(" ")))},npm:function(e){var t="https://npmjs.org";0==e.length?i(t):i(f(t,"/search?q=",e.join(" ")))},pypi:function(e){var t="https://pypi.org";0==e.length?i(t):i(f(t,"/search/?q=",e.join(" ")))},so:function(e){var t="https://stackoverflow.com";0==e.length?i(t):i(f(t,"/search?q=",e.join(" ")))},mdn:function(e){var t="https://developer.mozilla.org";0==e.length?i(t):i(f(t,"/search?q=",e.join(" ")))}}}()}]);</script></body>
</html>