Skip to content

Commit

Permalink
新增白名单功能
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Dec 6, 2020
1 parent 8723bea commit 06b4685
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ <h1 class="display-4">字幕过滤设定</h1>
</div>
<div>
<h3>房间 ID 黑名单</h3>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="use-whitelist">
<label class="custom-control-label" for="use-whitelist">使用为白名单</label>
</div>
<ul id="blacklist" class="list-group list-group-flush" style="overflow-y: auto; height: 200px; border: black solid">
</ul>
<label for="add-blacklist">添加房间 ID</label>
Expand Down
3 changes: 3 additions & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getCurrentInput(){
danmakuPosition: $('#danmaku-position')[0].value
}
setting.useStreamingTime = $('#use-streaming-time').prop('checked')
setting.useAsWhitelist = $('#use-whitelist').prop('checked')
return setting
}

Expand Down Expand Up @@ -84,6 +85,8 @@ function saveCurrentInput(setting){
$('#danmaku-position').attr('disabled', !setting.useWebSocket)
$('#use-streaming-time').prop('checked', setting.useStreamingTime)
$('label[for=use-streaming-time]')[0].innerText = setting.useStreamingTime ? '使用串流时间戳记' : '使用真实时间戳记'

$('#use-whitelist').prop('checked', setting.useAsWhitelist)
}


Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const roomId = parseInt(roomReg.exec(location.pathname)?.groups?.id)
const colorReg = /^#[0-9A-F]{6}$/ig

if (isNaN(roomId)){
console.warn('未知直播房間。')
throw new Error('未知直播房間。')
}

Expand Down Expand Up @@ -116,7 +117,7 @@ async function process() {
return
}
const settings = await getSettings()
if (settings.blacklistRooms.includes(`${roomId}`)){
if (settings.blacklistRooms.includes(`${roomId}`) === !settings.useAsWhitelist){
console.log('房間ID在黑名單上,已略過。')
return
}
Expand Down
1 change: 1 addition & 0 deletions src/options/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const defaultSettings = {
backgroundColor: '#808080',
subtitleColor: '#FFFFFF',
blacklistRooms: [],
useAsWhitelist: false,
subtitleSize: 16,
lineGap: 0,
useWebSocket: false,
Expand Down

0 comments on commit 06b4685

Please sign in to comment.