first commit
This commit is contained in:
76
js/newTab.js
Normal file
76
js/newTab.js
Normal file
@@ -0,0 +1,76 @@
|
||||
class NewTab {
|
||||
constructor() {
|
||||
// chrome.history.search({
|
||||
// text: ''
|
||||
// }, function (results) {
|
||||
// console.log(results);
|
||||
// })
|
||||
this.input = document.querySelector(".search input");
|
||||
this.input.focus();
|
||||
|
||||
this.ThemeClickChange();
|
||||
this.SearchInput();
|
||||
this.clearSearch();
|
||||
}
|
||||
|
||||
clearSearch () {
|
||||
var clear = document.querySelector(".clear");
|
||||
console.log(clear);
|
||||
clear.onclick = () => {
|
||||
this.input.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主题切换
|
||||
*/
|
||||
ThemeClickChange () {
|
||||
var body = document.querySelector("body"),
|
||||
theme = document.querySelector(".themeChange img");
|
||||
|
||||
// 当前为黑夜
|
||||
if (localStorage.getItem("status") != null) {
|
||||
body.className = "night";
|
||||
theme.setAttribute("src", "./img/day.svg")
|
||||
localStorage.setItem("status", "night")
|
||||
}
|
||||
|
||||
theme.onclick = () => {
|
||||
// 如果当前白天,切换为黑夜
|
||||
if (body.classList.length == 0) {
|
||||
body.className = "night";
|
||||
theme.setAttribute("src", "./img/day.svg")
|
||||
localStorage.setItem("status", "night")
|
||||
} else {
|
||||
body.className = "";
|
||||
theme.setAttribute("src", "./img/night.svg");
|
||||
localStorage.removeItem("status")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
SearchInput() {
|
||||
this.input.onkeydown = (event) => {
|
||||
if (event.keyCode == 13) {
|
||||
if (this.input.value.length != 0) {
|
||||
window.open(`https://www.google.com/search?q=${this.input.value}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new NewTab()
|
||||
|
||||
// chrome.bookmarks.getTree(function (result) {
|
||||
// console.log(result);
|
||||
// })
|
||||
|
||||
|
||||
|
||||
// chrome.system.cpu.getInfo(function (res) {
|
||||
// console.log(res);
|
||||
// });
|
||||
Reference in New Issue
Block a user