Files
frost-navigation/docs/js/script.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-09-06 00:20:58 +08:00
// 查找字符 tChar 在 str 中第 num 次出现的位置
2019-09-18 21:38:10 +08:00
/* 使
2019-09-06 00:20:58 +08:00
function findChar(str, tChar, num) {
var charPos = str.indexOf(tChar);
num = num - 1;
if (num > 0) {
for (var i = 0; i < num; i++) {
charPos = str.indexOf(tChar, charPos + 1);
}
}
return charPos;
}
2019-09-06 17:38:31 +08:00
*/
2019-09-06 00:20:58 +08:00
2019-09-06 17:38:31 +08:00
// 加载列表
2019-09-18 21:38:10 +08:00
// Slinky 插件的 Option
var SlinkyOption = {
title: true,
speed: 200
};
2019-09-06 17:38:31 +08:00
var ListID = "#list_"
var ListCount = 0;
2019-09-18 21:38:10 +08:00
// 列表总数
var ListCountMax = 17;
2019-09-06 00:20:58 +08:00
function loadList() {
2019-09-06 17:38:31 +08:00
ListCount = ListCount + 1;
2019-09-07 13:21:06 +08:00
ListID = "#list_" + ListCount;
$(ListID).slinky(SlinkyOption);
// 加载完毕
2019-09-06 17:38:31 +08:00
if (ListCount == ListCountMax) {
2019-09-18 21:38:10 +08:00
clearInterval(I_LoadList);
setTarget();
displayList();
// document.title = "Frost 网址导航";
2019-09-06 17:38:31 +08:00
}
}
2019-09-18 21:38:10 +08:00
// main 中的 A 标签的对象的集合(链接列表)
var LinkList = document.getElementsByTagName("main")[0].getElementsByTagName("a");
2019-09-06 17:38:31 +08:00
// 设置 target = "_blank"
2019-09-18 21:38:10 +08:00
2019-09-06 17:38:31 +08:00
function setTarget() {
for (var i = 0; i < LinkList.length; i++) {
if (LinkList[i].href.endsWith("#") == false) {
2019-09-18 21:38:10 +08:00
LinkList[i].target = "_blank";
/* 使
var slashPos = findChar(LinkList[i].href, '/', 3);
2019-09-18 21:38:10 +08:00
getFavicon = "https://www.google.cn/s2/favicons?domain=" + LinkList[i].href.substring(0, slashPos);
2019-09-06 00:20:58 +08:00
var imgTag = "<img src='" + getFavicon + "' />";
LinkList[i].insertAdjacentHTML("beforeBegin", imgTag);
2019-09-06 00:20:58 +08:00
*/
}
}
}
// 显示列表
2019-09-18 21:38:10 +08:00
2019-09-06 00:20:58 +08:00
function displayList() {
document.getElementsByTagName("main")[0].style.opacity = "1";
document.getElementsByClassName("fullscreen-text")[0].style.opacity = "0";
setTimeout("document.getElementsByClassName('fullscreen-text')[0].style.display = 'none';", 1000);
}
2019-09-18 21:38:10 +08:00
// 加载列表,间隔 100 毫秒
2019-09-06 17:38:31 +08:00
var I_LoadList = setInterval("loadList()", 100);
2019-09-06 23:54:10 +08:00
// 搜索框
2019-09-18 21:38:10 +08:00
2019-09-06 23:54:10 +08:00
var SearchMode = 1;
2019-09-18 21:38:10 +08:00
// 搜索面板
var SearchPanel = document.getElementsByClassName("search-panel")[0];
// 搜索输入框
var SearchInput = document.getElementsByClassName("search-input")[0];
// 搜索结果
var SearchResult = document.getElementsByClassName("search-result")[0];
2019-09-06 23:54:10 +08:00
var SearchResultItem = "";
function search() {
2019-09-18 21:38:10 +08:00
// 循环次数
var LinkListCount = LinkList.length;
// 搜索关键词
var SearchWord = SearchInput.value.toLowerCase();
2019-09-06 23:54:10 +08:00
if (SearchMode == 1 && SearchWord != "") {
2019-09-18 21:38:10 +08:00
// 清空搜索结果
SearchResult.innerHTML = "";
for (var i = 0; i < LinkListCount; i++) {
if (LinkList[i].href.endsWith("#") == false) {
if (LinkList[i].innerText.toLowerCase().indexOf(SearchWord) != -1 || LinkList[i].href.indexOf(SearchWord) != -1) {
SearchResultItem = LinkList[i].cloneNode(true);
SearchResult.appendChild(SearchResultItem);
}
2019-09-06 23:54:10 +08:00
}
}
} else if (SearchMode == 1 && SearchWord == "") {
SearchResult.innerHTML = "请输入关键词";
} else if (SearchMode == 2) {
2019-09-18 21:38:10 +08:00
// 清空输入框
SearchInput.value = "";
// 清空搜索结果
SearchResult.innerHTML = "";
// 隐藏搜索面板
SearchPanel.style.visibility = "hidden";
2019-09-06 23:54:10 +08:00
}
}