Repository: sciooga/Keyboard-launch
Branch: master
Commit: 0c1d18e5deaf
Files: 5
Total size: 12.3 KB
Directory structure:
gitextract_nid99y7k/
├── LICENSE
├── README.md
└── web/
├── index.html
├── main.css
└── main.js
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2017
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# Keyboard-launch
Simple and useful, one key to launch, so beautiful.
简单与实用,一键直达,很是优雅。
http://i.huguotao.com
感谢 [ldong](https://github.com/ldong) 将其发布至 Chrome webstore ,下载连接:[Keyboard-launch](https://chrome.google.com/webstore/detail/keyboard-launch/oocaffggffdbbefcmjbgkpbgehpnbadh)
================================================
FILE: web/index.html
================================================
新标签页
================================================
FILE: web/main.css
================================================
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f2f2f2;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
font-family: Sans-serif;
}
/*-----------SEARCH-----------*/
#search {
height: 40px;
width: 500px;
font-size: 1em;
padding: 0 10px;
position: absolute;
top: 20%;
left: 50%;
margin-left: -250px;
box-sizing: border-box;
}
#search:focus {
outline: 1px solid #eee;
}
#search::-ms-input-placeholder {
text-align: center;
}
#search::-webkit-input-placeholder {
text-align: center;
}
/*-----------KEYBOARD-----------*/
#keyboard {
width: 860px;
position: absolute;
bottom: 20%;
left: 50%;
margin-left: -430px;
}
#keyboard ul {
padding: 0px;
margin: 16px;
height: 50px;
text-align: center;
display: block;
}
#keyboard ul li {
cursor: pointer;
position: relative;
display: inline-block;
margin: 0 4px;
height: 54px;
border-radius: 10px;
-webkit-box-shadow: inset 0 0 1px 0px #eee;
-moz-box-shadow: inset 0 0 1px 0px #eee;
box-shadow: inset 0 0 1px 0px #eee;
}
#keyboard ul span {
height: 16px;
width: 16px;
margin: 0px 2px;
padding: 16px 22px;
background: #999;
color: #333;
border-radius: 8px;
display: inline-block;
list-style: none;
border-top: 1px solid #fff;
background: #fff;
-webkit-box-shadow: inset 0 0 36px #ddd, 0 3px 0 #ddd, 0 4px 2px #666;
-moz-box-shadow: inset 0 0 36px #ddd, 0 3px 0 #ddd, 0 4px 2px #666;
box-shadow: inset 0 0 36px #ddd, 0 3px 0 #ddd, 0 4px 2px #666;
}
#keyboard ul li:hover, #keyboard ul li.keyDownLi {
margin: 0px 5px;
border-bottom: 3px solid #fff;
box-shadow: inset 0 0px 8px #333;
-moz-box-shadow: inset 0 0px 8px #333;
-webkit-box-shadow: inset 0 0px 8px #333;
}
#keyboard ul li:hover span, #keyboard ul li span.keyDownSpan {
padding: 15px 20px 16px;
margin: 1px 3px 0px;
border-top: 1px solid #fafafa;
-webkit-box-shadow: inset 0 0 28px 5px #d2d2d2;
-moz-box-shadow: inset 0 0 28px 5px #d2d2d2;
box-shadow: inset 0 0 28px 5px #d2d2d2;
-webkit-transform: scale(.98);
-moz-transform: scale(.98);
-o-transform: scale(.98);
}
.fav {
width: 16px;
height: 16px;
position: absolute;
left: 8px;
bottom: 8px;
opacity: .4;
}
/*-----------KEYBOARD-----------*/
#setting {
position: absolute;
bottom: -320px;
height: 320px;
width: 100%;
box-sizing: border-box;
padding: 20px 20%;
color: #666;
background: #fff;
box-shadow: 0 0 12px #ccc;
transition: bottom .3s;
}
#setting .slideSwitch {
display: inline-block;
vertical-align: bottom;
background: #e4e4e4;
height: 20px;
width: 38px;
border-radius: 10px;
cursor: pointer;
}
#setting .slideSwitch:after {
content: "";
display: block;
position: relative;
top: 2px;
left: 2px;
background: #fff;
height: 16px;
width: 16px;
border-radius: 8px;
transition: all .2s;
box-shadow: 0 2px 1px rgba(0,0,0,0.4);
}
#setting .slideSwitch.active {
background: #4bd863;
}
#setting .slideSwitch.active:after {
left: 20px;
}
#setting .close {
display: inline-block;
text-align: center;
border: 1px solid #ccc;
line-height: 40px;
height: 40px;
width: 40px;
border-radius: 40px;
cursor: pointer;
}
#setting .close:hover {
border: 1px solid #999;
color: #222;
}
#setting table {
width: 100%;
}
#setting table td {
width: 50%;
padding: 10px 22px;
}
#setting table td:first-child {
text-align: right;
}
#setting a {
font-size: 12px;
color: #999;
text-decoration: none;
}
================================================
FILE: web/main.js
================================================
;(function() {
var version = '1.0.0',
keys = {},
$search = document.querySelector('#search'),
$keyboard = document.querySelector('#keyboard'),
$keys = document.querySelectorAll('#keyboard li'),
$setting = document.querySelector('#setting'),
$close = document.querySelector('.close'),
$newWindow = document.querySelector('#newWindow'),
$searchEngine = document.querySelector('#searchEngine')
// init
if (localStorage.version != version) {
localStorage.version = version
localStorage.newWindow = 0
localStorage.searchEngine = 'https://www.baidu.com/s?wd='
localStorage[67] = 'https://www.coding.net'
localStorage[72] = 'https://huguotao.com'
localStorage[84] = 'https://www.taobao.com'
localStorage[86] = 'https://www.v2ex.com'
localStorage[87] = 'https://www.weibo.com'
}
for (var i in $keys) {
if (!$keys.hasOwnProperty(i)) continue
keys[$keys[i].dataset.key] = {
'li': $keys[i],
'span': $keys[i].firstElementChild
}
}
// set favicon
for (var i = 48; i < 91; i++) {
var url = localStorage[i]
if (url) addFavicon(keys[i]['li'], getFavicon(url))
}
// read settings
if (~~localStorage.newWindow) {
$newWindow.classList.add('active')
} else {
$newWindow.classList.remove('active')
}
$searchEngine.value = localStorage.searchEngine
function getFavicon(url) {
return url.split('/').slice(0,3).join('/') + "/favicon.ico"
}
function addFavicon($li, src) {
var img = document.createElement('img')
img.src = src
img.className = 'fav'
$li.appendChild(img)
}
function keyDown(key) {
if (!key) return
keys[key]['span'].classList.add('keyDownSpan')
keys[key]['li'].classList.add('keyDownLi')
}
function keyUp(key) {
if (!key) return
keys[key]['span'].classList.remove('keyDownSpan')
keys[key]['li'].classList.remove('keyDownLi')
}
function openUrl(url) {
if (~~localStorage.newWindow) {
window.open(url)
} else {
location.href = url
}
}
$search.onkeyup = function(e) {
if (e.target.value == '设置') return $setting.style.bottom = 0
var key = e.which || e.keyCode || 0;
if (key == 13) openUrl(localStorage.searchEngine + e.target.value)
}
$close.onclick = function() {
$setting.style.bottom = '-320px'
}
var keyCache = 0
document.onkeydown = function(e) {
var key = e.which || e.keyCode || 0
keyCache = key
if (key == 9) {
window.event ? window.event.returnValue = false : e.preventDefault()
if (document.activeElement == $search) {
$search.blur()
} else {
$search.focus()
}
}
keyDown(key)
}
document.onkeyup = function(e) {
var key = e.which || e.keyCode || 0,
url = localStorage[key]
keyUp(key)
if (url && key == keyCache && document.activeElement != $search) openUrl(url)
keyCache = 0
}
$keyboard.onclick = function(e) {
if (e.target.tagName != 'SPAN') return
var name = e.target.innerText,
key = e.target.parentElement.dataset.key || 0,
url = prompt("请输入按键 " + name + " 对应的网址", localStorage[key] || '')
if (url === null) return
if (url && url.indexOf('http') != 0) url = 'http://' + url
localStorage[key] = url
location.reload()
}
$newWindow.onclick = function() {
this.classList.toggle('active')
localStorage.newWindow = +!!!~~localStorage.newWindow
}
$searchEngine.onchange = function(e) {
localStorage.searchEngine = e.target.value
}
})()