/**
* 对数组进行排序,作为 Array.sort() 回调函数使用
*/
const sortArray = function (a, b) {
return a.nIdx - b.nIdx;
}
/**
* 判断 indexOf() 是否捕获到了搜索词
* @returns {boolean} 是否捕获
*/
function indexOfCatch(a) {
return a > -1
}
(function () {
class Commands {
query = ''
query_size = 5 //搜索框结果显示5条
page_size = 50 //每页显示20条
$$(id) {
return document.getElementById(id)
}
constructor() {
function $$(id) {
return document.getElementById(id)
}
this.commands = linux_commands || [];
this.elm_query = $$('query');
this.elm_btn = $$('search_btn');
this.elm_result = $$('result');
this.elm_search_result = $$('search_list_result');
// 获取根路径
this.root_path = (function () {
let elm_path = $$('current_path');
let url = window.location.origin + window.location.pathname;
return elm_path ? url.replace(/\/(c\/)?(\w|-)+\.html/, '').replace(/\/$/, '') : '';
})();
this.init();
this.goToIndex();
}
/**
* 前往主页
* @memberof Commands
*/
goToIndex() {
let elma = document.getElementsByTagName('A');
for (let i = 0; i < elma.length; i++) {
if (elma[i].pathname === '/' && !/^https?:/i.test(elma[i].protocol)) {
elma[i].href = this.root_path + '/';
}
}
}
/**
* 绑定事件
* 该函数有兼容性处理
* @param {HTMLElement} element 需要绑定事件的元素
* @param {*} type 需要绑定的类型
* @param {*} callback 事件触发回调
* @memberof Commands
*/
bindEvent(element, type, callback) {
if (element.addEventListener) {
element.addEventListener(type, callback, false);
} else if (element.attachEvent) {
element.attachEvent('on' + type, callback);
}
}
isSreachIndexOF(oldstr, kw) {
if (!oldstr || !kw) return -1;
return oldstr.toLowerCase().indexOf(kw.toLowerCase());
}
//获取URL上面的参数
getQueryString(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = decodeURIComponent(window.location.hash.replace(/^(\#\!|\#)/, '')).match(reg);
if (r != null) return unescape(r[2]); return null;
}
/**
* 通过 window.history 设置地址栏的地址
* @memberof Commands
*/
pushState() {
if (window.history && window.history.pushState)
if (this.query) {
history.pushState({}, "linux_commands", `#!kw=${this.query}`)
} else {
history.pushState({}, "linux_commands", window.location.pathname);
}
}
/**
* 一个简单的模板函数
*
* @param {string} str 传入的 HTML 模板
* @param {object} obj 一个对象,用于放置在 HTML 模板中
* @return {string} 经过处理的 HTML 模板
* @memberof Commands
*/
simple(str, obj) {
return str.replace(/\$\w+\$/gi, function (matchs) {
let returns = obj[matchs.replace(/\$/g, "")];
return typeof returns === "undefined" ? "" : returns;
})
}
/**创建 keyworlds HTML
* @param {*} json 根据这段 JSON 生成
* @param {*} keywolds 关键字
* @param {*} islist 表示这是否是一个列表
* @return {*} 返回一个 HTML 字符串
*/
createKeyworldsHTML(json, keywolds, islist) {
const listHTML = '<p></p>'
const replaceHTML = `<i class="kw">$1</i>`
let name = json.n
let des = json.d
let reg = new RegExp(`(${keywolds})`, "ig")
if (keywolds) {
name = json.n.replace(reg, replaceHTML);
des = json.d.replace(reg, replaceHTML) || '';
}
let rootp = this.root_path.replace(/\/$/, '');
const str = `<a href="${rootp}/c$url$.html"><strong>$name$</strong> - $des$</a>${islist ? listHTML : ''}`
return this.simple(str, {
name,
url: json.p,
des
});
}
/**搜索结果
* @param {boolean} islist 是否为列表*/
searchResult(islist = false) {
let arr = this.commands
const self = this
let page_size = arr.length
let arrResultHTML = []
const show_list_count = islist ? this.page_size : this.query_size;
let nameArr = [], desArr = [];
if (indexOfCatch(arr && arr.length && toString.call(arr).indexOf('Array'))) {
for (let i = 0; i < page_size; i++) {
if (!arr[i]) break;
const nIdx = self.isSreachIndexOF(arr[i].n, self.query);
const dIdx = self.isSreachIndexOF(arr[i].d, self.query);
let json = arr[i];
if (indexOfCatch(nIdx)) {
json.nIdx = nIdx;
nameArr.push(json);
} else if (indexOfCatch(dIdx)) {
json.dIdx = dIdx;
desArr.push(json);
}
}
}
nameArr.sort(sortArray);
desArr.sort(sortArray);
const resultData = nameArr.concat(desArr).slice(0, show_list_count);
resultData.forEach(a => {
arrResultHTML.push(self.createKeyworldsHTML(a, self.query, islist));
})
/** @type {HTMLElement} */
let elm = islist ? this.elm_search_result : this.elm_result;
elm.innerHTML = ''
arrResultHTML.forEach((result, i) => {
const el = document.createElement('li')
el.innerHTML = result
elm.appendChild(el);
})
if (!arrResultHTML.length) {
const noResultTipHTML = document.createElement("LI");
const tipSpan = document.createElement("span")
const nullQueryStringTips = `请尝试输入一些字符,进行搜索!`
const undefinedQueryTips = `没有搜索到任何内容,请尝试输入其它字符!`
tipSpan.innerText = this.query ? undefinedQueryTips : nullQueryStringTips
noResultTipHTML.appendChild(tipSpan);
elm.appendChild(noResultTipHTML);
}
}
/**
* 移动搜索结果的光标
* @param {"up"|"down"} type 触发事件类型
* @memberof Commands
*/
selectedResult(type) {
/** @type {Array} */
let items = this.elm_result.children;
let index = 0;
for (var i = 0; i < items.length; i++) {
if (items[i].className == 'ok') {
items[i].className = '';
if (type == 'up') index = i - 1;
else index = i + 1;
break;
};
};
if (items[index]) items[index].className = 'ok';
}
// 是否选中搜索结果
isSelectedResult() {
let items = this.elm_result.children;
let isSel = false;
for (let i = 0; i < items.length; i++) {
if (items[i].className == 'ok') {
isSel = items[i];
break;
};
};
return isSel;
}
init() {
/**
* 设定搜索结果的 CSS display 属性
*
* @param {string} [inputDisplay='none']
*/
function setdisplay(inputDisplay) {
self.elm_result.style.display = inputDisplay || 'none'
}
let self = this;
let kw = self.getQueryString('kw');
this.elm_query.value = kw;
this.query = kw || '';
if (this.elm_search_result) self.searchResult(true);
this.bindEvent(this.elm_query, 'input', function (e) {
self.query = e.target.value;
self.pushState()
if (self.query) {
self.searchResult();
} else {
setdisplay()
}
if (!self.elm_search_result) {
setdisplay(self.query ? 'block' : 'none')
} else {
self.elm_btn.click();
}
})
this.bindEvent(this.elm_btn, 'click', function (e) {
setdisplay();
if (self.elm_search_result) self.searchResult(true);
else window.location.href = self.root_path + '/list.html#!kw=' + self.query;
})
this.bindEvent(this.elm_query, 'focus', function (e) {
self.searchResult();
if
没有合适的资源?快使用搜索试试~ 我知道了~
Linux命令大全搜索工具.zip
共631个文件
md:599个
ejs:9个
json:5个
需积分: 5 0 下载量 140 浏览量
2023-10-17
20:26:36
上传
评论
收藏 2.8MB ZIP 举报
温馨提示
linux常用命令大全
资源推荐
资源详情
资源评论
收起资源包目录
Linux命令大全搜索工具.zip (631个子文件)
contributors.ejs 23KB
search.ejs 17KB
header.ejs 1KB
footer.ejs 1KB
list.ejs 674B
details.ejs 612B
hot.ejs 337B
footer.ejs 222B
index.ejs 192B
Linux.gif 1.28MB
chrome-extensions.gif 449KB
hcitool 2KB
favicon.ico 18KB
index.js 8KB
copy-to-clipboard.js 1KB
sitemap.js 716B
data.json 63KB
data.min.json 48KB
package.json 988B
renovate.json 148B
vercel.json 35B
git.md 36KB
awk.md 32KB
readelf.md 26KB
tar.md 23KB
iptables.md 22KB
curl.md 21KB
ls.md 19KB
strace.md 16KB
objdump.md 16KB
sed.md 14KB
setfacl.md 13KB
find.md 13KB
rsync.md 13KB
screen.md 13KB
gdb.md 12KB
firewall-cmd.md 12KB
wget.md 12KB
lilo.md 11KB
fdisk.md 10KB
docker.md 10KB
ssh.md 10KB
ps.md 10KB
ss.md 10KB
iperf.md 9KB
openssl.md 9KB
dmidecode.md 9KB
ln.md 9KB
hping3.md 8KB
sudo.md 8KB
dnf.md 8KB
grep.md 8KB
ip6tables.md 8KB
mkcert.md 8KB
bzip2.md 8KB
edquota.md 7KB
rpm.md 7KB
sort.md 7KB
netstat.md 7KB
date.md 7KB
ethtool.md 7KB
mpstat.md 7KB
tput.md 7KB
vi.md 6KB
quota.md 6KB
lsof.md 6KB
free.md 6KB
dstat.md 6KB
declare.md 6KB
export.md 6KB
htop.md 6KB
pidstat.md 6KB
crontab.md 6KB
pmap.md 6KB
tcpreplay.md 6KB
traceroute.md 6KB
kill.md 5KB
cpio.md 5KB
sysctl.md 5KB
pv.md 5KB
ab.md 5KB
rcp.md 5KB
ip.md 5KB
diff.md 5KB
xargs.md 5KB
ifconfig.md 5KB
script.md 5KB
tmux.md 5KB
trap.md 5KB
ag.md 5KB
nano.md 5KB
parted.md 5KB
tree.md 5KB
inotifywait.md 5KB
lspci.md 5KB
cp.md 5KB
useradd.md 5KB
journalctl.md 5KB
skill.md 5KB
fishshell.md 5KB
共 631 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
Matlab仿真实验室
- 粉丝: 2w+
- 资源: 2181
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
- 测试aaaaaaabbbbb
- VID20240521070643.mp4
- Android系统原理与开发学习要点详解-培训课件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功