const baseURL = "https://yyets.dmesg.app/"; const resourceURL = baseURL + "resource.html?id="; const indexURL = baseURL + "?id=index"; // const indexURL = "css/index.json" function loadJSON(path, success, error) { let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { if (success) success(JSON.parse(xhr.responseText)); } else { if (error) error(xhr); } } }; xhr.open("GET", path, true); xhr.send(); } function doSearch() { let search = document.getElementById("kw"); if (kw !== "undefined") { search.value = kw; } let data = JSON.parse(localStorage.getItem("index")); let div = document.getElementById("tv"); let found = false for (let v in data) { if (v.toLowerCase().indexOf(kw) !== -1) { found = true let name = v.replace(/\n/g, " ") let id = data[v] let html = `

${name}

`; let backup = div.innerHTML; div.innerHTML = backup + html; } } if (found === false) { div.innerHTML = `

没有搜索到结果 (ノへ ̄、)

` } } function reloadIndex() { loadJSON(indexURL, function (data) { let jsonText = JSON.stringify(data); localStorage.setItem("index", jsonText); }, function (xhr) { console.error(xhr); }); }