-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.a193b9d8.js
255 lines (208 loc) · 7.5 KB
/
main.a193b9d8.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
var nodeRequire = typeof require === 'function' && require;
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = cache[name] = new newRequire.Module(name);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}
return cache[name].exports;
function localRequire(x){
return newRequire(localRequire.resolve(x));
}
function resolve(x){
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function (id, exports) {
modules[id] = [function (require, module) {
module.exports = exports;
}, {}];
};
var error;
for (var i = 0; i < entry.length; i++) {
try {
newRequire(entry[i]);
} catch (e) {
// Save first error but execute all entries
if (!error) {
error = e;
}
}
}
if (entry.length) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(entry[entry.length - 1]);
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = mainExports;
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(function () {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
// Override the current require with this new one
parcelRequire = newRequire;
if (error) {
// throw error from earlier, _after updating parcelRequire_
throw error;
}
return newRequire;
})({"epB2":[function(require,module,exports) {
var $siteList = $('.siteList');
var $lastLi = $siteList.find('li.last');
/* 初始时从 LocalStorage 中读取对应的 hash */
var x = localStorage.getItem('x') || 'null'; // 将读取的字符串 变为 对象
var xObject = JSON.parse(x); // hashMap 初始化保底值
var hashMap = xObject || [{
logo: 'A',
url: 'https://www.acfun.cn',
logoICO: 'https://www.acfun.cn/favicon.ico'
}, {
logo: 'B',
url: 'https://www.bilibili.com',
logoICO: 'https://www.bilibili.com/favicon.ico'
}];
/* 显示链接 缩短 */
var simplifyUrl = function simplifyUrl(url) {
return url.replace('https://', '').replace('http://', '').replace('www.', '').replace(/\/.*/, ''); // 删除以 / 开头的内容 贪婪匹配
};
/* 操作 hashMap 渲染页面 */
var render = function render() {
/* 再次渲染 hashMap 之前必须先 清空原来的 */
// 找到 的除了 lastLi 之外的所有 li
$siteList.find('li:not(.last)').remove();
hashMap.forEach(function (node, index) {
// console.log(node.logoICO)
var showLogo = "<img src = ".concat(node.logoICO, ">");
var $li = $("\n <li>\n <div class=\"site\">\n <div class=\"logo\">".concat(showLogo, "</div>\n <div class=\"link\">").concat(simplifyUrl(node.url), "</div>\n <div class=\"close\">\n <svg class=\"icon\">\n <use xlink:href=\"#icon-close\"></use>\n </svg>\n </div>\n </div>\n </li>\n ")).insertBefore($lastLi); // 用JS操作 点击跳转
$li.on('click', function () {
// console.log(node.url);
window.open(node.url, '_self');
}); // 阻止冒泡
$li.on('click', '.close', function (e) {
// console.log('阻止冒泡')
e.stopPropagation(); // console.log(hashMap);
// console.log(index);
hashMap.splice(index, 1);
render();
});
});
};
render();
/* 添加收藏 点击事件处理 */
$('.addButton').on('click', function () {
var url = window.prompt("请输入网址");
/* 网址合法行判断 */
if (url.indexOf("www.") !== 0 && url.indexOf("http") !== 0) {
url = 'www.' + url;
console.log(url);
}
if (url.indexOf("http") !== 0) {
url = 'https://' + url;
console.log(url);
} // console.log(url)
hashMap.push({
logo: simplifyUrl(url)[0].toUpperCase(),
url: url,
logoICO: url + '/favicon.ico'
});
render();
}); // 获取焦点
window.onload = function () {
// $('.searchInput').focus(); // < input autofocus >
$('.searchForm').attr("action", "./search.html");
/* 监听输入 提交事件 存储输入字符 */
$('#bingGo').submit(function () {
var searchInput = document.getElementById("searchInput").value; // console.log(searchInput);
var string = JSON.stringify(searchInput); // console.log(string);
localStorage.setItem('searchResult', string); // console.log(localStorage);
});
}; // 退出网站 用户关闭网站前触发 存到 localStorage 里
window.onbeforeunload = function () {
// console.log('页面要关闭了') // 可以开启 Preserve log 查看
// // 将 对象变为 字符串
var string = JSON.stringify(hashMap); // console.log(typeof hashMap)
// console.log(hashMap)
// console.log(typeof string)
// console.log(string)
localStorage.setItem('x', string);
}; // 监听键盘事件 点击跳转相应网站
$(document).on('keypress', function (e) {
// console.log(e.keyCode)
// console.log(e.key)
/*
const key = e.key
变量名 和 属性名一样
可以简写为
const {key} = e
解构赋值
*/
var key = e.key; // console.log(key);
for (var i = 0; i < hashMap.length; i++) {
if (hashMap[i].logo.toLowerCase() === key) {
// console.log(hashMap[i].logo)
// location.href = hashMap[i].url // 模拟用户在地址栏输入
window.open(hashMap[i].url, '_blank');
}
}
}); // 搜索框 键盘事件 阻止冒泡
$('.searchForm').on('keypress', function (e) {
e.stopPropagation();
});
/*
window.onload = () => {
$("body").addClass("bgp");
console.log("min");
} */
},{}]},{},["epB2"], null)
//# sourceMappingURL=main.a193b9d8.js.map