added a few types

This commit is contained in:
Lalle 2023-04-28 03:25:13 +02:00
parent cc4155500b
commit 329fc4dd14
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
15 changed files with 559 additions and 508 deletions

View File

@ -48,6 +48,7 @@
"never" "never"
], ],
"simple-import-sort/imports": "error", "simple-import-sort/imports": "error",
"simple-import-sort/exports": "error" "simple-import-sort/exports": "error",
"no-cond-assign": "off"
} }
} }

View File

@ -1,13 +1,17 @@
import BoardConfig from "../General/BoardConfig" import BoardConfig from "../General/BoardConfig"
import { d, g } from "../globals/globals" import { d, g } from "../globals/globals"
import Post from "./Post"
import SimpleDict from "./SimpleDict" import SimpleDict from "./SimpleDict"
import Thread from "./Thread"
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class Board { export default class Board {
ID: string
boardID: number | string
siteID: number
threads: SimpleDict<Thread>
posts: SimpleDict<Post>
config: any
toString() { return this.ID } toString() { return this.ID }
constructor(ID) { constructor(ID) {

View File

@ -1,12 +1,14 @@
import Main from "../main/Main" import Main from "../main/Main"
import Post from "./Post"
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS206: Consider reworking classes to avoid initClass
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class Callbacks { export default class Callbacks {
static Post: Callbacks
static Thread: Callbacks
static CatalogThread: Callbacks
static CatalogThreadNative: Callbacks
type: string
keys: string[]
static initClass() { static initClass() {
this.Post = new Callbacks('Post') this.Post = new Callbacks('Post')
this.Thread = new Callbacks('Thread') this.Thread = new Callbacks('Thread')

View File

@ -1,11 +1,18 @@
import $ from "../platform/$" import $ from "../platform/$"
import Board from "./Board"
import Post from "./Post"
import Thread from "./Thread"
export default class CatalogThread { export default class CatalogThread {
ID: any
thread: Thread
board: any
nodes: { root: Post; thumb: HTMLElement; icons: any; postCount: number; fileCount: number; pageCount: number; replies: any }
toString() { return this.ID } toString() { return this.ID }
constructor(root, thread) { constructor(root: Post, thread: Thread) {
this.thread = thread this.thread = thread
this.ID = this.thread.ID this.ID = this.thread.ID + ''
this.board = this.thread.board this.board = this.thread.board
const { post } = this.thread.OP.nodes const { post } = this.thread.OP.nodes
this.nodes = { this.nodes = {

View File

@ -4,6 +4,13 @@ import Board from "./Board"
import Thread from "./Thread" import Thread from "./Thread"
export default class CatalogThreadNative { export default class CatalogThreadNative {
ID: number | string
nodes: { root: Thread; thumb: HTMLElement }
siteID: string
boardID: string
board: Board | import("/home/victor/proj/4chan-XZ/src/globals/globals").Board
threadID: number
thread: Thread
toString() { return this.ID } toString() { return this.ID }
constructor(root) { constructor(root) {

View File

@ -1,13 +1,13 @@
import { g } from "../globals/globals" import { g } from "../globals/globals"
import $ from "../platform/$" import $ from "../platform/$"
import Callbacks from "./Callbacks"
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class Connection { export default class Connection {
constructor(target, origin, cb={}) { target: any
origin: any
cb: Callbacks
constructor(target: Window, origin: string, cb: Callbacks) {
this.send = this.send.bind(this) this.send = this.send.bind(this)
this.onMessage = this.onMessage.bind(this) this.onMessage = this.onMessage.bind(this)
this.target = target this.target = target
@ -28,7 +28,7 @@ export default class Connection {
return this.targetWindow().postMessage(`${g.NAMESPACE}${JSON.stringify(data)}`, this.origin) return this.targetWindow().postMessage(`${g.NAMESPACE}${JSON.stringify(data)}`, this.origin)
} }
onMessage(e) { onMessage(e: MessageEvent) {
if ((e.source !== this.targetWindow()) || if ((e.source !== this.targetWindow()) ||
(e.origin !== this.origin) || (e.origin !== this.origin) ||
(typeof e.data !== 'string') || (typeof e.data !== 'string') ||

View File

@ -11,6 +11,11 @@ import { dict, HOUR } from "../platform/helpers"
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
export default class DataBoard { export default class DataBoard {
static keys: string[]
static changes: string[]
key: string
sync: VoidFunction
data: any
static initClass() { static initClass() {
this.keys = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'watchedThreads', 'watcherLastModified', 'customTitles'] this.keys = ['hiddenThreads', 'hiddenPosts', 'lastReadPosts', 'yourPosts', 'watchedThreads', 'watcherLastModified', 'customTitles']

View File

@ -21,6 +21,13 @@ import Thread from "./Thread"
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
export default class Fetcher { export default class Fetcher {
archiveTags: { '\n': { innerHTML: string }; '[b]': { innerHTML: string }; '[/b]': { innerHTML: string }; '[spoiler]': { innerHTML: string }; '[/spoiler]': { innerHTML: string }; '[code]': { innerHTML: string }; '[/code]': { innerHTML: string }; '[moot]': { innerHTML: string }; '[/moot]': { innerHTML: string }; '[banned]': { innerHTML: string }; '[/banned]': { innerHTML: string }; '[fortune]'(text: string): { innerHTML: string }; '[/fortune]': { innerHTML: string }; '[i]': { innerHTML: string }; '[/i]': { innerHTML: string }; '[red]': { innerHTML: string }; '[/red]': { innerHTML: string }; '[green]': { innerHTML: string }; '[/green]': { innerHTML: string }; '[blue]': { innerHTML: string }; '[/blue]': { innerHTML: string } }
boardID: string
threadID: number
postID: number
root: HTMLElement
quoter: any
static flagCSS: any
static initClass() { static initClass() {
this.prototype.archiveTags = { this.prototype.archiveTags = {
@ -237,8 +244,7 @@ export default class Fetcher {
} else { } else {
const greentext = text[0] === '>' const greentext = text[0] === '>'
text = text.replace(/(\[\/?[a-z]+):lit(\])/g, '$1$2') text = text.replace(/(\[\/?[a-z]+):lit(\])/g, '$1$2')
text = text.split(/(>>(?:>\/[a-z\d]+\/)?\d+)/g).map((text2, j) => text = text.split(/(>>(?:>\/[a-z\d]+\/)?\d+)/g).map((text2, j) => { ((j % 2) ? "<span class=\"deadlink\">" + E(text2) + "</span>" : E(text2)) })
{((j % 2) ? "<span class=\"deadlink\">" + E(text2) + "</span>" : E(text2))})
text = { innerHTML: ((greentext) ? "<span class=\"quote\">" + E.cat(text) + "</span>" : E.cat(text)) } text = { innerHTML: ((greentext) ? "<span class=\"quote\">" + E.cat(text) + "</span>" : E.cat(text)) }
result.push(text) result.push(text)
} }
@ -259,7 +265,8 @@ export default class Fetcher {
email: data.email, email: data.email,
name: data.name || '', name: data.name || '',
tripcode: data.trip, tripcode: data.trip,
capcode: (() => { switch (data.capcode) { capcode: (() => {
switch (data.capcode) {
// https://github.com/pleebe/FoolFuuka/blob/bf4224eed04637a4d0bd4411c2bf5f9945dfec0b/assets/themes/foolz/foolfuuka-theme-fuuka/src/Partial/Board.php#L77 // https://github.com/pleebe/FoolFuuka/blob/bf4224eed04637a4d0bd4411c2bf5f9945dfec0b/assets/themes/foolz/foolfuuka-theme-fuuka/src/Partial/Board.php#L77
case 'M': return 'Mod' case 'M': return 'Mod'
case 'A': return 'Admin' case 'A': return 'Admin'
@ -267,7 +274,8 @@ export default class Fetcher {
case 'V': return 'Verified' case 'V': return 'Verified'
case 'F': return 'Founder' case 'F': return 'Founder'
case 'G': return 'Manager' case 'G': return 'Manager'
} })(), }
})(),
uniqueID: data.poster_hash, uniqueID: data.poster_hash,
flagCode: data.poster_country, flagCode: data.poster_country,
flagCodeTroll: data.troll_country_code, flagCodeTroll: data.troll_country_code,

View File

@ -4,6 +4,9 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
export default class RandomAccessList { export default class RandomAccessList {
length: number
last: any
first: any
constructor(items) { constructor(items) {
this.length = 0 this.length = 0
if (items) { for (const item of items) { this.push(item) } } if (items) { for (const item of items) { this.push(item) } }

View File

@ -4,6 +4,8 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
class ShimSet { class ShimSet {
elements: any
size: number
constructor() { constructor() {
this.elements = $.dict() this.elements = $.dict()
this.size = 0 this.size = 0

View File

@ -1,11 +1,5 @@
import $ from "../platform/$" import $ from "../platform/$"
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class SimpleDict<T> { export default class SimpleDict<T> {
keys: string[] keys: string[]
@ -13,14 +7,14 @@ export default class SimpleDict<T> {
this.keys = [] this.keys = []
} }
push(key, data: T) { push(key: string, data: T): T {
key = `${key}` key = `${key}`
if (!this[key]) { this.keys.push(key) } if (!this[key]) { this.keys.push(key) }
return this[key] = data return this[key] = data
} }
rm(key) { rm(key: string) {
let i let i: number
key = `${key}` key = `${key}`
if ((i = this.keys.indexOf(key)) !== -1) { if ((i = this.keys.indexOf(key)) !== -1) {
this.keys.splice(i, 1) this.keys.splice(i, 1)
@ -28,11 +22,11 @@ export default class SimpleDict<T> {
} }
} }
forEach(fn) { forEach(fn: (value: T) => void): void {
for (const key of [...Array.from(this.keys)]) { fn(this[key]) } for (const key of [...Array.from(this.keys)]) { fn(this[key]) }
} }
get(key): T { get(key: string): T {
if (key === 'keys') { if (key === 'keys') {
return undefined return undefined
} else { } else {

View File

@ -1,16 +1,34 @@
import { g } from "../globals/globals" import { g } from "../globals/globals"
import $ from "../platform/$" import $ from "../platform/$"
import Board from "./Board"
import Post from "./Post"
import SimpleDict from "./SimpleDict" import SimpleDict from "./SimpleDict"
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
export default class Thread { export default class Thread {
ID: number
OP: Post
isArchived: boolean
isClosed: boolean
lastPost: number
posts: SimpleDict<Post>
board: Board
threadID: number
boardID: number | string
siteID: number
fullID: string
isDead: boolean
isHidden: boolean
isSticky: boolean
postLimit: boolean
fileLimit: boolean
ipCount: number
json: JSON
catalogView: Node
nodes: { root: Post }
toString() { return this.ID } toString() { return this.ID }
constructor(ID, board) { constructor(ID: number | string, board: Board) {
this.board = board this.board = board
this.ID = +ID this.ID = +ID
this.threadID = this.ID this.threadID = this.ID
@ -39,8 +57,8 @@ export default class Thread {
g.threads.push(this.fullID, this) g.threads.push(this.fullID, this)
} }
setPage(pageNum) { setPage(pageNum: number) {
let icon let icon: HTMLElement
const { info, reply } = this.OP.nodes const { info, reply } = this.OP.nodes
if (!(icon = $('.page-num', info))) { if (!(icon = $('.page-num', info))) {
icon = $.el('span', { className: 'page-num' }) icon = $.el('span', { className: 'page-num' })
@ -51,14 +69,14 @@ export default class Thread {
if (this.catalogView) { return this.catalogView.nodes.pageCount.textContent = pageNum } if (this.catalogView) { return this.catalogView.nodes.pageCount.textContent = pageNum }
} }
setCount(type, count, reachedLimit) { setCount(type: string, count: number, reachedLimit: boolean) {
if (!this.catalogView) { return } if (!this.catalogView) { return }
const el = this.catalogView.nodes[`${type}Count`] const el = this.catalogView.nodes[`${type}Count`]
el.textContent = count el.textContent = count
return (reachedLimit ? $.addClass : $.rmClass)(el, 'warning') return (reachedLimit ? $.addClass : $.rmClass)(el, 'warning')
} }
setStatus(type, status) { setStatus(type: string, status: boolean) {
const name = `is${type}` const name = `is${type}`
if (this[name] === status) { return } if (this[name] === status) { return }
this[name] = status this[name] = status
@ -68,7 +86,7 @@ export default class Thread {
return this.setIcon('Archived', this.isArchived) return this.setIcon('Archived', this.isArchived)
} }
setIcon(type, status) { setIcon(type: string, status: boolean) {
const typeLC = type.toLowerCase() const typeLC = type.toLowerCase()
let icon = $(`.${typeLC}Icon`, this.OP.nodes.info) let icon = $(`.${typeLC}Icon`, this.OP.nodes.info)
if (!!icon === status) { return } if (!!icon === status) { return }
@ -84,8 +102,7 @@ export default class Thread {
alt: type, alt: type,
title: type, title: type,
className: `${typeLC}Icon retina` className: `${typeLC}Icon retina`
} }, g.BOARD.ID)
)
if (g.BOARD.ID === 'f') { if (g.BOARD.ID === 'f') {
icon.style.cssText = 'height: 18px; width: 18px;' icon.style.cssText = 'height: 18px; width: 18px;'
} }

View File

@ -408,7 +408,7 @@ $.before = (root, el) => root.parentNode.insertBefore($.nodes(el), root)
$.replace = (root, el) => root.parentNode.replaceChild($.nodes(el), root) $.replace = (root, el) => root.parentNode.replaceChild($.nodes(el), root)
$.el = function(tag, properties, properties2) { $.el = function (tag, properties, properties2?) {
const el = d.createElement(tag) const el = d.createElement(tag)
if (properties) { $.extend(el, properties) } if (properties) { $.extend(el, properties) }
if (properties2) { $.extend(el, properties2) } if (properties2) { $.extend(el, properties2) }
@ -813,7 +813,8 @@ if (platform === 'crx') {
} }
return Promise.all((() => { return Promise.all((() => {
const result = [] const result = []
for (key of keys) { result.push(GM.deleteValue(g.NAMESPACE + key)) for (key of keys) {
result.push(GM.deleteValue(g.NAMESPACE + key))
} }
return result return result
})()).then(function () { })()).then(function () {