mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
add ts config: noImplicitThis
This commit is contained in:
parent
1c9e0d0aac
commit
fadc39fc5c
@ -23,12 +23,12 @@ export const nextPageMixin = <MappedItem extends { id: string }, RawItem>(
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: true,
|
loading: true,
|
||||||
cards: [],
|
cards: [] as MappedItem[],
|
||||||
hasMorePage: true,
|
hasMorePage: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
sortedCards() {
|
sortedCards(): MappedItem[] {
|
||||||
return ([...this.cards] as MappedItem[]).sort(descendingStringSort(it => it.id))
|
return ([...this.cards] as MappedItem[]).sort(descendingStringSort(it => it.id))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -42,6 +42,9 @@ export const nextPageMixin = <MappedItem extends { id: string }, RawItem>(
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async nextPage() {
|
async nextPage() {
|
||||||
|
const this0 = this as typeof this & {
|
||||||
|
onCardsUpdate?: (cards: MappedItem[]) => MappedItem[]
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const cards: MappedItem[] = this.sortedCards
|
const cards: MappedItem[] = this.sortedCards
|
||||||
const lastCardID = cards[cards.length - 1]?.id ?? 0
|
const lastCardID = cards[cards.length - 1]?.id ?? 0
|
||||||
@ -61,8 +64,8 @@ export const nextPageMixin = <MappedItem extends { id: string }, RawItem>(
|
|||||||
.filter(card => !isPreOrderedVideo(card)),
|
.filter(card => !isPreOrderedVideo(card)),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (concatCards.length > 0 && this.onCardsUpdate) {
|
if (concatCards.length > 0 && this0.onCardsUpdate) {
|
||||||
concatCards = this.onCardsUpdate(concatCards)
|
concatCards = this0.onCardsUpdate(concatCards)
|
||||||
}
|
}
|
||||||
console.log('nextPage get', concatCards)
|
console.log('nextPage get', concatCards)
|
||||||
this.cards = concatCards
|
this.cards = concatCards
|
||||||
|
|||||||
@ -3,9 +3,9 @@ import { getJson } from '@/core/ajax'
|
|||||||
/**
|
/**
|
||||||
* 封装一些 API 请求的通用行为, 使用者要定义 parseJson 方法将返回的 JSON 转换为数据数组, 会自动存到 this.items 里
|
* 封装一些 API 请求的通用行为, 使用者要定义 parseJson 方法将返回的 JSON 转换为数据数组, 会自动存到 this.items 里
|
||||||
*/
|
*/
|
||||||
export const requestMixin = (
|
export const requestMixin = <D, I>(
|
||||||
config: {
|
config: {
|
||||||
requestMethod?: (url: string) => Promise<any>
|
requestMethod?: (url: string) => Promise<D>
|
||||||
} = {},
|
} = {},
|
||||||
) => {
|
) => {
|
||||||
const { requestMethod = getJson } = config
|
const { requestMethod = getJson } = config
|
||||||
@ -18,28 +18,28 @@ export const requestMixin = (
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [] as I[],
|
||||||
loading: true,
|
loading: true,
|
||||||
error: false,
|
error: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
loaded() {
|
loaded(): boolean {
|
||||||
return !this.loading && !this.error
|
return !this.loading && !this.error
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.reload()
|
this.reload().then()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async reload() {
|
async reload() {
|
||||||
|
const this0 = this as typeof this & { parseJson: (json: D) => I[]; itemLimit?: number }
|
||||||
try {
|
try {
|
||||||
this.error = false
|
this.error = false
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.items = this.parseJson(await requestMethod(this.api)).slice(
|
this.items = this0
|
||||||
0,
|
.parseJson(await requestMethod(this.api))
|
||||||
this.itemLimit ?? Infinity,
|
.slice(0, this0.itemLimit ?? Infinity)
|
||||||
)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
this.error = true
|
this.error = true
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export const createEpisodesPicker = (
|
|||||||
Vue.extend({
|
Vue.extend({
|
||||||
computed: {
|
computed: {
|
||||||
checkedInputItems() {
|
checkedInputItems() {
|
||||||
return this.$refs.picker.checkedInputItems
|
return (this.$refs.picker as any).checkedInputItems
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render(createElement) {
|
render(createElement) {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import type { VueModule } from '../common-types'
|
|||||||
* 当查询 video 元素且被灰度了 WasmPlayer 时, 更换为对 bwp-video 的查询, 否则会找不到 video 元素
|
* 当查询 video 元素且被灰度了 WasmPlayer 时, 更换为对 bwp-video 的查询, 否则会找不到 video 元素
|
||||||
* @param selector 选择器
|
* @param selector 选择器
|
||||||
*/
|
*/
|
||||||
export const bwpVideoFilter = (selector: string) => {
|
export const bwpVideoFilter = (selector: string): string => {
|
||||||
// if (!unsafeWindow.__ENABLE_WASM_PLAYER__) {
|
// if (!unsafeWindow.__ENABLE_WASM_PLAYER__) {
|
||||||
// return selector
|
// return selector
|
||||||
// }
|
// }
|
||||||
@ -24,44 +24,46 @@ interface DocumentQuerySelector {
|
|||||||
* 同 `document.querySelector`, 对 `<bwp-video>` 有额外处理
|
* 同 `document.querySelector`, 对 `<bwp-video>` 有额外处理
|
||||||
* @param selector 选择器
|
* @param selector 选择器
|
||||||
*/
|
*/
|
||||||
(selector: string): Element | null
|
<E extends Element>(selector: string): E | null
|
||||||
/**
|
/**
|
||||||
* 在指定元素上进行 `querySelector`, 对 `<bwp-video>` 有额外处理
|
* 在指定元素上进行 `querySelector`, 对 `<bwp-video>` 有额外处理
|
||||||
* @param selector 元素
|
* @param element 元素
|
||||||
* @param scopedSelector 选择器
|
* @param scopedSelector 选择器
|
||||||
*/
|
*/
|
||||||
(element: Element, scopedSelector: string): Element | null
|
<E extends Element>(element: Element, scopedSelector: string): E | null
|
||||||
}
|
}
|
||||||
export const dq: DocumentQuerySelector = (
|
export const dq: DocumentQuerySelector = <E extends Element>(
|
||||||
selectorOrElement: string | Element,
|
selectorOrElement: string | Element,
|
||||||
scopedSelector?: string,
|
scopedSelector?: string,
|
||||||
) => {
|
): E => {
|
||||||
if (!scopedSelector) {
|
if (!scopedSelector) {
|
||||||
return document.querySelector(bwpVideoFilter(selectorOrElement as string))
|
return document.querySelector<E>(bwpVideoFilter(selectorOrElement as string))
|
||||||
}
|
}
|
||||||
return (selectorOrElement as Element).querySelector(bwpVideoFilter(scopedSelector))
|
return (selectorOrElement as Element).querySelector<E>(bwpVideoFilter(scopedSelector))
|
||||||
}
|
}
|
||||||
interface DocumentQuerySelectorAll {
|
interface DocumentQuerySelectorAll {
|
||||||
/**
|
/**
|
||||||
* 同 `document.querySelectorAll` (返回转换过的真数组), 对 `<bwp-video>` 有额外处理
|
* 同 `document.querySelectorAll` (返回转换过的真数组), 对 `<bwp-video>` 有额外处理
|
||||||
* @param selector 选择器
|
* @param selector 选择器
|
||||||
*/
|
*/
|
||||||
(selector: string): Element[]
|
<E extends Element>(selector: string): E[]
|
||||||
/**
|
/**
|
||||||
* 在指定元素上进行`querySelectorAll` (返回转换过的真数组), 对 `<bwp-video>` 有额外处理
|
* 在指定元素上进行`querySelectorAll` (返回转换过的真数组), 对 `<bwp-video>` 有额外处理
|
||||||
* @param selector 元素
|
* @param selector 元素
|
||||||
* @param scopedSelector 选择器
|
* @param scopedSelector 选择器
|
||||||
*/
|
*/
|
||||||
(element: Element, scopedSelector: string): Element[]
|
<E extends Element>(element: Element, scopedSelector: string): E[]
|
||||||
}
|
}
|
||||||
export const dqa: DocumentQuerySelectorAll = (
|
export const dqa: DocumentQuerySelectorAll = <E extends Element>(
|
||||||
selectorOrElement: Element | string,
|
selectorOrElement: Element | string,
|
||||||
scopedSelector?: string,
|
scopedSelector?: string,
|
||||||
) => {
|
): E[] => {
|
||||||
if (!scopedSelector) {
|
if (!scopedSelector) {
|
||||||
return Array.from(document.querySelectorAll(bwpVideoFilter(selectorOrElement as string)))
|
return Array.from(document.querySelectorAll<E>(bwpVideoFilter(selectorOrElement as string)))
|
||||||
}
|
}
|
||||||
return Array.from((selectorOrElement as Element).querySelectorAll(bwpVideoFilter(scopedSelector)))
|
return Array.from(
|
||||||
|
(selectorOrElement as Element).querySelectorAll<E>(bwpVideoFilter(scopedSelector)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
interface DocumentEvaluate {
|
interface DocumentEvaluate {
|
||||||
(xpathExpression: string): XPathResult
|
(xpathExpression: string): XPathResult
|
||||||
@ -74,8 +76,8 @@ export const de: DocumentEvaluate = (
|
|||||||
contextNode?: Node,
|
contextNode?: Node,
|
||||||
type?: number,
|
type?: number,
|
||||||
result?: XPathResult,
|
result?: XPathResult,
|
||||||
) => document.evaluate(xpathExpression, contextNode, null, type, result)
|
): XPathResult => document.evaluate(xpathExpression, contextNode, null, type, result)
|
||||||
interface DocumentEvaluateAll {
|
type DocumentEvaluateAll = {
|
||||||
(xpathExpression: string): Node[]
|
(xpathExpression: string): Node[]
|
||||||
(xpathExpression: string, contextNode: Node): Node[]
|
(xpathExpression: string, contextNode: Node): Node[]
|
||||||
(xpathExpression: string, contextNode: Node, order: boolean): Node[]
|
(xpathExpression: string, contextNode: Node, order: boolean): Node[]
|
||||||
@ -86,7 +88,7 @@ export const dea: DocumentEvaluateAll = (
|
|||||||
contextNode?: Node,
|
contextNode?: Node,
|
||||||
order?: boolean,
|
order?: boolean,
|
||||||
result?: XPathResult,
|
result?: XPathResult,
|
||||||
) => {
|
): Node[] => {
|
||||||
const xpathResult = de(
|
const xpathResult = de(
|
||||||
xpathExpression,
|
xpathExpression,
|
||||||
contextNode,
|
contextNode,
|
||||||
@ -96,18 +98,12 @@ export const dea: DocumentEvaluateAll = (
|
|||||||
|
|
||||||
return Array.from({ length: xpathResult.snapshotLength }, (_, i) => xpathResult.snapshotItem(i))
|
return Array.from({ length: xpathResult.snapshotLength }, (_, i) => xpathResult.snapshotItem(i))
|
||||||
}
|
}
|
||||||
interface DocumentEvaluateAllIterable {
|
function* deaiRaw(
|
||||||
(xpathExpression: string): Iterable<Node>
|
|
||||||
(xpathExpression: string, contextNode: Node): Iterable<Node>
|
|
||||||
(xpathExpression: string, contextNode: Node, order: boolean): Iterable<Node>
|
|
||||||
(xpathExpression: string, contextNode: Node, order: boolean, result: XPathResult): Iterable<Node>
|
|
||||||
}
|
|
||||||
export const deai: DocumentEvaluateAllIterable = (
|
|
||||||
xpathExpression: string,
|
xpathExpression: string,
|
||||||
contextNode?: Node,
|
contextNode?: Node,
|
||||||
order?: boolean,
|
order?: boolean,
|
||||||
result?: XPathResult,
|
result?: XPathResult,
|
||||||
) => {
|
): Generator<Node, void, void> {
|
||||||
const xpathResult = de(
|
const xpathResult = de(
|
||||||
xpathExpression,
|
xpathExpression,
|
||||||
contextNode,
|
contextNode,
|
||||||
@ -115,20 +111,28 @@ export const deai: DocumentEvaluateAllIterable = (
|
|||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
let node = null
|
||||||
[Symbol.iterator]: () => ({
|
for (;;) {
|
||||||
next: () => {
|
node = xpathResult.iterateNext()
|
||||||
let node = null
|
if (node) {
|
||||||
do {
|
yield node
|
||||||
node = xpathResult.iterateNext()
|
} else {
|
||||||
return node
|
break
|
||||||
? ({ done: false, value: node } as { done: false; value: Node })
|
}
|
||||||
: ({ done: true } as { done: true; value: any })
|
|
||||||
} while (node)
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
interface DocumentEvaluateAllIterable {
|
||||||
|
(xpathExpression: string): IterableIterator<Node>
|
||||||
|
(xpathExpression: string, contextNode: Node): IterableIterator<Node>
|
||||||
|
(xpathExpression: string, contextNode: Node, order: boolean): IterableIterator<Node>
|
||||||
|
(
|
||||||
|
xpathExpression: string,
|
||||||
|
contextNode: Node,
|
||||||
|
order: boolean,
|
||||||
|
result: XPathResult,
|
||||||
|
): IterableIterator<Node>
|
||||||
|
}
|
||||||
|
export const deai: DocumentEvaluateAllIterable = deaiRaw
|
||||||
interface DocumentEvaluateSingle {
|
interface DocumentEvaluateSingle {
|
||||||
<T extends Node>(xpathExpression: string): T | null
|
<T extends Node>(xpathExpression: string): T | null
|
||||||
<T extends Node>(xpathExpression: string, contextNode: Node): T | null
|
<T extends Node>(xpathExpression: string, contextNode: Node): T | null
|
||||||
@ -138,7 +142,7 @@ export const des: DocumentEvaluateSingle = <T extends Node>(
|
|||||||
xpathExpression: string,
|
xpathExpression: string,
|
||||||
contextNode?: Node,
|
contextNode?: Node,
|
||||||
result?: XPathResult,
|
result?: XPathResult,
|
||||||
) =>
|
): T | null =>
|
||||||
de(xpathExpression, contextNode, XPathResult.FIRST_ORDERED_NODE_TYPE, result)
|
de(xpathExpression, contextNode, XPathResult.FIRST_ORDERED_NODE_TYPE, result)
|
||||||
.singleNodeValue as T | null
|
.singleNodeValue as T | null
|
||||||
/** 空函数 */
|
/** 空函数 */
|
||||||
@ -300,7 +304,7 @@ export const createHook = <ParentType, HookParameters extends any[], ReturnType
|
|||||||
hookFunc: (...args: HookParameters) => boolean,
|
hookFunc: (...args: HookParameters) => boolean,
|
||||||
) => {
|
) => {
|
||||||
const original: (...args: HookParameters) => ReturnType = type[target] as any
|
const original: (...args: HookParameters) => ReturnType = type[target] as any
|
||||||
type[target] = function hook(...args: HookParameters) {
|
type[target] = function hook(this: any, ...args: HookParameters) {
|
||||||
const shouldCallOriginal = hookFunc(...args)
|
const shouldCallOriginal = hookFunc(...args)
|
||||||
if (!shouldCallOriginal) {
|
if (!shouldCallOriginal) {
|
||||||
return undefined
|
return undefined
|
||||||
@ -321,7 +325,7 @@ export const createPostHook = <ParentType, HookParameters extends any[], ReturnT
|
|||||||
hookFunc: (...args: HookParameters) => unknown,
|
hookFunc: (...args: HookParameters) => unknown,
|
||||||
) => {
|
) => {
|
||||||
const original: (...args: HookParameters) => ReturnType = type[target] as any
|
const original: (...args: HookParameters) => ReturnType = type[target] as any
|
||||||
type[target] = function hook(...args: HookParameters) {
|
type[target] = function hook(this: any, ...args: HookParameters) {
|
||||||
const result = original?.call(this, ...args)
|
const result = original?.call(this, ...args)
|
||||||
hookFunc(...args)
|
hookFunc(...args)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export const ScopedConsoleCallHook = 'scopedConsole.call'
|
|||||||
* 创建一个 ScopedConsole, 为输出的日志添加固定的前缀
|
* 创建一个 ScopedConsole, 为输出的日志添加固定的前缀
|
||||||
* @param config 配置对象或者 scope 名称
|
* @param config 配置对象或者 scope 名称
|
||||||
*/
|
*/
|
||||||
export const useScopedConsole = (config: ScopedConsoleConfig | string) => {
|
export const useScopedConsole = (config: ScopedConsoleConfig | string): Console => {
|
||||||
const { before: beforeCreate, after: afterCreate } = getHook(ScopedConsoleCreateHook)
|
const { before: beforeCreate, after: afterCreate } = getHook(ScopedConsoleCreateHook)
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
@ -78,7 +78,7 @@ export const useScopedConsole = (config: ScopedConsoleConfig | string) => {
|
|||||||
target: (...args: any[]) => void,
|
target: (...args: any[]) => void,
|
||||||
prependConfig: ScopedConsoleConfig,
|
prependConfig: ScopedConsoleConfig,
|
||||||
firstColor = prependConfig.color,
|
firstColor = prependConfig.color,
|
||||||
) => {
|
): ((this: Console, ...args: unknown[]) => unknown) => {
|
||||||
const lastScopedData: ScopedData = target[ScopedConsoleSymbol]
|
const lastScopedData: ScopedData = target[ScopedConsoleSymbol]
|
||||||
const backgroundColor =
|
const backgroundColor =
|
||||||
(lastScopedData ? prependConfig.color : firstColor) ?? specialPalette.default
|
(lastScopedData ? prependConfig.color : firstColor) ?? specialPalette.default
|
||||||
@ -98,7 +98,7 @@ export const useScopedConsole = (config: ScopedConsoleConfig | string) => {
|
|||||||
original: lastScopedData?.original ?? target,
|
original: lastScopedData?.original ?? target,
|
||||||
}
|
}
|
||||||
const rootTarget = currentScopedData.original
|
const rootTarget = currentScopedData.original
|
||||||
const patchedLog = function patchedLog(...args: any[]) {
|
const patchedLog = function patchedLog(this: Console, ...args: unknown[]): unknown {
|
||||||
const hookPayload = {
|
const hookPayload = {
|
||||||
type: rootTarget[NamePatchSymbol],
|
type: rootTarget[NamePatchSymbol],
|
||||||
args,
|
args,
|
||||||
@ -126,9 +126,9 @@ export const useScopedConsole = (config: ScopedConsoleConfig | string) => {
|
|||||||
groupConfig: ScopedConsoleConfig,
|
groupConfig: ScopedConsoleConfig,
|
||||||
firstColor = groupConfig.color,
|
firstColor = groupConfig.color,
|
||||||
counter: (num: number) => number = n => n,
|
counter: (num: number) => number = n => n,
|
||||||
) => {
|
): ((this: Console, ...args: unknown[]) => unknown) => {
|
||||||
const patch = prependBadge(target, groupConfig, firstColor)
|
const patch = prependBadge(target, groupConfig, firstColor)
|
||||||
const patchedGroup = function patchedGroup(...args: any[]) {
|
const patchedGroup = function patchedGroup(this: Console, ...args: unknown[]): unknown {
|
||||||
const returnValue = patch.apply(this, args)
|
const returnValue = patch.apply(this, args)
|
||||||
groupCounter = counter(groupCounter)
|
groupCounter = counter(groupCounter)
|
||||||
return returnValue
|
return returnValue
|
||||||
@ -179,7 +179,7 @@ export const useScopedConsole = (config: ScopedConsoleConfig | string) => {
|
|||||||
)
|
)
|
||||||
scopedConsole.debug = (() => {
|
scopedConsole.debug = (() => {
|
||||||
const patch = prependBadge(console.debug, actualConfig)
|
const patch = prependBadge(console.debug, actualConfig)
|
||||||
return function patchedDebug(...args: any[]) {
|
return function patchedDebug(this: Console, ...args: unknown[]): unknown {
|
||||||
if (!getGeneralSettings().devMode) {
|
if (!getGeneralSettings().devMode) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"strict": false,
|
"strict": false,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
|
"noImplicitThis": true,
|
||||||
"importsNotUsedAsValues": "error",
|
"importsNotUsedAsValues": "error",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user