Repository navigation
Expand file tree
/
Copy pathdata.js
More file actions
145 lines (133 loc) · 4.96 KB
/
Copy pathdata.js
File metadata and controls
145 lines (133 loc) · 4.96 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
init()
function setBackground() {
let background = localStorage.getItem('background')
if (background !== undefined && background !== null) {
let bodyObj = document.getElementById("body")
if (background.startsWith("data:image")) {
bodyObj.style.backgroundImage = "url('" + background + "')"
} else {
bodyObj.style.backgroundColor = background
}
}
}
function init() {
if (!localStorage.getItem(localStorageIndexKey)) {
localStorage.setItem(localStorageKey + '-' + 1, 'https://www.google.com/search?q=')
localStorage.setItem(localStorageKey + '-' + 2, 'https://cn.bing.com/search?ensearch=1&q=')
localStorage.setItem(localStorageKey + '-' + 3, 'https://www.baidu.com/s?wd=')
localStorage.setItem(localStorageKey + '-' + 4, 'https://www.sogou.com/web?query=')
localStorage.setItem(localStorageKey + '-' + 5, 'https://www.so.com/s?q=')
localStorage.setItem(localStorageIndexKey, 1)
localStorage.setItem(localStorageSumKey, 5)
}
checkNetwork()
setBackground();
initTodo();
setClickListener();
setDeleteListener();
}
// 设置稍后读删除事件
function setDeleteListener() {
let tableI = document.getElementsByName("todo-table-i")
for (let i = 0; i < tableI.length; i++) {
tableI[i].onclick = function () {
let todoJson = localStorage.getItem('todo')
let todoObj = JSON.parse(todoJson)
todoObj.splice(this.getAttribute('index'), 1)
localStorage.setItem('todo', JSON.stringify(todoObj))
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode)
}
}
}
// 设置稍后读点击事件
function setClickListener() {
let todoLi = document.getElementsByName("todo-table-td")
for (let i = 0; i < todoLi.length; i++) {
todoLi[i].onclick = function () {
window.open(this.getAttribute("url"), '_blank')
}
}
}
function initTodo() {
let todo = ''
let todoJson = localStorage.getItem('todo')
let todoObj = JSON.parse(todoJson)
if (todoObj === null) {
return
}
for (let i = 0; i < todoObj.length; i++) {
todo += '<tr style="height: 50px;">' +
' <td style="width: 80%;" name="todo-table-td" class="mdui-ripple" url="' + todoObj[i].url + '">' +
' <h3 style="padding-left: 2%;">' + todoObj[i].title + '</h3>' +
' </td>' +
' <td style="width: 17%;">记录时间: ' + formatDateTime(new Date(todoObj[i].time)) + '</td>' +
' <td style="width: 3%;">' +
' <button class="mdui-btn mdui-ripple" name="todo-table-i" index="' + i + '">' +
' <i class="mdui-icon material-icons">delete</i>' +
' </button>' +
' </td>' +
'</tr>'
}
document.getElementById('todo-table').innerHTML = todo
}
function checkNetwork() {
if (getSearchEngineIndex() === 1) {
let startTime
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 1) {
startTime = Date.now()
}
if (xhr.readyState === 4 && xhr.status !== 200) {
mdui.snackbar({
message: '检测到谷歌网络不可用, 建以切换至百度',
timeout: 3000,
position: 'right-bottom'
})
symbol = 2
}
if (xhr.readyState === 4 && xhr.status === 200) {
if ((Date.now() - startTime) > 2500) {
mdui.snackbar({
message: '谷歌网络延迟偏高, 建议使用百度',
timeout: 3000,
position: 'right-bottom'
})
}
}
}
xhr.timeout = 5000
xhr.open("GET", "https://www.google.com", true);
xhr.send()
}
}
// 根据index获取对应的搜索引擎
function getSearchEngine(val) {
return localStorage.getItem(localStorageKey + '-' + val)
}
// 获取当前搜索引擎index
function getSearchEngineIndex() {
return parseInt(localStorage.getItem(localStorageIndexKey))
}
// 获取当前搜索引擎总数
function getSearchEngineSum() {
return parseInt(localStorage.getItem(localStorageSumKey))
}
function setSearchEngineIndex(val) {
localStorage.setItem(localStorageIndexKey, val)
}
function formatDateTime(inputTime) {
let date = new Date(inputTime)
let y = date.getFullYear()
let m = date.getMonth() + 1
m = m < 10 ? ('0' + m) : m
let d = date.getDate()
d = d < 10 ? ('0' + d) : d
let h = date.getHours()
h = h < 10 ? ('0' + h) : h
let minute = date.getMinutes()
let second = date.getSeconds()
minute = minute < 10 ? ('0' + minute) : minute
second = second < 10 ? ('0' + second) : second
return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
}