forked from yuameshi/PhiCommunity-Bak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.redirect.js
73 lines (71 loc) · 2.69 KB
/
index.redirect.js
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
window.addEventListener('DOMContentLoaded', () => {
fetch('https://api.github.com/repos/HanHan233/PhiCommunity/commits').then(
(response) => {
response.json().then((data) => {
const changeLogFrame=document.querySelector('div#changelogContainer');
data.forEach(commit => {
const item=document.createElement('a');
item.classList.add('item');
item.href=commit.html_url;
item.setAttribute('data-sha',commit.sha.slice(0,7));
item.innerText=commit.commit.message;
changeLogFrame.appendChild(item);
});
});
}
);
const addBtn = document.querySelector('#installPWA');
addBtn.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
addBtn.style.display = 'unset';
addBtn.addEventListener('click', () => {
e.prompt();
e.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('准备添加到主屏幕');
} else {
console.log('用户拒绝了添加到主屏幕');
}
});
});
});
document.querySelector('button#go').addEventListener('click',()=>{
location.href='../tapToStart/index.html';
});
document.querySelector('button#gotoCFPages').addEventListener('click',()=>{
location.href='https://cf.phi.han-han.xyz';
});
document.querySelector('button#gotoGHPages').addEventListener('click',()=>{
location.href='https://phi.han-han.xyz';
});
if (location.href.match('cf.phi.han-han.xyz')) { // 检测是否为CF节点
document.querySelector('button#gotoCFPages').style.display='none';
}else{
document.querySelector('button#gotoGHPages').style.display='none';
}
document.querySelector('button#ghRepo').addEventListener('click',()=>{
window.open('https://github.com/HanHan233/PhiCommunity');
});
document.querySelector('button#deviceReq').addEventListener('click',()=>{
document.querySelector('div#devRequirementPopupoverlay').classList.add('show');
});
document.querySelector('div#devRequirementPopupoverlay').addEventListener('click',(e)=>{
if(e.target!=document.querySelector('#devReq')){
document.querySelector('div#devRequirementPopupoverlay').classList.remove('show');
}
});
document.querySelector('button#changeLog').addEventListener('click',()=>{
document.querySelector('div#changeLogContainerPopupOverlay').classList.add('show');
});
document.querySelector('div#changeLogContainerPopupOverlay').addEventListener('click',(e)=>{
if(e.target!=document.querySelector('#changelogContainer')){
document.querySelector('div#changeLogContainerPopupOverlay').classList.remove('show');
}
});
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function () {
console.log('Service Worker Registered');
});
}