var to let and const

This commit is contained in:
Lalle 2023-05-05 14:42:32 +02:00
parent 9dbb04d165
commit 5a34fa1435
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
31 changed files with 115 additions and 103 deletions

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
tools/*
dist/*
src/meta/*
src/types/*

View File

@ -19,7 +19,7 @@
}, },
"env": { "env": {
"browser": true, "browser": true,
"es2021": true, "es2020": true,
"node": true "node": true
}, },
"plugins": [ "plugins": [

View File

@ -31,7 +31,7 @@ const Redirect = {
const archives = dict() const archives = dict()
for (data of Conf['archives']) { for (data of Conf['archives']) {
var name, software, uid let name, software, uid
for (const key of ['boards', 'files']) { for (const key of ['boards', 'files']) {
if (!(data[key] instanceof Array)) { data[key] = [] } if (!(data[key] instanceof Array)) { data[key] = [] }
} }
@ -48,7 +48,7 @@ const Redirect = {
for (boardID in Conf['selectedArchives']) { for (boardID in Conf['selectedArchives']) {
const record = Conf['selectedArchives'][boardID] const record = Conf['selectedArchives'][boardID]
for (const type in record) { for (const type in record) {
var archive let archive
const id = record[type] const id = record[type]
if ((archive = archives[JSON.stringify(id)]) && $.hasOwn(o, type)) { if ((archive = archives[JSON.stringify(id)]) && $.hasOwn(o, type)) {
boards = type === 'file' ? archive.files : archive.boards boards = type === 'file' ? archive.files : archive.boards
@ -89,7 +89,7 @@ const Redirect = {
for (let i = 0; i < urls.length; i++) { for (let i = 0; i < urls.length; i++) {
url = urls[i] url = urls[i]
if (['[', '{'].includes(url[0])) { if (['[', '{'].includes(url[0])) {
var response let response
try { try {
response = JSON.parse(url) response = JSON.parse(url)
} catch (err) { } catch (err) {

View File

@ -69,7 +69,7 @@ const Filter = {
} }
// Don't mix up filter flags with the regular expression. // Don't mix up filter flags with the regular expression.
var filter = line.replace(regexp[0], '') const filter = line.replace(regexp[0], '')
// List of the boards this filter applies to. // List of the boards this filter applies to.
const boards = this.parseBoards(filter.match(/(?:^|;)\s*boards:([^;]+)/)?.[1]) const boards = this.parseBoards(filter.match(/(?:^|;)\s*boards:([^;]+)/)?.[1])

View File

@ -21,7 +21,7 @@ const Recursive = {
node() { node() {
if (this.isClone || this.isFetchedQuote) { return } if (this.isClone || this.isFetchedQuote) { return }
for (const quote of this.quotes) { for (const quote of this.quotes) {
var obj let obj
if ((obj = Recursive.recursives[quote])) { if ((obj = Recursive.recursives[quote])) {
for (let i = 0; i < obj.recursives.length; i++) { for (let i = 0; i < obj.recursives.length; i++) {
const recursive = obj.recursives[i] const recursive = obj.recursives[i]

View File

@ -80,7 +80,7 @@ const Get = {
// get all of their backlinks. // get all of their backlinks.
if (Conf['Quote Backlinks']) { if (Conf['Quote Backlinks']) {
for (const quote of post.quotes) { for (const quote of post.quotes) {
var qPost let qPost
if ((qPost = posts.get(quote))) { handleQuotes(qPost, 'backlinks') } if ((qPost = posts.get(quote))) { handleQuotes(qPost, 'backlinks') }
} }
} }

View File

@ -612,7 +612,7 @@ const Index: Index = {
const commands = hash.slice(1).split('/') const commands = hash.slice(1).split('/')
const leftover = [] const leftover = []
for (const command of commands) { for (const command of commands) {
var mode, sort let mode, sort
if (mode = $.getOwn(Index.hashCommands.mode, command)) { if (mode = $.getOwn(Index.hashCommands.mode, command)) {
state.mode = mode state.mode = mode
} else if (command === 'index') { } else if (command === 'index') {
@ -929,7 +929,7 @@ const Index: Index = {
Index.parsedThreads = dict() Index.parsedThreads = dict()
Index.replyData = dict() Index.replyData = dict()
for (let i = 0; i < Index.liveThreadData.length; i++) { for (let i = 0; i < Index.liveThreadData.length; i++) {
var obj, results let obj, results
const data = Index.liveThreadData[i] const data = Index.liveThreadData[i]
Index.liveThreadDict[data.no] = data Index.liveThreadDict[data.no] = data
Index.threadPosition[data.no] = i Index.threadPosition[data.no] = i
@ -972,9 +972,9 @@ const Index: Index = {
const newThreads = [] const newThreads = []
let newPosts = [] let newPosts = []
for (const ID of threadIDs) { for (const ID of threadIDs) {
var opRoot, thread let opRoot, thread
try { try {
var OP let OP
const threadData = Index.liveThreadDict[ID] const threadData = Index.liveThreadDict[ID]
if (thread = g.BOARD.threads.get(ID)) { if (thread = g.BOARD.threads.get(ID)) {
@ -1040,11 +1040,11 @@ const Index: Index = {
let errors let errors
const posts = [] const posts = []
for (const thread of threads) { for (const thread of threads) {
var lastReplies let lastReplies
if (!(lastReplies = Index.liveThreadDict[thread.ID].last_replies)) { continue } if (!(lastReplies = Index.liveThreadDict[thread.ID].last_replies)) { continue }
const nodes = [] const nodes = []
for (const data of lastReplies) { for (const data of lastReplies) {
var node, post let node, post
if ((post = thread.posts.get(data.no)) && !post.isFetchedQuote) { if ((post = thread.posts.get(data.no)) && !post.isFetchedQuote) {
nodes.push(post.nodes.root) nodes.push(post.nodes.root)
continue continue
@ -1123,8 +1123,8 @@ const Index: Index = {
Index.sortedThreadIDs = (() => { Index.sortedThreadIDs = (() => {
switch (sortType) { switch (sortType) {
case 'lastreply': case 'lastlong': case 'lastreply': case 'lastlong':
var repliesAvailable = liveThreadData.some(thread => thread.last_replies?.length) const repliesAvailable = liveThreadData.some(thread => thread.last_replies?.length)
var lastlong = function (thread) { const lastlong = function (thread) {
if (!repliesAvailable) { if (!repliesAvailable) {
return thread.last_modified return thread.last_modified
} }
@ -1142,7 +1142,7 @@ const Index: Index = {
} }
if (thread.omitted_posts && thread.last_replies?.length) { return thread.last_replies[0] } else { return thread } if (thread.omitted_posts && thread.last_replies?.length) { return thread.last_replies[0] } else { return thread }
} }
var lastlongD = dict() const lastlongD = dict()
for (const thread of liveThreadData) { for (const thread of liveThreadData) {
lastlongD[thread.no] = lastlong(thread).no lastlongD[thread.no] = lastlong(thread).no
} }

View File

@ -1031,7 +1031,7 @@ vp-replace
for (boardID in Conf['selectedArchives']) { for (boardID in Conf['selectedArchives']) {
const data = Conf['selectedArchives'][boardID] const data = Conf['selectedArchives'][boardID]
for (const type in data) { for (const type in data) {
var select let select
const id = data[type] const id = data[type]
if (select = $(`select[data-boardid='${boardID}'][data-type='${type}']`, tbody)) { if (select = $(`select[data-boardid='${boardID}'][data-type='${type}']`, tbody)) {
select.value = JSON.stringify(id) select.value = JSON.stringify(id)

View File

@ -10,7 +10,7 @@ import Notice from "../classes/Notice"
import Post from "../classes/Post" import Post from "../classes/Post"
import Config from "../config/Config" import Config from "../config/Config"
import Filter from "../Filtering/Filter" import Filter from "../Filtering/Filter"
import { c,Conf, g } from "../globals/globals" import { c, Conf, g } from "../globals/globals"
import ImageHost from "../Images/ImageHost" import ImageHost from "../Images/ImageHost"
import Menu from "../Menu/Menu" import Menu from "../Menu/Menu"
import Keybinds from "../Miscellaneous/Keybinds" import Keybinds from "../Miscellaneous/Keybinds"
@ -25,7 +25,7 @@ const Test = {
if (Conf['Menu']) { if (Conf['Menu']) {
const a = $.el('a', const a = $.el('a',
{textContent: 'Test HTML building'}) { textContent: 'Test HTML building' })
$.on(a, 'click', this.cb.testOne) $.on(a, 'click', this.cb.testOne)
Menu.menu.addEntry({ Menu.menu.addEntry({
el: a, el: a,
@ -37,17 +37,19 @@ const Test = {
} }
const a2 = $.el('a', const a2 = $.el('a',
{textContent: 'Test HTML building'}) { textContent: 'Test HTML building' })
$.on(a2, 'click', this.cb.testAll) $.on(a2, 'click', this.cb.testAll)
Header.menu.addEntry({ Header.menu.addEntry({
el: a2}) el: a2
})
if (Unread.posts) { if (Unread.posts) {
const testOrderLink = $.el('a', const testOrderLink = $.el('a',
{textContent: 'Test Post Order'}) { textContent: 'Test Post Order' })
$.on(testOrderLink, 'click', this.cb.testOrder) $.on(testOrderLink, 'click', this.cb.testOrder)
Header.menu.addEntry({ Header.menu.addEntry({
el: testOrderLink}) el: testOrderLink
})
} }
return $.on(d, 'keydown', this.cb.keydown) return $.on(d, 'keydown', this.cb.keydown)
@ -78,7 +80,7 @@ const Test = {
el.src = el.src.replace(/(spoiler-\w+)\d(\.png)$/, '$11$2') el.src = el.src.replace(/(spoiler-\w+)\d(\.png)$/, '$11$2')
} }
for (el of $$('pre.prettyprinted', root2)) { for (el of $$('pre.prettyprinted', root2)) {
var nodes = $.X('.//br|.//wbr|.//text()', el) let nodes = $.X('.//br|.//wbr|.//text()', el)
i = 0 i = 0
nodes = ((() => { nodes = ((() => {
const result = [] const result = []
@ -125,9 +127,9 @@ const Test = {
testOne(post) { testOne(post) {
Test.postsRemaining++ Test.postsRemaining++
return $.cache(g.SITE.urls.threadJSON({boardID: post.boardID, threadID: post.threadID}), function() { return $.cache(g.SITE.urls.threadJSON({ boardID: post.boardID, threadID: post.threadID }), function () {
if (!this.response) { return } if (!this.response) { return }
const {posts} = this.response const { posts } = this.response
g.SITE.Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler g.SITE.Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler
for (const postData of posts) { for (const postData of posts) {
if (postData.no === post.ID) { if (postData.no === post.ID) {
@ -136,7 +138,7 @@ const Test = {
const root = g.SITE.Build.post(obj) const root = g.SITE.Build.post(obj)
const t2 = new Date().getTime() const t2 = new Date().getTime()
Test.time += t2 - t1 Test.time += t2 - t1
const post2 = new Post(root, post.thread, post.board, {forBuildTest: true}) const post2 = new Post(root, post.thread, post.board, { forBuildTest: true })
let fail = false let fail = false
const x = post.normalizedOriginal const x = post.normalizedOriginal
@ -154,7 +156,7 @@ const Test = {
for (const key in Config.filter) { for (const key in Config.filter) {
if ((!key === 'General') && !((key === 'MD5') && (post.board.ID === 'f'))) { if ((!key === 'General') && !((key === 'MD5') && (post.board.ID === 'f'))) {
const val1 = Filter.values(key, obj) const val1 = Filter.values(key, obj)
var val2 = Filter.values(key, post2) const val2 = Filter.values(key, post2)
if ((val1.length !== val2.length) || !val1.every((x, i) => x === val2[i])) { if ((val1.length !== val2.length) || !val1.every((x, i) => x === val2[i])) {
fail = true fail = true
c.log(`${post.fullID} has filter bug in ${key}`) c.log(`${post.fullID} has filter bug in ${key}`)
@ -177,7 +179,7 @@ const Test = {
}, },
testAll() { testAll() {
g.posts.forEach(function(post) { g.posts.forEach(function (post) {
if (!post.isClone && !post.isFetchedQuote) { if (!post.isClone && !post.isFetchedQuote) {
let abbr let abbr
if (!((abbr = $('.abbr', post.nodes.comment)) && /Comment too long\./.test(abbr.textContent))) { if (!((abbr = $('.abbr', post.nodes.comment)) && /Comment too long\./.test(abbr.textContent))) {
@ -215,17 +217,19 @@ const Test = {
let x let x
const list1 = ((() => { const list1 = ((() => {
const result = [] const result = []
for (x of Unread.order.order()) { result.push(x.ID) for (x of Unread.order.order()) {
result.push(x.ID)
} }
return result return result
})()) })())
const list2 = ((() => { const list2 = ((() => {
const result1 = [] const result1 = []
for (x of ($$((g.SITE.isOPContainerThread ? `${g.SITE.selectors.thread}, ` : '') + g.SITE.selectors.postContainer))) { result1.push(+x.id.match(/\d*$/)[0]) for (x of ($$((g.SITE.isOPContainerThread ? `${g.SITE.selectors.thread}, ` : '') + g.SITE.selectors.postContainer))) {
result1.push(+x.id.match(/\d*$/)[0])
} }
return result1 return result1
})()) })())
const pass = (function() { const pass = (function () {
if (list1.length !== list2.length) { return false } if (list1.length !== list2.length) { return false }
for (let i = 0, end = list1.length; i < end; i++) { for (let i = 0, end = list1.length; i < end; i++) {
if (list1[i] !== list2[i]) { return false } if (list1[i] !== list2[i]) { return false }

View File

@ -127,7 +127,7 @@ const Gallery = {
$.on(window, 'resize', Gallery.cb.setHeight) $.on(window, 'resize', Gallery.cb.setHeight)
for (const postThumb of $$(g.SITE.selectors.file.thumb)) { for (const postThumb of $$(g.SITE.selectors.file.thumb)) {
var post let post
if (!(post = Get.postFromNode(postThumb))) { continue } if (!(post = Get.postFromNode(postThumb))) { continue }
for (const file of post.files) { for (const file of post.files) {
if (file.thumb) { if (file.thumb) {
@ -242,7 +242,7 @@ const Gallery = {
if (Conf['Sauce'] && Sauce.links && (post = g.posts.get(file.dataset.post))) { if (Conf['Sauce'] && Sauce.links && (post = g.posts.get(file.dataset.post))) {
const sauces = [] const sauces = []
for (const link of Sauce.links) { for (const link of Sauce.links) {
var node let node
if (node = Sauce.createSauceLink(link, post, post.files[+file.dataset.file])) { if (node = Sauce.createSauceLink(link, post, post.files[+file.dataset.file])) {
sauces.push($.tn(' '), node) sauces.push($.tn(' '), node)
} }

View File

@ -24,7 +24,7 @@ const Metadata = {
for (let i = 0; i < this.files.length; i++) { for (let i = 0; i < this.files.length; i++) {
const file = this.files[i] const file = this.files[i]
if (/webm$/i.test(file.url)) { if (/webm$/i.test(file.url)) {
var el let el
if (this.isClone) { if (this.isClone) {
el = $('.webm-title', file.text) el = $('.webm-title', file.text)
@ -77,7 +77,7 @@ const Metadata = {
return n return n
} }
var i = 0 let i = 0
while (i < data.length) { while (i < data.length) {
const element = readInt() const element = readInt()
let size = readInt() let size = readInt()

View File

@ -21,7 +21,7 @@ const Sauce = {
const links = [] const links = []
for (link of Conf['sauces'].split('\n')) { for (link of Conf['sauces'].split('\n')) {
var linkData let linkData
if ((link[0] !== '#') && (linkData = this.parseLink(link))) { if ((link[0] !== '#') && (linkData = this.parseLink(link))) {
links.push(linkData) links.push(linkData)
} }
@ -90,7 +90,7 @@ const Sauce = {
if (!!parts['regexp'] && (!(matches = file.name.match(parts['regexp'])))) { return null } if (!!parts['regexp'] && (!(matches = file.name.match(parts['regexp'])))) { return null }
const missing = [] const missing = []
for (var key of ['url', 'text']) { for (const key of ['url', 'text']) {
parts[key] = parts[key].replace(/%(T?URL|IMG|[sh]?MD5|board|name|%|semi|\$\d+)/g, function (orig, parameter) { parts[key] = parts[key].replace(/%(T?URL|IMG|[sh]?MD5|board|name|%|semi|\$\d+)/g, function (orig, parameter) {
let type let type
if (parameter[0] === '$') { if (parameter[0] === '$') {
@ -147,10 +147,10 @@ const Sauce = {
$.add(file.text, nodes) $.add(file.text, nodes)
if (skipped.length) { if (skipped.length) {
var observer = new MutationObserver(function () { const observer = new MutationObserver(function () {
if (file.text.dataset.md5) { if (file.text.dataset.md5) {
for ([link, node] of skipped) { for ([link, node] of skipped) {
var node2 let node2
if (node2 = Sauce.createSauceLink(link, post, file)) { if (node2 = Sauce.createSauceLink(link, post, file)) {
$.replace(node, node2) $.replace(node, node2)
} }

View File

@ -64,7 +64,7 @@ const Embedding = {
i = 0 i = 0
items = $$('.linkify', post.nodes.comment) items = $$('.linkify', post.nodes.comment)
while ((el = items[i++])) { while ((el = items[i++])) {
var data let data
if (data = Embedding.services(el)) { if (data = Embedding.services(el)) {
Embedding.preview(data) Embedding.preview(data)
} }
@ -88,7 +88,7 @@ const Embedding = {
services(link) { services(link) {
const { href } = link const { href } = link
for (const type of Embedding.ordered_types) { for (const type of Embedding.ordered_types) {
var match let match
if (match = type.regExp.exec(href)) { if (match = type.regExp.exec(href)) {
return { key: type.key, uid: match[1], options: match[2], link } return { key: type.key, uid: match[1], options: match[2], link }
} }
@ -482,9 +482,9 @@ const Embedding = {
default: return ['.webm', '.mp4'] default: return ['.webm', '.mp4']
} }
})() })()
for (var name of names.split(',')) { for (const name of names.split(',')) {
for (var type of types) { for (const type of types) {
var base = `${name}${type}` const base = `${name}${type}`
const urls = (() => { const urls = (() => {
switch (host) { switch (host) {
// list from src/common.py at http://loopvid.appspot.com/source.html // list from src/common.py at http://loopvid.appspot.com/source.html
@ -621,7 +621,7 @@ const Embedding = {
if ($.engine === 'gecko') { if ($.engine === 'gecko') {
// XXX https://bugzilla.mozilla.org/show_bug.cgi?id=680823 // XXX https://bugzilla.mozilla.org/show_bug.cgi?id=680823
el.style.cssText = 'border: none; width: 100%; height: 100%;' el.style.cssText = 'border: none; width: 100%; height: 100%;'
var cont = $.el('div') const cont = $.el('div')
$.add(cont, el) $.add(cont, el)
return cont return cont
} else { } else {

View File

@ -52,7 +52,7 @@ const Linkify = {
let i = 0 let i = 0
const links = [] const links = []
while ((node = snapshot.snapshotItem(i++))) { while ((node = snapshot.snapshotItem(i++))) {
var result let result
let { data } = node let { data } = node
if (!data || (node.parentElement.nodeName === "A")) { continue } if (!data || (node.parentElement.nodeName === "A")) { continue }
@ -62,13 +62,13 @@ const Linkify = {
let word = result[0] let word = result[0]
// End of node, not necessarily end of space-delimited string // End of node, not necessarily end of space-delimited string
if ((length = index + word.length) === data.length) { if ((length = index + word.length) === data.length) {
var saved let saved
test.lastIndex = 0 test.lastIndex = 0
while (saved = snapshot.snapshotItem(i++)) { while (saved = snapshot.snapshotItem(i++)) {
var end let end
if ((saved.nodeName === 'BR') || ((saved.parentElement.nodeName === 'P') && !saved.previousSibling)) { if ((saved.nodeName === 'BR') || ((saved.parentElement.nodeName === 'P') && !saved.previousSibling)) {
var part1, part2 let part1, part2
if ( if (
// link deliberately split // link deliberately split
(part1 = word.match(/(https?:\/\/)?([a-z\d-]+\.)*[a-z\d-]+$/i)) && (part1 = word.match(/(https?:\/\/)?([a-z\d-]+\.)*[a-z\d-]+$/i)) &&

View File

@ -29,7 +29,7 @@ const CatalogLinks = {
})() })()
$.ready(function () { $.ready(function () {
for (const link of $$(selector)) { for (const link of $$(selector)) {
var catalogURL let catalogURL
switch (link.pathname.replace(/\/+/g, '/')) { switch (link.pathname.replace(/\/+/g, '/')) {
case `/${g.BOARD}/`: case `/${g.BOARD}/`:
if (Conf['JSON Index']) { link.textContent = 'Index' } if (Conf['JSON Index']) { link.textContent = 'Index' }
@ -73,7 +73,7 @@ const CatalogLinks = {
node() { node() {
for (const a of $$('a', this.nodes.comment)) { for (const a of $$('a', this.nodes.comment)) {
var m let m
if (m = a.href.match(/^https?:\/\/(boards\.4chan(?:nel)?\.org\/[^\/]+)\/catalog(#s=.*)?/)) { if (m = a.href.match(/^https?:\/\/(boards\.4chan(?:nel)?\.org\/[^\/]+)\/catalog(#s=.*)?/)) {
a.href = `//${m[1]}/${m[2] || '#catalog'}` a.href = `//${m[1]}/${m[2] || '#catalog'}`
} }
@ -104,7 +104,7 @@ const CatalogLinks = {
for (const a of $$('a:not([data-only])', list)) { for (const a of $$('a:not([data-only])', list)) {
let { siteID, boardID } = a.dataset let { siteID, boardID } = a.dataset
if (!siteID || !boardID) { if (!siteID || !boardID) {
var VIEW; let VIEW;
({ siteID, boardID, VIEW } = Site.parseURL(a)) ({ siteID, boardID, VIEW } = Site.parseURL(a))
if ( if (
!siteID || !boardID || !siteID || !boardID ||

View File

@ -1,6 +1,6 @@
import Callbacks from "../classes/Callbacks" import Callbacks from "../classes/Callbacks"
import Get from "../General/Get" import Get from "../General/Get"
import { Conf,g } from "../globals/globals" import { Conf, g } from "../globals/globals"
import $ from "../platform/$" import $ from "../platform/$"
import $$ from "../platform/$$" import $$ from "../platform/$$"
@ -9,13 +9,13 @@ import $$ from "../platform/$$"
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
var ExpandComment = { const ExpandComment = {
init() { init() {
if ((g.VIEW !== 'index') || !Conf['Comment Expansion'] || Conf['JSON Index']) { return } if ((g.VIEW !== 'index') || !Conf['Comment Expansion'] || Conf['JSON Index']) { return }
return Callbacks.Post.push({ return Callbacks.Post.push({
name: 'Comment Expansion', name: 'Comment Expansion',
cb: this.node cb: this.node
}) })
}, },
@ -42,7 +42,7 @@ var ExpandComment = {
} }
if (!(a = $('.abbr > a', post.nodes.comment))) { return } if (!(a = $('.abbr > a', post.nodes.comment))) { return }
a.textContent = `Post No.${post} Loading...` a.textContent = `Post No.${post} Loading...`
return $.cache(g.SITE.urls.threadJSON({boardID: post.boardID, threadID: post.threadID}), function() { return ExpandComment.parse(this, a, post) }) return $.cache(g.SITE.urls.threadJSON({ boardID: post.boardID, threadID: post.threadID }), function () { return ExpandComment.parse(this, a, post) })
}, },
contract(post) { contract(post) {
@ -55,7 +55,7 @@ var ExpandComment = {
parse(req, a, post) { parse(req, a, post) {
let postObj, spoilerRange let postObj, spoilerRange
const {status} = req const { status } = req
if (![200, 304].includes(status)) { if (![200, 304].includes(status)) {
a.textContent = status ? `Error ${req.statusText} (${status})` : 'Connection Error' a.textContent = status ? `Error ${req.statusText} (${status})` : 'Connection Error'
return return
@ -76,7 +76,7 @@ var ExpandComment = {
return return
} }
const {comment} = post.nodes const { comment } = post.nodes
const clone = comment.cloneNode(false) const clone = comment.cloneNode(false)
clone.innerHTML = postObj.com clone.innerHTML = postObj.com
// Fix pathnames // Fix pathnames
@ -84,9 +84,9 @@ var ExpandComment = {
const href = quote.getAttribute('href') const href = quote.getAttribute('href')
if (href[0] === '/') { continue } // Cross-board quote, or board link if (href[0] === '/') { continue } // Cross-board quote, or board link
if (href[0] === '#') { if (href[0] === '#') {
quote.href = `${a.pathname.split(/\/+/).splice(0,4).join('/')}${href}` quote.href = `${a.pathname.split(/\/+/).splice(0, 4).join('/')}${href}`
} else { } else {
quote.href = `${a.pathname.split(/\/+/).splice(0,3).join('/')}/${href}` quote.href = `${a.pathname.split(/\/+/).splice(0, 3).join('/')}/${href}`
} }
} }
post.nodes.shortComment = comment post.nodes.shortComment = comment

View File

@ -39,7 +39,7 @@ const ExpandThread = {
disconnect(refresh) { disconnect(refresh) {
if ((g.VIEW === 'thread') || !Conf['Thread Expansion']) { return } if ((g.VIEW === 'thread') || !Conf['Thread Expansion']) { return }
for (const threadID in ExpandThread.statuses) { for (const threadID in ExpandThread.statuses) {
var oldReq let oldReq
const status = ExpandThread.statuses[threadID] const status = ExpandThread.statuses[threadID]
if (oldReq = status.req) { if (oldReq = status.req) {
delete status.req delete status.req
@ -112,7 +112,7 @@ const ExpandThread = {
for (const reply of replies) { for (const reply of replies) {
// rm clones // rm clones
if (Conf['Quote Inlining']) { if (Conf['Quote Inlining']) {
var inlined let inlined
while ((inlined = $('.inlined', reply))) { inlined.click() } while ((inlined = $('.inlined', reply))) { inlined.click() }
} }
postsCount++ postsCount++
@ -139,7 +139,7 @@ const ExpandThread = {
const postsRoot = [] const postsRoot = []
let filesCount = 0 let filesCount = 0
for (const postData of req.response.posts) { for (const postData of req.response.posts) {
var post let post
if (postData.no === thread.ID) { continue } if (postData.no === thread.ID) { continue }
if ((post = thread.posts.get(postData.no)) && !post.isFetchedQuote) { if ((post = thread.posts.get(postData.no)) && !post.isFetchedQuote) {
if ('file' in post) { filesCount++ } if ('file' in post) { filesCount++ }

View File

@ -182,7 +182,7 @@ const Keybinds = {
// Images // Images
case Conf['Expand image']: case Conf['Expand image']:
if (!ImageExpand.enabled || !threadRoot) { return } if (!ImageExpand.enabled || !threadRoot) { return }
var post = Get.postFromNode(Keybinds.post(threadRoot)) let post = Get.postFromNode(Keybinds.post(threadRoot))
if (post.file) { ImageExpand.toggle(post) } if (post.file) { ImageExpand.toggle(post) }
break break
case Conf['Expand images']: case Conf['Expand images']:
@ -232,7 +232,7 @@ const Keybinds = {
break break
case Conf['Search form']: case Conf['Search form']:
if (g.VIEW !== 'index') { return } if (g.VIEW !== 'index') { return }
var searchInput = Index.enabled ? const searchInput = Index.enabled ?
Index.searchInput Index.searchInput
: g.SITE.selectors.searchBox ? : g.SITE.selectors.searchBox ?
$(g.SITE.selectors.searchBox) $(g.SITE.selectors.searchBox)

View File

@ -24,7 +24,7 @@ const MarkNewIPs = {
switch (ipCount - MarkNewIPs.ipCount) { switch (ipCount - MarkNewIPs.ipCount) {
case (postCount - MarkNewIPs.postCount) + deletedPosts.length: case (postCount - MarkNewIPs.postCount) + deletedPosts.length:
var i = MarkNewIPs.ipCount let i = MarkNewIPs.ipCount
for (fullID of newPosts) { for (fullID of newPosts) {
MarkNewIPs.markNew(g.posts.get(fullID), ++i) MarkNewIPs.markNew(g.posts.get(fullID), ++i)
} }

View File

@ -247,7 +247,7 @@ const ThreadWatcher = {
const siteID = g.SITE.ID const siteID = g.SITE.ID
const boardID = g.BOARD.ID const boardID = g.BOARD.ID
let nKilled = 0 let nKilled = 0
for (var threadID in db.data[siteID].boards[boardID]) { for (const threadID in db.data[siteID].boards[boardID]) {
// Don't prune threads that have yet to appear in index. // Don't prune threads that have yet to appear in index.
const data = db.data[siteID].boards[boardID][threadID] const data = db.data[siteID].boards[boardID][threadID]
if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) { if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) {
@ -446,7 +446,7 @@ const ThreadWatcher = {
for (thread of board) { for (thread of board) {
const { threadID, data } = thread const { threadID, data } = thread
if (threads[threadID]) { if (threads[threadID]) {
var index, modified, replies; let index, modified, replies;
({ page, index, modified, replies } = threads[threadID]) ({ page, index, modified, replies } = threads[threadID])
if (Conf['Show Page']) { if (Conf['Show Page']) {
const lastPage = g.sites[siteID].isPrunedByAge?.({ siteID, boardID }) ? const lastPage = g.sites[siteID].isPrunedByAge?.({ siteID, boardID }) ?
@ -505,7 +505,7 @@ const ThreadWatcher = {
if (!Conf['Require OP Quote Link'] && youOP) { if (!Conf['Require OP Quote Link'] && youOP) {
quotesYou = true quotesYou = true
} else if (QuoteYou.db && postObj.com) { } else if (QuoteYou.db && postObj.com) {
var match let match
const regexp = site.regexp.quotelinkHTML const regexp = site.regexp.quotelinkHTML
regexp.lastIndex = 0 regexp.lastIndex = 0
while (match = regexp.exec(postObj.com)) { while (match = regexp.exec(postObj.com)) {
@ -550,7 +550,7 @@ const ThreadWatcher = {
for (const siteID in ThreadWatcher.db.data) { for (const siteID in ThreadWatcher.db.data) {
const boards = ThreadWatcher.db.data[siteID] const boards = ThreadWatcher.db.data[siteID]
for (const boardID in boards.boards) { for (const boardID in boards.boards) {
var cont let cont
const threads = boards.boards[boardID] const threads = boards.boards[boardID]
if (Conf['Current Board'] && ((siteID !== g.SITE.ID) || (boardID !== g.BOARD.ID))) { if (Conf['Current Board'] && ((siteID !== g.SITE.ID) || (boardID !== g.BOARD.ID))) {
continue continue
@ -664,7 +664,7 @@ const ThreadWatcher = {
ThreadWatcher.setPrefixes(threads) ThreadWatcher.setPrefixes(threads)
for (const { siteID, boardID, threadID, data } of threads) { for (const { siteID, boardID, threadID, data } of threads) {
// Add missing excerpt for threads added by Auto Watch // Add missing excerpt for threads added by Auto Watch
var thread let thread
if ((data.excerpt == null) && (siteID === g.SITE.ID) && (thread = g.threads.get(`${boardID}.${threadID}`)) && thread.OP) { if ((data.excerpt == null) && (siteID === g.SITE.ID) && (thread = g.threads.get(`${boardID}.${threadID}`)) && thread.OP) {
ThreadWatcher.db.extend({ boardID, threadID, val: { excerpt: Get.threadExcerpt(thread) } }) ThreadWatcher.db.extend({ boardID, threadID, val: { excerpt: Get.threadExcerpt(thread) } })
} }
@ -684,7 +684,7 @@ const ThreadWatcher = {
const isWatched = ThreadWatcher.isWatched(thread) const isWatched = ThreadWatcher.isWatched(thread)
if (thread.OP) { if (thread.OP) {
for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) { for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) {
var toggler let toggler
if (toggler = $('.watch-thread-link', post.nodes.info)) { if (toggler = $('.watch-thread-link', post.nodes.info)) {
ThreadWatcher.setToggler(toggler, isWatched) ThreadWatcher.setToggler(toggler, isWatched)
} }

View File

@ -318,7 +318,7 @@ const Captcha = {
afterSetup(mutations) { afterSetup(mutations) {
for (const mutation of mutations) { for (const mutation of mutations) {
for (const node of mutation.addedNodes) { for (const node of mutation.addedNodes) {
var iframe, textarea let iframe, textarea
if (iframe = $.x('./descendant-or-self::iframe[starts-with(@src, "https://www.google.com/recaptcha/")]', node)) { this.setupIFrame(iframe) } if (iframe = $.x('./descendant-or-self::iframe[starts-with(@src, "https://www.google.com/recaptcha/")]', node)) { this.setupIFrame(iframe) }
if (textarea = $.x('./descendant-or-self::textarea', node)) { this.setupTextArea(textarea) } if (textarea = $.x('./descendant-or-self::textarea', node)) { this.setupTextArea(textarea) }
} }

View File

@ -80,7 +80,7 @@ const QR = {
captcha: null, captcha: null,
postingIsEnabled: false, postingIsEnabled: false,
nodes: null, nodes: null,
posts: null, posts: 0,
shortcut: null, shortcut: null,
link: '', link: '',
min_width: 0, min_width: 0,
@ -1480,7 +1480,7 @@ const QR = {
if (window.Tegaki) { if (window.Tegaki) {
return document.querySelector('#qr .oekaki').hidden = false return document.querySelector('#qr .oekaki').hidden = false
} }
}) }, 'oekaki')
}, },
load(cb) { load(cb) {
@ -1529,7 +1529,7 @@ const QR = {
height: getHeight(), height: getHeight(),
bgColor: getBgColor(), bgColor: getBgColor(),
}) })
}) }, 'oekaki')
}, },
button() { button() {
@ -1587,18 +1587,21 @@ const QR = {
} else { } else {
return cb(E) return cb(E)
} }
})) }, 0))
}, },
toggle() { toggle() {
return QR.oekaki.load(() => QR.nodes.oekaki.hidden = !QR.nodes.oekaki.hidden) return QR.oekaki.load(() => QR.nodes.oekaki.hidden = !QR.nodes.oekaki.hidden)
} }
}, },
email: null, email: {
},
sub: {
},
persona: { persona: {
pwd: '', pwd: '',
always: false, always: [],
types: { types: {
name: [""], name: [""],
email: [""], email: [""],
@ -1689,7 +1692,6 @@ const QR = {
com: string com: string
spoiler: boolean spoiler: boolean
name: string name: string
email: string
fileUrl: string fileUrl: string
fileThumb: string fileThumb: string
nodes: { el: HTMLElement; rm: HTMLElement; spoiler: HTMLInputElement; span: HTMLElement } nodes: { el: HTMLElement; rm: HTMLElement; spoiler: HTMLInputElement; span: HTMLElement }
@ -1752,12 +1754,12 @@ const QR = {
: :
persona.name persona.name
this.email = 'email' in QR.persona.always ? QR.email = 'email' in QR.persona.always ?
QR.persona.always.email QR.persona.always.email
: :
'' ''
this.sub = 'sub' in QR.persona.always ? QR.sub = 'sub' in QR.persona.always ?
QR.persona.always.sub QR.persona.always.sub
: :
'' ''

View File

@ -49,7 +49,7 @@ const QuoteBacklink = {
) )
if (markYours) { $.add(a, QuoteYou.mark.cloneNode(true)) } if (markYours) { $.add(a, QuoteYou.mark.cloneNode(true)) }
for (const quote of this.quotes) { for (const quote of this.quotes) {
var post let post
const containers = [QuoteBacklink.getContainer(quote)] const containers = [QuoteBacklink.getContainer(quote)]
if ((post = g.posts.get(quote)) && post.nodes.backlinkContainer) { if ((post = g.posts.get(quote)) && post.nodes.backlinkContainer) {
// Don't add OP clones when OP Backlinks is disabled, // Don't add OP clones when OP Backlinks is disabled,

View File

@ -87,7 +87,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: any let 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)
} }

View File

@ -37,8 +37,8 @@ const handlers = {
xhr.responseType = request.responseType; xhr.responseType = request.responseType;
xhr.timeout = request.timeout; xhr.timeout = request.timeout;
const object = request.headers || {}; const object = request.headers || {};
for (var key in object) { for (let key in object) {
var value = object[key]; let value = object[key];
xhr.setRequestHeader(key, value); xhr.setRequestHeader(key, value);
} }
xhr.addEventListener('load', function () { xhr.addEventListener('load', function () {

View File

@ -29,7 +29,7 @@ export default async function generateMetadata(packageJson, channel) {
output += (function () { output += (function () {
function expand(items, regex, substitutions) { function expand(items, regex, substitutions) {
var results = []; let results = [];
items.forEach(function (item) { items.forEach(function (item) {
if (regex.test(item)) { if (regex.test(item)) {
substitutions.forEach(function (s) { substitutions.forEach(function (s) {

View File

@ -848,7 +848,7 @@ if (platform === 'crx') {
$.on($.syncChannel, 'message', e => (() => { $.on($.syncChannel, 'message', e => (() => {
const result = [] const result = []
for (const key in e.data) { for (const key in e.data) {
var cb let cb
const val = e.data[key] const val = e.data[key]
if (cb = $.syncing[key]) { if (cb = $.syncing[key]) {
result.push(cb(dict.json(JSON.stringify(val)), key)) result.push(cb(dict.json(JSON.stringify(val)), key))

View File

@ -42,7 +42,7 @@ const CrossOrigin = {
return cb(null) return cb(null)
} }
} }
}) }, cb)
} }
if ((typeof window.GM_xmlhttpRequest === 'undefined' || window.GM_xmlhttpRequest === null)) { if ((typeof window.GM_xmlhttpRequest === 'undefined' || window.GM_xmlhttpRequest === null)) {
fallback() fallback()
@ -109,6 +109,11 @@ const CrossOrigin = {
Request: (function () { Request: (function () {
const Request = class Request { const Request = class Request {
statusText: string
response: any
status: number
responseHeaderString: string
responseHeaders: any
static initClass() { static initClass() {
this.prototype.status = 0 this.prototype.status = 0
this.prototype.statusText = '' this.prototype.statusText = ''
@ -119,7 +124,7 @@ const CrossOrigin = {
if ((this.responseHeaders == null) && (this.responseHeaderString != null)) { if ((this.responseHeaders == null) && (this.responseHeaderString != null)) {
this.responseHeaders = dict() this.responseHeaders = dict()
for (const header of this.responseHeaderString.split('\r\n')) { for (const header of this.responseHeaderString.split('\r\n')) {
var i let i
if ((i = header.indexOf(':')) >= 0) { if ((i = header.indexOf(':')) >= 0) {
const key = header.slice(0, i).trim().toLowerCase() const key = header.slice(0, i).trim().toLowerCase()
const val = header.slice(i + 1).trim() const val = header.slice(i + 1).trim()
@ -193,7 +198,12 @@ const CrossOrigin = {
try { try {
gmReq = (GM?.xmlHttpRequest || GM_xmlhttpRequest)(gmOptions) gmReq = (GM?.xmlHttpRequest || GM_xmlhttpRequest)(gmOptions)
} catch (error) { } catch (error) {
return $.ajax(url, options) return $.ajax(url, options, function (result) {
if (result.status) {
$.extend(req, result)
}
return req.onloadend()
})
} }
if (gmReq && (typeof gmReq.abort === 'function')) { if (gmReq && (typeof gmReq.abort === 'function')) {

View File

@ -89,15 +89,7 @@ const SWTinyboard = {
return Main.mounted(true) return Main.mounted(true)
}, },
awaitBoard(cb) { awaitBoard(cb) {
let reactUI return Main.mounted(true).then(cb)
if (reactUI = $.id('react-ui')) {
const s = (this.selectors = Object.create(this.selectors))
s.boardFor = { index: '.page-container' }
s.thread = 'div[id^="thread_"]'
return Main.mounted(cb)
} else {
return cb()
}
}, },
urls: { urls: {

View File

@ -131,7 +131,7 @@ const SWYotsuba = {
$\ $\
`), `),
quotelinkHTML: quotelinkHTML:
/<a [^>]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^\/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g, /<a [^>]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g,
pass: pass:
/^https?:\/\/www\.4chan(?:nel)?\.org\/+pass(?:$|[?#])/, /^https?:\/\/www\.4chan(?:nel)?\.org\/+pass(?:$|[?#])/,
captcha: captcha:

View File

@ -72,7 +72,7 @@ const Site = {
set(hostname) { set(hostname) {
for (const ID in Conf['siteProperties']) { for (const ID in Conf['siteProperties']) {
var site let site
const properties = Conf['siteProperties'][ID] const properties = Conf['siteProperties'][ID]
if (properties.canonical) { continue } if (properties.canonical) { continue }
const { const {