diff --git a/registry/lib/components/utils/auto-like/blackList.vue b/registry/lib/components/utils/auto-like/blackList.vue new file mode 100644 index 000000000..9bb5968ea --- /dev/null +++ b/registry/lib/components/utils/auto-like/blackList.vue @@ -0,0 +1,207 @@ + + + + diff --git a/registry/lib/components/utils/auto-like/index.md b/registry/lib/components/utils/auto-like/index.md index ccf33057e..4b79333ce 100644 --- a/registry/lib/components/utils/auto-like/index.md +++ b/registry/lib/components/utils/auto-like/index.md @@ -1 +1,4 @@ -进入视频 / 查看动态时, 自动点赞. +进入视频 / 查看动态时, 自动点赞\ +无法触发未加载动态的点赞,当启用手动对动态点赞后可手动触发,启用后不会触发动态自动点赞\ +安装快捷键扩展后可以点击【l】键或【L】键触发\ +还可以添加动态点赞的黑名单\ diff --git a/registry/lib/components/utils/auto-like/index.ts b/registry/lib/components/utils/auto-like/index.ts index 8243811a2..7c4155e9f 100644 --- a/registry/lib/components/utils/auto-like/index.ts +++ b/registry/lib/components/utils/auto-like/index.ts @@ -1,8 +1,11 @@ import { defineComponentMetadata } from '@/components/define' -import { forEachFeedsCard } from '@/components/feeds/api' import { select } from '@/core/spin-query' import { matchUrlPattern, playerReady } from '@/core/utils' import { feedsUrls, videoAndBangumiUrls } from '@/core/utils/urls' +import { KeyBindingAction } from '../keymap/bindings' +import { forEachFeedsCard } from '@/components/feeds/api' +import { BlackListDataKey, loadlikeButton } from './vm' +import { getData, registerData } from '@/plugins/data' const feedsLikeQueue = [] as HTMLElement[] export const component = defineComponentMetadata({ @@ -10,6 +13,10 @@ export const component = defineComponentMetadata({ displayName: '自动点赞', tags: [componentsTags.utils, componentsTags.feeds, componentsTags.video], urlInclude: [...videoAndBangumiUrls, ...feedsUrls], + author: { + name: 'CrazyboyQCD', + link: 'https://github.com/CrazyboyQCD', + }, options: { video: { defaultValue: true, @@ -19,7 +26,17 @@ export const component = defineComponentMetadata({ defaultValue: true, displayName: '对动态点赞', }, + manualFeed: { + defaultValue: true, + displayName: '手动对动态点赞', + }, + users: { + displayName: '黑名单', + defaultValue: [] as string[], + hidden: true, + }, }, + extraOptions: () => import('./settings.vue').then(m => m.default), entry: async ({ settings: { options } }) => { if (options.video && videoAndBangumiUrls.some(url => matchUrlPattern(url))) { await playerReady() @@ -32,22 +49,51 @@ export const component = defineComponentMetadata({ likeButton.click() } if (options.feed && feedsUrls.some(url => matchUrlPattern(url))) { - window.setInterval(() => { - if (feedsLikeQueue.length === 0) { - return - } - const button = feedsLikeQueue.shift() - button?.click() - }, 1000) - forEachFeedsCard({ - added: card => { - const likeButton = dq(card.element, '.bili-dyn-action.like') as HTMLElement - if (!likeButton || likeButton.classList.contains('active')) { + const blackListData = { + users: options.users, + } + registerData(BlackListDataKey, blackListData) + if (options.manualFeed) { + loadlikeButton() + } else { + window.setInterval(() => { + if (feedsLikeQueue.length === 0) { return } - feedsLikeQueue.push(likeButton) - }, - }) + const button = feedsLikeQueue.shift() + button?.click() + }, 1000) + const blackList = getData(BlackListDataKey) + forEachFeedsCard({ + added: card => { + if (blackList.includes(card.username)) { + return + } + const likeButtons = dq(card.element, '.bili-dyn-action.like') as HTMLElement + if (!likeButtons || likeButtons.classList.contains('active')) { + return + } + feedsLikeQueue.push(likeButtons) + }, + }) + } } }, + plugin: { + displayName: '点赞 - 手动', + setup: ({ addData }) => { + addData('keymap.actions', (actions: Record) => { + actions.manuallike = { + displayName: '手动触发对动态点赞', + run: context => { + const { clickElement } = context + return clickElement('.manual-like', context) + }, + } + }) + addData('keymap.presets', (presetBase: Record) => { + presetBase.manuallike = 'l L' + }) + }, + }, }) diff --git a/registry/lib/components/utils/auto-like/like.vue b/registry/lib/components/utils/auto-like/like.vue new file mode 100644 index 000000000..d5139813c --- /dev/null +++ b/registry/lib/components/utils/auto-like/like.vue @@ -0,0 +1,84 @@ + + + + + diff --git a/registry/lib/components/utils/auto-like/settings.vue b/registry/lib/components/utils/auto-like/settings.vue new file mode 100644 index 000000000..fcd069f3e --- /dev/null +++ b/registry/lib/components/utils/auto-like/settings.vue @@ -0,0 +1,50 @@ + + + diff --git a/registry/lib/components/utils/auto-like/vm.ts b/registry/lib/components/utils/auto-like/vm.ts new file mode 100644 index 000000000..94e5714fe --- /dev/null +++ b/registry/lib/components/utils/auto-like/vm.ts @@ -0,0 +1,48 @@ +import { select } from '@/core/spin-query' +import { mountVueComponent } from '@/core/utils' +import { getData } from '@/plugins/data' + +export const BlackListDataKey = 'like-black-List.data' + +type SettingsVmType = Vue & { + toggle: () => void + triggerElement: HTMLElement + list: string[] + titleName: string +} +let blacklistVM: SettingsVmType = null + +export const setBlackListProps = (element: HTMLElement) => { + if (!blacklistVM) { + return + } + blacklistVM.triggerElement = element + const blackList = getData(BlackListDataKey) + blacklistVM.list = blackList[0].users + blacklistVM.titleName = '黑名单' +} +export const loadlikeButton = async () => { + const LikeButton = await import('./like.vue').then(m => m.default) + const blackList = getData(BlackListDataKey) + const likebuttonVM: Vue & { list: string[] } = mountVueComponent(LikeButton) + likebuttonVM.list = blackList[0].users + const bg = (await select('#app')) as HTMLElement + bg.insertAdjacentElement('afterbegin', likebuttonVM.$el) +} + +export const loadBlackList = async () => { + if (blacklistVM) { + return false + } + const blackList = await import('./blackList.vue').then(m => m.default) + blacklistVM = mountVueComponent(blackList) + document.body.insertAdjacentElement('beforeend', blacklistVM.$el) + return true +} + +export const toggleBlackList = async () => { + if (!blacklistVM) { + await loadBlackList() + } + blacklistVM?.toggle() +}