mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2025-10-07 07:22:37 +02:00
types and small improvements
This commit is contained in:
parent
329fc4dd14
commit
69051d6095
1
diagnostic/comit-self note.txt
Normal file
1
diagnostic/comit-self note.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Only classes
|
||||||
@ -11,7 +11,7 @@ export default class Post {
|
|||||||
declare root: HTMLElement
|
declare root: HTMLElement
|
||||||
declare thread: Thread
|
declare thread: Thread
|
||||||
declare board: Board
|
declare board: Board
|
||||||
declare ID: number
|
declare ID: number | string
|
||||||
declare postID: number
|
declare postID: number
|
||||||
declare threadID: number
|
declare threadID: number
|
||||||
declare boardID: number | string
|
declare boardID: number | string
|
||||||
@ -22,7 +22,7 @@ export default class Post {
|
|||||||
declare nodes: ReturnType<Post['parseNodes']>
|
declare nodes: ReturnType<Post['parseNodes']>
|
||||||
declare isDead: boolean
|
declare isDead: boolean
|
||||||
declare isHidden: boolean
|
declare isHidden: boolean
|
||||||
declare clones: any[]
|
declare clones: unknown[]
|
||||||
declare isRebuilt?: boolean
|
declare isRebuilt?: boolean
|
||||||
declare isFetchedQuote: boolean
|
declare isFetchedQuote: boolean
|
||||||
declare isClone: boolean
|
declare isClone: boolean
|
||||||
@ -31,17 +31,17 @@ export default class Post {
|
|||||||
declare files: ReturnType<Post['parseFile']>[]
|
declare files: ReturnType<Post['parseFile']>[]
|
||||||
|
|
||||||
declare info: {
|
declare info: {
|
||||||
subject: string | undefined,
|
subject: string,
|
||||||
name: string | undefined,
|
name: string,
|
||||||
email: string | undefined,
|
email: string,
|
||||||
tripcode: string | undefined,
|
tripcode: string,
|
||||||
uniqueID: string | undefined,
|
uniqueID: string,
|
||||||
capcode: string | undefined,
|
capcode: string,
|
||||||
pass: string | undefined,
|
pass: string,
|
||||||
flagCode: string | undefined,
|
flagCode: string,
|
||||||
flagCodeTroll: string | undefined,
|
flagCodeTroll: string,
|
||||||
flag: string | undefined,
|
flag: string,
|
||||||
date: Date | undefined,
|
date: Date,
|
||||||
nameBlock: string,
|
nameBlock: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ export default class Post {
|
|||||||
if (!this.isReply) {
|
if (!this.isReply) {
|
||||||
this.thread.OP = this
|
this.thread.OP = this
|
||||||
for (const key of ['isSticky', 'isClosed', 'isArchived']) {
|
for (const key of ['isSticky', 'isClosed', 'isArchived']) {
|
||||||
var selector
|
var selector: any
|
||||||
if (selector = g.SITE.selectors.icons[key]) {
|
if (selector = g.SITE.selectors.icons[key]) {
|
||||||
this.thread[key] = !!$(selector, this.nodes.info)
|
this.thread[key] = !!$(selector, this.nodes.info)
|
||||||
}
|
}
|
||||||
@ -135,8 +135,8 @@ export default class Post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isFetchedQuote && (this.ID > this.thread.lastPost)) { this.thread.lastPost = this.ID }
|
if (!this.isFetchedQuote && (this.ID > this.thread.lastPost)) { this.thread.lastPost = this.ID }
|
||||||
this.board.posts.push(this.ID, this)
|
this.board.posts.push(this.ID.toString(), this)
|
||||||
this.thread.posts.push(this.ID, this)
|
this.thread.posts.push(this.ID.toString(), this)
|
||||||
g.posts.push(this.fullID, this)
|
g.posts.push(this.fullID, this)
|
||||||
|
|
||||||
this.isFetchedQuote = false
|
this.isFetchedQuote = false
|
||||||
@ -187,7 +187,7 @@ export default class Post {
|
|||||||
|
|
||||||
parseComment() {
|
parseComment() {
|
||||||
// Merge text nodes and remove empty ones.
|
// Merge text nodes and remove empty ones.
|
||||||
let bq
|
let bq: Node
|
||||||
this.nodes.comment.normalize()
|
this.nodes.comment.normalize()
|
||||||
|
|
||||||
// Get the comment's text.
|
// Get the comment's text.
|
||||||
@ -221,8 +221,8 @@ export default class Post {
|
|||||||
return this.nodesToText(bq)
|
return this.nodesToText(bq)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodesToText(bq) {
|
nodesToText(bq: any) {
|
||||||
let node
|
let node: Node
|
||||||
let text = ""
|
let text = ""
|
||||||
const nodes = $.X('.//br|.//text()', bq)
|
const nodes = $.X('.//br|.//text()', bq)
|
||||||
let i = 0
|
let i = 0
|
||||||
@ -232,7 +232,7 @@ export default class Post {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanSpoilers(bq) {
|
cleanSpoilers(bq: HTMLElement) {
|
||||||
const spoilers = $$(g.SITE.selectors.spoiler, bq)
|
const spoilers = $$(g.SITE.selectors.spoiler, bq)
|
||||||
for (const node of spoilers) {
|
for (const node of spoilers) {
|
||||||
$.replace(node, $.tn('[spoiler]'))
|
$.replace(node, $.tn('[spoiler]'))
|
||||||
@ -246,7 +246,7 @@ export default class Post {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseQuote(quotelink) {
|
parseQuote(quotelink: HTMLAnchorElement) {
|
||||||
// Only add quotes that link to posts on an imageboard.
|
// Only add quotes that link to posts on an imageboard.
|
||||||
// Don't add:
|
// Don't add:
|
||||||
// - board links. (>>>/b/)
|
// - board links. (>>>/b/)
|
||||||
@ -326,8 +326,8 @@ export default class Post {
|
|||||||
return file as File
|
return file as File
|
||||||
}
|
}
|
||||||
|
|
||||||
kill(file, index = 0) {
|
kill(file: any, index = 0) {
|
||||||
let strong
|
let strong: { textContent: string }
|
||||||
if (file) {
|
if (file) {
|
||||||
if (this.isDead || this.files[index].isDead) { return }
|
if (this.isDead || this.files[index].isDead) { return }
|
||||||
this.files[index].isDead = true
|
this.files[index].isDead = true
|
||||||
@ -395,20 +395,20 @@ export default class Post {
|
|||||||
this.board.posts.rm(this)
|
this.board.posts.rm(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
addClone(context, contractThumb) {
|
addClone(context: any, contractThumb: any) {
|
||||||
// Callbacks may not have been run yet due to anti-browser-lock delay in Main.callbackNodesDB.
|
// Callbacks may not have been run yet due to anti-browser-lock delay in Main.callbackNodesDB.
|
||||||
Callbacks.Post.execute(this)
|
Callbacks.Post.execute(this)
|
||||||
return new PostClone(this, context, contractThumb)
|
return new PostClone(this, context, contractThumb)
|
||||||
}
|
}
|
||||||
|
|
||||||
rmClone(index) {
|
rmClone(index: number) {
|
||||||
this.clones.splice(index, 1)
|
this.clones.splice(index, 1)
|
||||||
for (const clone of this.clones.slice(index)) {
|
for (const clone of this.clones.slice(index)) {
|
||||||
clone.nodes.root.dataset.clone = index++
|
clone.nodes.root.dataset.clone = index++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCatalogOP(isCatalogOP) {
|
setCatalogOP(isCatalogOP: boolean) {
|
||||||
this.nodes.root.classList.toggle('catalog-container', isCatalogOP)
|
this.nodes.root.classList.toggle('catalog-container', isCatalogOP)
|
||||||
this.nodes.root.classList.toggle('opContainer', !isCatalogOP)
|
this.nodes.root.classList.toggle('opContainer', !isCatalogOP)
|
||||||
this.nodes.post.classList.toggle('catalog-post', isCatalogOP)
|
this.nodes.post.classList.toggle('catalog-post', isCatalogOP)
|
||||||
@ -422,11 +422,11 @@ export class PostClone extends Post {
|
|||||||
|
|
||||||
static suffix = 0
|
static suffix = 0
|
||||||
|
|
||||||
constructor(origin, context, contractThumb) {
|
constructor(origin: Post, context: Post, contractThumb: any) {
|
||||||
super()
|
super()
|
||||||
this.isClone = true
|
this.isClone = true
|
||||||
|
|
||||||
let file, fileRoots, key
|
let file, fileRoots: any[], key: string | number
|
||||||
this.origin = origin
|
this.origin = origin
|
||||||
this.context = context
|
this.context = context
|
||||||
for (key of ['ID', 'postID', 'threadID', 'boardID', 'siteID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply']) {
|
for (key of ['ID', 'postID', 'threadID', 'boardID', 'siteID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply']) {
|
||||||
@ -458,9 +458,9 @@ export class PostClone extends Post {
|
|||||||
// Remove catalog stuff.
|
// Remove catalog stuff.
|
||||||
if (!this.isReply) {
|
if (!this.isReply) {
|
||||||
this.setCatalogOP(false)
|
this.setCatalogOP(false)
|
||||||
$.rm($('.catalog-link', this.nodes.post))
|
$.rm($('.catalog-link')),
|
||||||
$.rm($('.catalog-stats', this.nodes.post))
|
$.rm($('.catalog-stats')),
|
||||||
$.rm($('.catalog-replies', this.nodes.post))
|
$.rm($('.catalog-subject'))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parseQuotes()
|
this.parseQuotes()
|
||||||
@ -495,7 +495,7 @@ export class PostClone extends Post {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneWithoutVideo(node) {
|
cloneWithoutVideo(node: HTMLElement) {
|
||||||
if ((node.tagName === 'VIDEO') && !node.dataset.md5) { // (exception for WebM thumbnails)
|
if ((node.tagName === 'VIDEO') && !node.dataset.md5) { // (exception for WebM thumbnails)
|
||||||
return []
|
return []
|
||||||
} else if ((node.nodeType === Node.ELEMENT_NODE) && $('video', node)) {
|
} else if ((node.nodeType === Node.ELEMENT_NODE) && $('video', node)) {
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
import { d } from "../globals/globals"
|
import { d } from "../globals/globals"
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
const $$ = (selector, root = d.body) => [...Array.from(root.querySelectorAll(selector))]
|
const $$ = (selector, root = d.body) => [...Array.from(root.querySelectorAll(selector))]
|
||||||
export default $$
|
export default $$
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
// loosely follows the jquery api:
|
// loosely follows the jquery api:
|
||||||
// http://api.jquery.com/
|
// http://api.jquery.com/
|
||||||
|
|
||||||
|
import Callbacks from "../classes/Callbacks"
|
||||||
import Notice from "../classes/Notice"
|
import Notice from "../classes/Notice"
|
||||||
import { c, Conf, d, doc, g } from "../globals/globals"
|
import { c, Conf, d, doc, g } from "../globals/globals"
|
||||||
import CrossOrigin from "./CrossOrigin"
|
import CrossOrigin from "./CrossOrigin"
|
||||||
@ -17,7 +18,16 @@ import { debounce, dict, MINUTE, platform, SECOND } from "./helpers"
|
|||||||
const $ = (selector, root = document.body) => root.querySelector(selector)
|
const $ = (selector, root = document.body) => root.querySelector(selector)
|
||||||
|
|
||||||
$.id = id => d.getElementById(id)
|
$.id = id => d.getElementById(id)
|
||||||
|
$.cache = (function () {
|
||||||
|
const cache = {}
|
||||||
|
return function (key, value) {
|
||||||
|
if (value != null) {
|
||||||
|
return (cache[key] = value)
|
||||||
|
} else {
|
||||||
|
return cache[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
$.ajaxPage = function (url, options) {
|
$.ajaxPage = function (url, options) {
|
||||||
if (options.responseType == null) { options.responseType = 'json' }
|
if (options.responseType == null) { options.responseType = 'json' }
|
||||||
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
||||||
@ -88,7 +98,7 @@ $.ajax = (function () {
|
|||||||
pageXHR = XMLHttpRequest
|
pageXHR = XMLHttpRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = (function (url, options = {}) {
|
const r = (function (url: string, options) {
|
||||||
if (options.responseType == null) { options.responseType = 'json' }
|
if (options.responseType == null) { options.responseType = 'json' }
|
||||||
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
||||||
// XXX https://forums.lanik.us/viewtopic.php?f=64&t=24173&p=78310
|
// XXX https://forums.lanik.us/viewtopic.php?f=64&t=24173&p=78310
|
||||||
@ -321,7 +331,7 @@ $.onExists = function (root, selector, cb) {
|
|||||||
if (el = $(selector, root)) {
|
if (el = $(selector, root)) {
|
||||||
return cb(el)
|
return cb(el)
|
||||||
}
|
}
|
||||||
var observer = new MutationObserver(function () {
|
const observer = new MutationObserver(function () {
|
||||||
if (el = $(selector, root)) {
|
if (el = $(selector, root)) {
|
||||||
observer.disconnect()
|
observer.disconnect()
|
||||||
return cb(el)
|
return cb(el)
|
||||||
@ -508,31 +518,15 @@ $.debounce = function (wait, fn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.queueTask = (function () {
|
$.queueTask = function (fn) {
|
||||||
// inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
if (typeof requestIdleCallback === 'function') {
|
||||||
const taskQueue = []
|
return requestIdleCallback(fn)
|
||||||
const execTask = function () {
|
} else {
|
||||||
const task = taskQueue.shift()
|
return setTimeout(fn, 0)
|
||||||
const func = task[0]
|
|
||||||
const args = Array.prototype.slice.call(task, 1)
|
|
||||||
return func.apply(func, args)
|
|
||||||
}
|
}
|
||||||
if (window.MessageChannel) {
|
}
|
||||||
const taskChannel = new MessageChannel()
|
|
||||||
taskChannel.port1.onmessage = execTask
|
|
||||||
return function () {
|
|
||||||
taskQueue.push(arguments)
|
|
||||||
return taskChannel.port2.postMessage(null)
|
|
||||||
}
|
|
||||||
} else { // XXX Firefox
|
|
||||||
return function () {
|
|
||||||
taskQueue.push(arguments)
|
|
||||||
return setTimeout(execTask, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
$.global = function (fn, data) {
|
$.global = function (fn, data?) {
|
||||||
if (doc) {
|
if (doc) {
|
||||||
const script = $.el('script',
|
const script = $.el('script',
|
||||||
{ textContent: `(${fn}).call(document.currentScript.dataset);` })
|
{ textContent: `(${fn}).call(document.currentScript.dataset);` })
|
||||||
@ -645,8 +639,13 @@ if (platform === 'crx') {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
$.sync = (key, cb) => $.syncing[key] = cb
|
$.sync = (key, cb) => $.syncing[key] = cb
|
||||||
$.forceSync = function () { }
|
$.forceSync = function (key, cb) {
|
||||||
|
chrome.storage.sync.get(key, function (data) {
|
||||||
|
if (data[key] != null) {
|
||||||
|
cb(data[key], key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
$.crxWorking = function () {
|
$.crxWorking = function () {
|
||||||
try {
|
try {
|
||||||
if (chrome.runtime.getManifest()) {
|
if (chrome.runtime.getManifest()) {
|
||||||
@ -998,15 +997,15 @@ if (platform === 'crx') {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
$.clear = function (cb) {
|
$.clear = function (cb: Callbacks) {
|
||||||
// XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
// XXX https://github.com/greasemonkey/greasemonkey/issues/2033
|
||||||
// Also support case where GM_listValues is not defined.
|
// Also support case where GM_listValues is not defined.
|
||||||
$.delete(Object.keys(Conf))
|
$.delete(Object.keys(Conf), cb)
|
||||||
$.delete(['previousversion', 'QR Size', 'QR.persona'])
|
$.delete(['previousversion', 'QR Size', 'QR.persona'], cb)
|
||||||
try {
|
try {
|
||||||
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')))
|
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')), cb)
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
return cb?.()
|
return cb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user