Repository navigation
Expand file tree
/
Copy pathidx.js
More file actions
112 lines (92 loc) · 3.19 KB
/
Copy pathidx.js
File metadata and controls
112 lines (92 loc) · 3.19 KB
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
//idx.js
(() => {
const ページを入れ替える = (フォルダ, ページ名, 履歴に保存 = true) => {
// 【ここを追加!】httpから始まる場合はそのまま、それ以外は今までの処理
const ファイルパス = フォルダ.startsWith('http')
? フォルダ
: (フォルダ.includes('.html') ? フォルダ : `${フォルダ}/index.html`);
const 表示エリア = document.getElementById('表示場所');
if (!表示エリア) return;
表示エリア.style.opacity = 0;
fetch(ファイルパス).then(r => r.text()).then(t => {
表示エリア.innerHTML = t;
// ページ切り替え時にフィルターをリセット
activeFilters = [];
// スクリプトの強制実行
表示エリア.querySelectorAll('script').forEach(oldScript => {
const newScript = document.createElement('script');
newScript.textContent = oldScript.textContent;
document.body.appendChild(newScript).parentNode.removeChild(newScript);
});
表示エリア.style.opacity = 1;
window.scrollTo(0, 0);
// フッター・アイコンの制御
const footerLink = document.querySelector('footer .btn');
const homeIcon = document.getElementById('home-icon');
if (ページ名 !== 'home') {
if (footerLink) footerLink.setAttribute('onclick', "window.site.changePage('home', 'home')");
if (homeIcon) homeIcon.style.display = 'inline';
} else {
if (footerLink) footerLink.setAttribute('onclick', "window.site.changePage('owner', 'owner')");
if (homeIcon) homeIcon.style.display = 'none';
}
// 【重要】URLを ?p=ページ名 に書き換えて保存
if (履歴に保存) {
history.pushState({ フォルダ: フォルダ, 名前: ページ名 }, '', `?p=${ページ名}`);
}
});
};
let activeFilters = [];
const フィルター実行 = (category) => {
const items = document.getElementsByClassName("item");
const allBtn = document.getElementById('btn-all');
if (!allBtn) return;
if (category === 'all') {
activeFilters = [];
} else {
const index = activeFilters.indexOf(category);
if (index > -1) {
activeFilters.splice(index, 1);
} else {
activeFilters.push(category);
}
}
document.querySelectorAll('.filter-menu button').forEach(btn => {
btn.classList.remove('active');
});
if (activeFilters.length === 0) {
allBtn.classList.add('active');
} else {
activeFilters.forEach(cat => {
const target = document.getElementById('btn-' + cat);
if (target) target.classList.add('active');
});
}
for (let i = 0; i < items.length; i++) {
if (activeFilters.length === 0) {
items[i].classList.remove("hide");
} else {
const hasMatch = activeFilters.some(cat => items[i].classList.contains(cat));
items[i].classList.toggle("hide", !hasMatch);
}
}
};
window.site = {
changePage: ページを入れ替える,
toggleFilter: フィルター実行
};
// 戻るボタン対応
window.onpopstate = (イベント) => {
if (イベント.state) {
ページを入れ替える(イベント.state.フォルダ, イベント.state.名前, false);
} else {
location.reload();
}
};
// 初期読み込み
const params = new URLSearchParams(window.location.search);
const currentP = params.get('p') || 'home';
ページを入れ替える(currentP, currentP, false);
// スマホ用 active 有効化
document.addEventListener("touchstart", () => {}, {passive: true});
})();