|
@@ -98,9 +98,12 @@
|
|
|
let tags = document.getElementById('tags');
|
|
|
res.forEach(tag => {
|
|
|
let input = document.createElement('input');
|
|
|
+ let tagsFromLocal = getTagsFromLocal();
|
|
|
// 如果是location.href 包含tag,则设置为选中状态, href 要反编译以识别中文
|
|
|
if (decodeURI(location.href).indexOf(tag) !== -1) {
|
|
|
input.checked = true;
|
|
|
+ }else if (tagsFromLocal.indexOf(tag) !== -1) {
|
|
|
+ input.checked = true;
|
|
|
}
|
|
|
input.type = 'checkbox';
|
|
|
input.id = tag;
|
|
@@ -121,9 +124,37 @@
|
|
|
checkboxes.forEach(checkbox => {
|
|
|
checkbox.onclick = function () {
|
|
|
search();
|
|
|
+ setTagsToLocal();
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
+ function getAllCheckedTags() {
|
|
|
+ let elements = document.querySelectorAll('input[name="category"]:checked');
|
|
|
+ // 获取values
|
|
|
+ elements = Array.from(elements).map(ele => ele.value);
|
|
|
+ return elements;
|
|
|
+ }
|
|
|
+
|
|
|
+ function setTagsToLocal() {
|
|
|
+ // 如果是location.href 包含tag,则return,否则存储到localStorage
|
|
|
+ if (decodeURI(location.href).indexOf("tag") !== -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 存储到localStorage
|
|
|
+ let tags = getAllCheckedTags();
|
|
|
+ localStorage.setItem('tags', JSON.stringify(tags));
|
|
|
+ }
|
|
|
+ function getTagsFromLocal() {
|
|
|
+ if (decodeURI(location.href).indexOf("tag") !== -1) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ let tags = localStorage.getItem('tags');
|
|
|
+ if (tags) {
|
|
|
+ tags = JSON.parse(tags);
|
|
|
+ return tags;
|
|
|
+ }
|
|
|
+ return [];
|
|
|
+ }
|
|
|
|
|
|
function showModel() {
|
|
|
document.getElementById('mask').style.display = 'block';
|