-
Notifications
You must be signed in to change notification settings - Fork 116
/
selectP.html
76 lines (73 loc) · 2.59 KB
/
selectP.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
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>Bilibili v.mini</title>
<link rel="stylesheet" href="css/child-window.css">
</head>
<body>
<div id="wrapper">
<span id="close" @click="closeWindow">x</span>
<div id="select-part" class="list">
<p class="list-title">视频分Part</p>
<div class="item part" :class="{'current-ep': index === currentPartId}" v-for="(title, index) in partList" :title="title" @click="selectPart(index)"><span v-show="index == currentPartId">● </span>{{ index + 1 }}) {{ title }}</div>
<div class="item part" :class="{'current-ep': part.epid === currentPartId}" v-for="part in bangumiPartList" :title="part.title" @click="selectBangumiPart(part)"><span v-show="part.epid == currentPartId">● </span>{{ part.epid + 1 }}) {{ part.title }}</div>
</div>
</div>
<script src="js/vue.min.js"></script>
<script>
const ipc = require('electron').ipcRenderer;
const remote = require('electron').remote;
const v = new Vue({
el: '#wrapper',
data: {
partList: null,
bangumiPartList: null,
currentPartId: 0
},
methods: {
selectPart(index) {
this.currentPartId = index;
ipc.send('select-part', index + 1);
},
selectBangumiPart(part) {
this.currentPartId = part.epid;
ipc.send('select-bangumi-part', part);
},
closeWindow() {
remote.getCurrentWindow().hide();
}
}
});
// 更新分p列表
ipc.on('update-part', (ev, partList) => {
v.currentPartId = 0;
v.partList = partList;
v.bangumiPartList = null;
});
// 番剧分p
ipc.on('update-bangumi-part', (ev, data) => {
v.currentPartId = data.currentPartId;
v.partList = null;
v.bangumiPartList = data.parts;
});
// 监听webview url改变
// https://github.com/chitosai/bilimini/issues/66
// 阿B现在支持自动跳转下一页了,这种情况下的跳转不会经过我们的代码触发_isLastNavigationSelectPart,
// 于是会被路由当作是打开了新视频而重新获取分p,currentPartId也因此被重置回0。我们一方面在路由那边加判断来防止重复获取同一个视频的分p,
// 另一方面每当webview加载了新的url时,就让路由把最新的url广播出来,然后这里我们监听这个事件并解析当前应该显示第几p
ipc.on('url-changed', (ev, url) => {
const m = /p\=(\d+)/.exec(url);
if (m) {
v.currentPartId = Number(m[1]) - 1;
} else {
v.currentPartId = 0;
}
});
window.onerror = function(err, f, line) {
var id = f.split('/');
utils.error(`${id[id.length-1]} : Line ${line}\n> ${err}`);
}
</script>
</body>
</html>