mirror of
https://github.com/LalleSX/4chan-XZ.git
synced 2025-10-07 07:22:37 +02:00
a fix bug fix and types
This commit is contained in:
parent
5183de55b6
commit
e89a66aa9a
@ -663,12 +663,10 @@ const Header = {
|
|||||||
case 'granted':
|
case 'granted':
|
||||||
Header.areNotificationsEnabled = true
|
Header.areNotificationsEnabled = true
|
||||||
return
|
return
|
||||||
break
|
|
||||||
case 'denied':
|
case 'denied':
|
||||||
// requestPermission doesn't work if status is 'denied',
|
// requestPermission doesn't work if status is 'denied',
|
||||||
// but it'll still work if status is 'default'.
|
// but it'll still work if status is 'default'.
|
||||||
return
|
return
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const el = $.el('span',
|
const el = $.el('span',
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import Config from '../config/Config'
|
|||||||
import Filter from '../Filtering/Filter'
|
import Filter from '../Filtering/Filter'
|
||||||
import PostHiding from '../Filtering/PostHiding'
|
import PostHiding from '../Filtering/PostHiding'
|
||||||
import ThreadHiding from '../Filtering/ThreadHiding'
|
import ThreadHiding from '../Filtering/ThreadHiding'
|
||||||
import { c, Conf, d, doc, g } from '../globals/globals'
|
import { Board, c, Conf, d, doc, g } from '../globals/globals'
|
||||||
import Main from '../main/Main'
|
import Main from '../main/Main'
|
||||||
import Menu from '../Menu/Menu'
|
import Menu from '../Menu/Menu'
|
||||||
import CatalogLinks from '../Miscellaneous/CatalogLinks'
|
import CatalogLinks from '../Miscellaneous/CatalogLinks'
|
||||||
@ -31,8 +31,85 @@ import Header from './Header'
|
|||||||
import NavLinksPage from './Index/NavLinks.html'
|
import NavLinksPage from './Index/NavLinks.html'
|
||||||
import PageList from './Index/PageList.html'
|
import PageList from './Index/PageList.html'
|
||||||
import UI from './UI'
|
import UI from './UI'
|
||||||
|
interface Index {
|
||||||
const Index = {
|
req: boolean
|
||||||
|
liveThreadData: any
|
||||||
|
pageNum: any
|
||||||
|
currentPage: any
|
||||||
|
pagesNum: number
|
||||||
|
changed: any
|
||||||
|
showHiddenThreads: boolean
|
||||||
|
threadPosition: any
|
||||||
|
threadsNumPerPage: any
|
||||||
|
selectSort: any
|
||||||
|
initFinishedFired: boolean
|
||||||
|
cb: any
|
||||||
|
loaded: any
|
||||||
|
lastLongThresholds: any
|
||||||
|
inputs: any
|
||||||
|
selectRev: any
|
||||||
|
hashCommands: any
|
||||||
|
search: any
|
||||||
|
liveThreadDict: any
|
||||||
|
parsedThreads: any
|
||||||
|
replyData: any
|
||||||
|
selectMode: any
|
||||||
|
lastLongOptions: any
|
||||||
|
sortedThreadIDs: any
|
||||||
|
hideLabel: any
|
||||||
|
liveThreadIDs: any
|
||||||
|
notice: any
|
||||||
|
nTimeout: any
|
||||||
|
searchInput: any
|
||||||
|
update(): unknown
|
||||||
|
currentSort(currentSort: any): any
|
||||||
|
root(board: any, root: any): unknown
|
||||||
|
navLinks(topNavPos: Element, navLinks: any): unknown
|
||||||
|
pagelist(pagelist: any, pagelist1: any): unknown
|
||||||
|
endNotice(): unknown
|
||||||
|
threadsOnPage(pageNum: number): unknown
|
||||||
|
buildStructure(threadIDs: any): unknown
|
||||||
|
enabledOn(BOARD: Board): unknown
|
||||||
|
toggleHide(thread: any): unknown
|
||||||
|
sort(): unknown
|
||||||
|
buildIndex(): unknown
|
||||||
|
pushState(arg0: { mode: any }): unknown
|
||||||
|
pageLoad(arg0: boolean): unknown
|
||||||
|
saveSort(): unknown
|
||||||
|
saveLastLongThresholds(i: number): unknown
|
||||||
|
getCurrentPage(): unknown
|
||||||
|
setState(arg0: { search: any; mode: any; sort: any; page: any; hash: string }): unknown
|
||||||
|
processHash(): unknown
|
||||||
|
userPageNav(arg0: number): unknown
|
||||||
|
buildCatalogReplies(arg0: any): unknown
|
||||||
|
savePerBoard(arg0: string, currentSort: any): unknown
|
||||||
|
buildPagelist(): unknown
|
||||||
|
setupSearch(): unknown
|
||||||
|
setupMode(): unknown
|
||||||
|
setupSort(): unknown
|
||||||
|
setPage(): unknown
|
||||||
|
scrollToIndex(): unknown
|
||||||
|
getPagesNum(): number
|
||||||
|
getMaxPageNum(): unknown
|
||||||
|
isHidden(threadID: any): unknown
|
||||||
|
load(arg0: string, arg1: string, load: any): any
|
||||||
|
button(button: any, arg1: string): unknown
|
||||||
|
parse(response: any): unknown
|
||||||
|
parseThreadList(pages: any): unknown
|
||||||
|
buildReplies(threads: any[]): any
|
||||||
|
updateHideLabel(): unknown
|
||||||
|
isHiddenReply(ID: any, data: any): unknown
|
||||||
|
querySearch(search: any): any
|
||||||
|
sortOnTop(arg0: (obj: any) => any): unknown
|
||||||
|
buildCatalog(threadIDs: any): unknown
|
||||||
|
buildThreads(threadIDs: any, arg1: boolean, arg2: any): unknown
|
||||||
|
buildCatalogPart(arg0: any): unknown
|
||||||
|
buildCatalogViews(threads: any): unknown
|
||||||
|
sizeCatalogViews(threads: any): unknown
|
||||||
|
onSearchInput(): unknown
|
||||||
|
searchMatch(arg0: any, keywords: any): unknown
|
||||||
|
}
|
||||||
|
const Index: Index = {
|
||||||
showHiddenThreads: false,
|
showHiddenThreads: false,
|
||||||
changed: {},
|
changed: {},
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,9 @@ import Post from "./Post"
|
|||||||
import Thread from "./Thread"
|
import Thread from "./Thread"
|
||||||
|
|
||||||
export default class CatalogThread {
|
export default class CatalogThread {
|
||||||
ID: any
|
ID: string | number
|
||||||
thread: Thread
|
thread: Thread
|
||||||
board: any
|
board: Board
|
||||||
nodes: { root: Post; thumb: HTMLElement; icons: any; postCount: number; fileCount: number; pageCount: number; replies: any }
|
nodes: { root: Post; thumb: HTMLElement; icons: any; postCount: number; fileCount: number; pageCount: number; replies: any }
|
||||||
toString() { return this.ID }
|
toString() { return this.ID }
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,7 @@ export default class Post {
|
|||||||
return el
|
return el
|
||||||
})()
|
})()
|
||||||
normalizedOriginal: any
|
normalizedOriginal: any
|
||||||
|
indexRefreshSeen: any
|
||||||
|
|
||||||
toString() { return this.ID }
|
toString() { return this.ID }
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
/*
|
import $ from '../platform/$'
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
class ShimSet {
|
class ShimSet {
|
||||||
elements: any
|
elements: any
|
||||||
size: number
|
size: number
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import SimpleDict from "./SimpleDict"
|
|||||||
|
|
||||||
|
|
||||||
export default class Thread {
|
export default class Thread {
|
||||||
ID: number
|
ID: number | string
|
||||||
OP: Post
|
OP: Post
|
||||||
isArchived: boolean
|
isArchived: boolean
|
||||||
isClosed: boolean
|
isClosed: boolean
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
// 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"
|
||||||
@ -18,33 +17,48 @@ 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 = {}
|
type AjaxPageOptions = {
|
||||||
return function (key, value) {
|
responseType?: string;
|
||||||
if (value != null) {
|
type?: string;
|
||||||
return (cache[key] = value)
|
form?: Document | null;
|
||||||
} else {
|
headers?: { [key: string]: string };
|
||||||
return cache[key]
|
onloadend?: () => void;
|
||||||
|
timeout?: number;
|
||||||
|
withCredentials?: boolean;
|
||||||
|
onprogress?: (event: ProgressEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.ajaxPage = function (url: string, options: AjaxPageOptions) {
|
||||||
|
const {
|
||||||
|
responseType = 'json',
|
||||||
|
type = options.form ? 'post' : 'get',
|
||||||
|
onloadend,
|
||||||
|
timeout,
|
||||||
|
withCredentials,
|
||||||
|
onprogress,
|
||||||
|
form,
|
||||||
|
headers = {},
|
||||||
|
} = options
|
||||||
|
|
||||||
|
const xhr = new XMLHttpRequest()
|
||||||
|
xhr.open(type, url, true)
|
||||||
|
|
||||||
|
for (const key in headers) {
|
||||||
|
xhr.setRequestHeader(key, headers[key])
|
||||||
}
|
}
|
||||||
})()
|
|
||||||
$.ajaxPage = function (url, options) {
|
Object.assign(xhr, { onloadend, timeout, responseType, withCredentials })
|
||||||
if (options.responseType == null) { options.responseType = 'json' }
|
Object.assign(xhr.upload, { onprogress })
|
||||||
if (!options.type) { options.type = (options.form && 'post') || 'get' }
|
|
||||||
const { onloadend, timeout, responseType, withCredentials, type, onprogress, form, headers } = options
|
xhr.addEventListener('error', () => {
|
||||||
const r = new XMLHttpRequest()
|
if (!xhr.status) {
|
||||||
r.open(type, url, true)
|
console.warn(`4chan X failed to load: ${url}`)
|
||||||
const object = headers || {}
|
|
||||||
for (const key in object) {
|
|
||||||
const value = object[key]
|
|
||||||
r.setRequestHeader(key, value)
|
|
||||||
}
|
}
|
||||||
$.extend(r, { onloadend, timeout, responseType, withCredentials })
|
})
|
||||||
$.extend(r.upload, { onprogress })
|
|
||||||
// connection error or content blocker
|
xhr.send(form)
|
||||||
$.on(r, 'error', function () { if (!r.status) { return c.warn(`4chan X failed to load: ${url}`) } })
|
return xhr
|
||||||
r.send(form)
|
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
$.ready = function (fc) {
|
$.ready = function (fc) {
|
||||||
if (d.readyState !== 'loading') {
|
if (d.readyState !== 'loading') {
|
||||||
@ -98,7 +112,7 @@ $.ajax = (function () {
|
|||||||
pageXHR = XMLHttpRequest
|
pageXHR = XMLHttpRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = (function (url: string, options) {
|
const r = (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' }
|
||||||
// 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
|
||||||
@ -201,7 +215,7 @@ $.ajax = (function () {
|
|||||||
return r.abort()
|
return r.abort()
|
||||||
}
|
}
|
||||||
, false)
|
, false)
|
||||||
})
|
}, '4chanXAjax')
|
||||||
|
|
||||||
$.on(d, '4chanXAjaxProgress', function (e) {
|
$.on(d, '4chanXAjaxProgress', function (e) {
|
||||||
let req
|
let req
|
||||||
@ -518,15 +532,31 @@ $.debounce = function (wait, fn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.queueTask = function (fn) {
|
$.queueTask = (function () {
|
||||||
if (typeof requestIdleCallback === 'function') {
|
// inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
||||||
return requestIdleCallback(fn)
|
const taskQueue = []
|
||||||
} else {
|
const execTask = function () {
|
||||||
return setTimeout(fn, 0)
|
const task = taskQueue.shift()
|
||||||
|
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);` })
|
||||||
@ -639,13 +669,8 @@ if (platform === 'crx') {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
$.sync = (key, cb) => $.syncing[key] = cb
|
$.sync = (key, cb) => $.syncing[key] = cb
|
||||||
$.forceSync = function (key, cb) {
|
$.forceSync = function () { }
|
||||||
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()) {
|
||||||
@ -997,15 +1022,15 @@ if (platform === 'crx') {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
$.clear = function (cb: Callbacks) {
|
$.clear = function (cb) {
|
||||||
// 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), cb)
|
$.delete(Object.keys(Conf))
|
||||||
$.delete(['previousversion', 'QR Size', 'QR.persona'], cb)
|
$.delete(['previousversion', 'QR Size', 'QR.persona'])
|
||||||
try {
|
try {
|
||||||
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')), cb)
|
$.delete($.listValues().map(key => key.replace(g.NAMESPACE, '')))
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
return cb
|
return cb?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user