-
Notifications
You must be signed in to change notification settings - Fork 545
/
index.html
179 lines (163 loc) · 5.97 KB
/
index.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<base href="$$.RootPath$$">
<title>Shiori - Bookmarks Manager</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="assets/res/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/res/apple-touch-icon-144x144.png">
<link rel="icon" type="image/png" href="assets/res/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="assets/res/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/x-icon" href="assets/res/favicon.ico">
<link href="assets/css/style.css" rel="stylesheet">
<script src="assets/js/vue.min.js"></script>
<script src="assets/js/url.min.js"></script>
</head>
<body class="night">
<div id="main-scene" :class="{night: appOptions.NightMode}">
<div id="main-sidebar">
<a v-for="item in sidebarItems" :title="item.title" :class="{active: activePage === item.page}" @click="switchPage(item.page)">
<i class="fas fa-fw" :class="item.icon"></i>
</a>
<div class="spacer"></div>
<a title="Logout" @click="logout">
<i class="fas fa-fw fa-sign-out-alt"></i>
</a>
</div>
<keep-alive>
<component :is="activePage" :active-account="activeAccount" :app-options="appOptions" @setting-changed="saveSetting"></component>
</keep-alive>
<custom-dialog v-bind="dialog" />
</div>
<script type="module">
import basePage from "./assets/js/page/base.js";
import pageHome from "./assets/js/page/home.js";
import pageSetting from "./assets/js/page/setting.js";
import customDialog from "./assets/js/component/dialog.js";
import EventBus from "../assets/js/component/eventBus.js";
Vue.prototype.$bus = EventBus;
var app = new Vue({
el: '#main-scene',
mixins: [basePage],
components: {
pageHome,
pageSetting,
customDialog
},
data: {
activePage: "page-home",
sidebarItems: [{
title: "Home",
icon: "fa-home",
page: "page-home",
}, {
title: "Setting",
icon: "fa-cog",
page: "page-setting",
}],
},
methods: {
switchPage(page) {
var pageName = page.replace("page-", ""),
state = { activePage: page },
url = new Url;
if (page === 'page-home' && this.activePage === 'page-home') {
Vue.prototype.$bus.$emit('clearHomePage', {});
}
url.hash = pageName;
this.activePage = page;
history.pushState(state, page, url);
},
logout() {
this.showDialog({
title: "Log Out",
content: "Are you sure you want to log out ?",
mainText: "Yes",
secondText: "No",
mainClick: () => {
this.dialog.loading = true;
fetch(new URL("api/logout", document.baseURI), {
method: "post"
}).then(response => {
if (!response.ok) throw response;
return response;
}).then(() => {
localStorage.removeItem("shiori-account");
localStorage.removeItem("shiori-token");
document.cookie = `session-id=; Path=${new URL(document.baseURI).pathname}; Expires=Thu, 01 Jan 1970 00:00:00 GMT;`;
location.href = new URL("login", document.baseURI);
}).catch(err => {
this.dialog.loading = false;
this.getErrorMessage(err).then(msg => {
this.showErrorDialog(msg);
})
});
}
});
},
saveSetting(opts) {
this.appOptions = opts;
document.body.className = opts.config.NightMode ? "night" : "";
},
loadSetting() {
var opts = JSON.parse(localStorage.getItem("shiori-account")) || {},
ShowId = (typeof opts.config.ShowId === "boolean") ? opts.config.ShowId : false,
ListMode = (typeof opts.config.ListMode === "boolean") ? opts.config.ListMode : false,
HideThumbnail = (typeof opts.config.HideThumbnail === "boolean") ? opts.config.HideThumbnail : false,
HideExcerpt = (typeof opts.config.HideExcerpt === "boolean") ? opts.config.HideExcerpt : false,
NightMode = (typeof opts.config.NightMode === "boolean") ? opts.config.NightMode : false,
KeepMetadata = (typeof opts.config.KeepMetadata === "boolean") ? opts.config.KeepMetadata : false,
UseArchive = (typeof opts.config.UseArchive === "boolean") ? opts.config.UseArchive : false,
CreateEbook = (typeof opts.config.CreateEbook === "boolean") ? opts.config.CreateEbook : false,
MakePublic = (typeof opts.config.MakePublic === "boolean") ? opts.config.MakePublic : false;
this.appOptions = {
ShowId: ShowId,
ListMode: ListMode,
HideThumbnail: HideThumbnail,
HideExcerpt: HideExcerpt,
NightMode: NightMode,
KeepMetadata: KeepMetadata,
UseArchive: UseArchive,
CreateEbook: CreateEbook,
MakePublic: MakePublic,
};
document.body.className = NightMode ? "night" : "";
},
loadAccount() {
var account = JSON.parse(localStorage.getItem("shiori-account")) || {},
id = (typeof account.id === "number") ? account.id : 0,
username = (typeof account.username === "string") ? account.username : "",
owner = (typeof account.owner === "boolean") ? account.owner : false;
this.activeAccount = {
id: id,
username: username,
owner: owner,
};
}
},
mounted() {
// Load setting
this.loadSetting();
this.loadAccount();
// Prepare history state watcher
var stateWatcher = (e) => {
var state = e.state || {};
this.activePage = state.activePage || "page-home";
}
window.addEventListener('popstate', stateWatcher);
this.$once('hook:beforeDestroy', function () {
window.removeEventListener('popstate', stateWatcher);
})
// Set initial active page
var initialPage = (new Url).hash || "home";
if (initialPage === "home" || initialPage === "setting") {
this.activePage = `page-${initialPage}`;
} else {
history.replaceState(null, "page-home", "/#home");
}
}
})
</script>
</body>
</html>