forked from chitosai/bilimini
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.html
205 lines (200 loc) · 8.34 KB
/
config.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!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="config-list" class="list">
<!-- 不透明度 -->
<p class="list-title">窗口不透明度</p>
<div class="item item-range"><input type="range" class="range" v-model="opacity" min="0.1" max="1" step="0.01"></div>
<!-- 老板键 -->
<p class="list-title">老板键</p>
<div class="item">
<input type="text" class="input" v-model="hideShortcut">
<span class="btn btn-submit" @click="saveHideShortcut">确定</span>
</div>
<!-- 使用pc版浏览首页 -->
<p class="list-title">使用pc版浏览首页</p>
<div class="item">
<input type="radio" id="use-pc-y" value="1" class="input w10px" v-model="isUsePcVersion">
<label for="option-y">是</label>
<label> </label>
<input type="radio" id="use-pc-n" value="2" class="input w10px" v-model="isUsePcVersion">
<label for="option-n">否</label>
<span class="btn btn-submit" @click="saveIsUsePcVersion">保存</span>
</div>
<!-- 雀魂双击自定义窗口大小 -->
<p class="list-title">雀魂双击自定义窗口大小、位置</p>
<div class="item">
<span class="label">X</span>
<input type="text" class="input M" v-model="majsoulCustomPositionX">
</div>
<div class="item">
<span class="label">Y</span>
<input type="text" class="input M" v-model="majsoulCustomPositionY">
</div>
<div class="item">
<span class="label">宽</span>
<input type="text" class="input M" v-model="majsoulCustomSizeW">
</div>
<div class="item">
<span class="label">高</span>
<input type="text" class="input M" v-model="majsoulCustomSizeH">
<span class="btn btn-submit" @click="saveMajsoulCustomSize">保存</span>
</div>
<!-- 单击"雀"按钮是否重置窗口大小和位置 -->
<p class="list-title">单击"雀"按钮是否重置窗口大小和位置</p>
<div class="item">
<input type="radio" id="option-y" value="1" class="input w10px" v-model="isResetBoundForMajsoul">
<label for="option-y">是</label>
<label> </label>
<input type="radio" id="option-n" value="2" class="input w10px" v-model="isResetBoundForMajsoul">
<label for="option-n">否</label>
<span class="btn btn-submit" @click="saveIsResetBoundForMajsoul">保存</span>
</div>
<!-- 代理 -->
<p class="list-title">代理设置</p>
<div class="item">
<input type="text" class="input" v-model="proxy" placeholder="scheme://host:port">
<span class="btn btn-submit" @click="saveProxy">确定</span>
</div>
</div>
</div>
<script src="js/vue.min.js"></script>
<script>
const ipc = require('electron').ipcRenderer;
const remote = require('electron').remote;
const isAccelerator = require('electron-is-accelerator');
const utils = require('./js/utils.js');
const config = utils.config;
var lastOpacity = 1;
const v = new Vue({
el: '#wrapper',
data: {
opacity: 1,
hideShortcut: '',
proxy: '',
majsoulCustomPositionX: '',
majsoulCustomPositionY: '',
majsoulCustomSizeW: '',
majsoulCustomSizeH: '',
isResetBoundForMajsoul: 2,
isUsePcVersion: 2
},
watch: {
opacity(val) {
// 在不透明和透明间切换的瞬间,需要重新创建主窗口并切换模式
if( lastOpacity == 1 && val < 1 || lastOpacity < 1 && val == 1 ) {
ipc.send('recreate-main-window');
} else {
ipc.send('set-opacity');
}
lastOpacity = val;
config.set('opacity', val);
}
},
methods: {
closeWindow() {
remote.getCurrentWindow().hide();
},
saveHideShortcut() {
var lastShortcut = config.get('hideShortcut'),
curShortcut = this.hideShortcut.split('+').map((c) => {
let _c = c.trim().toLowerCase().split('');
_c[0] = _c[0].toUpperCase();
return _c.join('');
}).join('+');
// 手动检查快捷键格式:
// 似乎随便瞎写一个字符串丢进globalShortcut.register会报错,而且这个错误还catch不到,必定会中断程序执行
// 所以只能在这里人工检查了
if( isAccelerator(curShortcut) ) {
this.hideShortcut = curShortcut.replace(/\+/g, ' + ');
config.set('hideShortcut', curShortcut);
ipc.send('update-hide-shortcut', lastShortcut);
} else {
this.hideShortcut = lastShortcut.replace(/\+/g, ' + ');
utils.error(`快捷键被检测为不合法 ${curShortcut}`);
alert('你输入的快捷键不合法!\n合法的快捷键组合应当类似于「ctrl+shift+e」。\n合法的修饰键包括Ctrl、Alt、Shift、Cmd(仅Mac)、Option(仅Mac,等同于Alt)。')
}
},
saveProxy() {
config.set('proxy', this.proxy);
ipc.send('set-proxy');
},
saveMajsoulCustomSize() {
let customSize = [], customPosition = [];
if (this.majsoulCustomPositionX == null || this.majsoulCustomPositionX === "") {
alert("请输入X!!");
return false;
}
if (this.majsoulCustomPositionY == null || this.majsoulCustomPositionY === "") {
alert("请输入Y!!");
return false;
}
if (this.majsoulCustomSizeW == null || this.majsoulCustomSizeW === "") {
alert("请输入宽!!");
return false;
}
if (this.majsoulCustomSizeH == null || this.majsoulCustomSizeH === "") {
alert("请输入高!!");
return false;
}
if (
!(/(^[1-9]\d*$)/.test(this.majsoulCustomSizeW)) ||
!(/(^[1-9]\d*$)/.test(this.majsoulCustomSizeH)) ||
!(/(^[0-9]\d*$)/.test(this.majsoulCustomPositionX)) ||
!(/(^[0-9]\d*$)/.test(this.majsoulCustomPositionY))
) {
alert("XY宽高数值非法,请重试!!!");
return false;
}
customSize[0] = Number(this.majsoulCustomSizeW);
customSize[1] = Number(this.majsoulCustomSizeH);
customPosition[0] = Number(this.majsoulCustomPositionX);
customPosition[1] = Number(this.majsoulCustomPositionY);
config.set("majsoulWindowCustomSize", customSize);
config.set("majsoulWindowCustomPosition", customPosition);
},
saveIsResetBoundForMajsoul() {
config.set('isResetBoundForMajsoul', Number(this.isResetBoundForMajsoul));
},
saveIsUsePcVersion() {
if (Number(this.isUsePcVersion) === 1) {
config.set('homeUrl', 'http://bilibili.com');
config.delete('userAgent');
} else {
config.set('homeUrl', 'http://m.bilibili.com/index.html');
config.set('userAgent', 'bilimini Mobile like (iPhone or Android) whatever AppleWebKit/124.50 Mobile/BI233');
}
config.set('isUsePcVersion', Number(this.isUsePcVersion));
}
},
mounted() {
this.opacity = lastOpacity = config.get('opacity');
this.hideShortcut = config.get('hideShortcut');
this.proxy = config.get('proxy');
this.majsoulCustomSizeW = config.get('majsoulWindowCustomSize')[0];
this.majsoulCustomSizeH = config.get('majsoulWindowCustomSize')[1];
this.majsoulCustomPositionX = config.get('majsoulWindowCustomPosition')[0];
this.majsoulCustomPositionY = config.get('majsoulWindowCustomPosition')[1];
this.isResetBoundForMajsoul = config.get('isResetBoundForMajsoul');
this.isUsePcVersion = config.get('isUsePcVersion');
}
});
window.onerror = function(err, f, line) {
var id = f.split('/');
utils.error(`${id[id.length-1]} : Line ${line}\n> ${err}`);
}
if( !process.platform.indexOf('win') ) {
document.querySelectorAll('input[type=text]').forEach((input) => {
input.style.width = '70%';
});
}
</script>
</body>
</html>