Migrate to checkInCenter (#1517)

This commit is contained in:
the1812 2021-03-18 16:39:45 +08:00
parent 15cad80e8a
commit ce19657fbe
12 changed files with 97 additions and 59 deletions

View File

@ -1 +1 @@
(()=>(e,o)=>{console.log("not implemented")})();
(()=>(e,n)=>{const i=[{id:"seeds-to-coins",icon:"mdi-seed-outline",name:"瓜子换硬币",action:async()=>{const e="https://api.live.bilibili.com/pay/v1/Exchange/silver2coin";const n=await Ajax.getJsonWithCredentials(e);if(n.code!==0){Toast.info(n.message,"瓜子换硬币",3e3)}else{Toast.success(`${n.message}\n剩余银瓜子:${n.data.silver}`,"瓜子换硬币",3e3)}}},{id:"live-check-in",icon:"mdi-calendar-check",name:"直播间签到",action:async()=>{const e="https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign";const n=await Ajax.getJsonWithCredentials(e);if(n.code!==0){Toast.info(n.message,"直播间签到",3e3)}else{const{text:e,specialText:i,allDays:s,hadSignDays:t}=n.data;const a=`签到成功, 获得了${e} ${i}\n本月进度: ${t} / ${s}`;Toast.success(a,"直播间签到",3e3)}}}];return{widget:{content:i.map((e=>`\n<button\n class="gui-settings-flat-button"\n id="${e.id}">\n<i class="mdi mdi-24px ${e.icon}"></i>\n<span>${e.name}</span>\n</button>\n`)).join("\n"),condition:()=>Boolean(getUID()),success:()=>{i.forEach((e=>{const n=document.getElementById(e.id);if(!n){return}n.addEventListener("click",(i=>{try{n.disabled=true;e.action(n,i)}finally{n.disabled=false}}))}))}}}})();

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
(()=>(s,e)=>{const n=`https://api.live.bilibili.com/pay/v1/Exchange/silver2coin`;return{widget:{content:`\n<button\n class="gui-settings-flat-button"\n id="seeds-to-coins">\n<i class="mdi mdi-24px mdi-seed-outline"></i>\n<span>瓜子换硬币</span>\n</button>\n`,condition:()=>Boolean(getUID()),success:()=>{const s=async()=>{const s=await Ajax.getJsonWithCredentials(n);if(s.code!==0){Toast.info(s.message,"瓜子换硬币",3e3)}else{Toast.success(`${s.message}\n剩余银瓜子:${s.data.silver}`,"瓜子换硬币",3e3)}};const e=dq("#seeds-to-coins");e.addEventListener("click",(async()=>{try{e.disabled=true;await s()}finally{e.disabled=false}}))}}}})();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -518,12 +518,6 @@ Resource.manifest = {
useDefaultVideoSpeed: '记忆上次播放速度',
},
},
seedsToCoins: {
displayNames: {
seedsToCoins: '瓜子换硬币',
autoSeedsToCoins: '自动运行',
},
},
autoDraw: {
displayNames: {
autoDraw: '直播间自动领奖',

View File

@ -158,9 +158,6 @@ export const settings = {
aria2RpcOptionSelectedProfile: '',
aria2RpcOptionProfiles: [],
searchHistory: [],
seedsToCoins: true,
autoSeedsToCoins: true,
lastSeedsToCoinsDate: 0,
autoDraw: false,
keymap: false,
keymapPreset: 'Default',
@ -260,6 +257,9 @@ export const settings = {
cache: {},
}
const fixedSettings = {
seedsToCoins: false,
autoSeedsToCoins: false,
lastSeedsToCoinsDate: 0,
useDefaultLiveQuality: false,
recordLiveDanmaku: false,
autoContinue: false,

View File

@ -1 +1,87 @@
console.log('not implemented')
interface CheckInItem {
id: string
icon: string
name: string
action: (button: HTMLButtonElement, event: MouseEvent) => Promise<void>
}
const checkInItems: CheckInItem[] = [
{
id: 'seeds-to-coins',
icon: 'mdi-seed-outline',
name: '瓜子换硬币',
action: async () => {
const seedsToCoinsApi = 'https://api.live.bilibili.com/pay/v1/Exchange/silver2coin'
const json = await Ajax.getJsonWithCredentials(seedsToCoinsApi) as {
code: number
message: string
data: {
gold: string
silver: string
coin: number
}
}
if (json.code !== 0) {
Toast.info(json.message, '瓜子换硬币', 3000)
} else {
Toast.success(`${json.message}\n剩余银瓜子:${json.data.silver}`, '瓜子换硬币', 3000)
}
}
},
{
id: 'live-check-in',
icon: 'mdi-calendar-check',
name: '直播间签到',
action: async () => {
const liveCheckInApi = 'https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign'
const json = await Ajax.getJsonWithCredentials(liveCheckInApi) as {
code: number
message: string
data: {
text: string
specialText: string
allDays: number
hadSignDays: number
isBonusDay: number
}
}
if (json.code !== 0) {
Toast.info(json.message, '直播间签到', 3000)
} else {
const { text, specialText, allDays, hadSignDays } = json.data
const message = `签到成功, 获得了${text} ${specialText}\n本月进度: ${hadSignDays} / ${allDays}`
Toast.success(message, '直播间签到', 3000)
}
}
},
]
export default {
widget: {
content: checkInItems.map(item => {
return /*html*/`
<button
class="gui-settings-flat-button"
id="${item.id}">
<i class="mdi mdi-24px ${item.icon}"></i>
<span>${item.name}</span>
</button>
`
}).join('\n'),
condition: () => Boolean(getUID()),
success: () => {
checkInItems.forEach(item => {
const button = document.getElementById(item.id) as HTMLButtonElement
if (!button) {
return
}
button.addEventListener('click', e => {
try {
button.disabled = true
item.action(button, e)
} finally {
button.disabled = false
}
})
})
},
},
}

View File

@ -157,7 +157,7 @@
<checkbox indent="0" key="imageResolution" dependencies=""></checkbox>
<checkbox indent="0" key="i18n" dependencies=""></checkbox>
<dropdown indent="1" key="i18nLanguage" dependencies="i18n"></dropdown>
<checkbox indent="0" key="seedsToCoins" dependencies=""></checkbox>
<checkbox indent="0" key="checkInCenter" dependencies=""></checkbox>
<checkbox indent="0" key="selectableColumnText" dependencies=""></checkbox>
<checkbox indent="0" key="urlParamsClean" dependencies=""></checkbox>
<!-- <checkbox indent="0" key="preferAvUrl" dependencies=""></checkbox> -->

View File

@ -110,7 +110,7 @@ A more specific example: To use a "video title + AV ID + time" format, we can us
['deadVideoTitleProvider', `Select dead video info provider: Watchlater is stable but takes some time, BiliPlus runs fast but it's not implemented yet.`],
['useDefaultVideoSpeed', `Remember last video playback rate.`],
['defaultVideoSpeed', `Select the default playback rate.`],
['seedsToCoins', `Append a <span>Seeds to coins</span> button, click to convert 700 silver seeds to 1 coin, up to one time per day.`],
['checkInCenter', `Add daily actions to add-ons, like <span>Seeds to coins</span> and <span>Live check in</span>`],
['autoDraw', `Auto click draw button when there're drawing events in live room.`],
['keymap', `Enable more keyboard shortcuts for video player:
- <kbd>w</kbd> Web fullscreen

View File

@ -149,7 +149,7 @@ export const toolTips = new Map<keyof BilibiliEvolvedSettings, string>([
['foldComment', /*html*/`动态里查看评论区时, 在底部添加一个<span>收起评论</span>按钮, 这样就不用再回到上面收起了.`],
['useDefaultVideoSpeed', /*html*/`设置是否记忆上次选择的视频播放速度.`],
['extendVideoSpeed', /*html*/`设置是否扩展原生倍速菜单.`],
['seedsToCoins', /*html*/`在附加功能中添加<span>瓜子换硬币</span>的按钮, 点击可以将700银瓜子换成1个硬币, 每天限1次.`],
['checkInCenter', /*html*/`在附加功能中添加一些每日签到类的按钮, 例如银瓜子换硬币, 直播间签到.`],
['autoDraw', /*html*/`在当前直播间有抽奖活动时, 自动点击抽奖按钮. 注意只适用于少量抽奖, 那种99+限量抽奖可能跟不上其他人的手速(`],
['keymap', /*html*/`为视频播放器启用更多的快捷键:
- <kbd>w</kbd>

View File

@ -1,41 +0,0 @@
const seedsToCoinsApi = `https://api.live.bilibili.com/pay/v1/Exchange/silver2coin`
export default {
widget: {
content: /*html*/`
<button
class="gui-settings-flat-button"
id="seeds-to-coins">
<i class="mdi mdi-24px mdi-seed-outline"></i>
<span></span>
</button>
`,
condition: () => Boolean(getUID()),
success: () => {
const exchange = async () => {
const json = await Ajax.getJsonWithCredentials(seedsToCoinsApi) as {
code: number
message: string
data: {
gold: string
silver: string
coin: number
}
}
if (json.code !== 0) {
Toast.info(json.message, '瓜子换硬币', 3000)
} else {
Toast.success(`${json.message}\n剩余银瓜子:${json.data.silver}`, '瓜子换硬币', 3000)
}
}
const button = dq('#seeds-to-coins') as HTMLButtonElement
button.addEventListener('click', async () => {
try {
button.disabled = true
await exchange()
} finally {
button.disabled = false
}
})
},
},
}