From 5a34fa143578fb26d352e59903dc3d7e6d3f6643 Mon Sep 17 00:00:00 2001 From: Lalle <29478339+LalleSX@users.noreply.github.com> Date: Fri, 5 May 2023 14:42:32 +0200 Subject: [PATCH] var to let and const --- .eslintignore | 4 ++++ .eslintrc | 2 +- src/Archive/Redirect.ts | 6 +++--- src/Filtering/Filter.ts | 2 +- src/Filtering/Recursive.ts | 2 +- src/General/Get.ts | 2 +- src/General/Index.ts | 18 ++++++++-------- src/General/Settings.tsx | 2 +- src/General/Test.ts | 34 +++++++++++++++++------------- src/Images/Gallery.ts | 4 ++-- src/Images/Metadata.ts | 4 ++-- src/Images/Sauce.ts | 8 +++---- src/Linkification/Embedding.ts | 12 +++++------ src/Linkification/Linkify.ts | 8 +++---- src/Miscellaneous/CatalogLinks.ts | 6 +++--- src/Miscellaneous/ExpandComment.ts | 16 +++++++------- src/Miscellaneous/ExpandThread.ts | 6 +++--- src/Miscellaneous/Keybinds.ts | 4 ++-- src/Monitoring/MarkNewIPs.ts | 2 +- src/Monitoring/ThreadWatcher.ts | 12 +++++------ src/Posting/Captcha.ts | 2 +- src/Posting/QR.ts | 20 ++++++++++-------- src/Quotelinks/QuoteBacklink.ts | 2 +- src/classes/Post.ts | 2 +- src/meta/eventPage.ts | 4 ++-- src/meta/metadata.js | 2 +- src/platform/$.ts | 2 +- src/platform/CrossOrigin.ts | 16 +++++++++++--- src/site/SW.tinyboard.ts | 10 +-------- src/site/SW.yotsuba.tsx | 2 +- src/site/Site.ts | 2 +- 31 files changed, 115 insertions(+), 103 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..9773f1c --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +tools/* +dist/* +src/meta/* +src/types/* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index f162e86..321ab29 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ }, "env": { "browser": true, - "es2021": true, + "es2020": true, "node": true }, "plugins": [ diff --git a/src/Archive/Redirect.ts b/src/Archive/Redirect.ts index 3e1e69e..09c03b2 100644 --- a/src/Archive/Redirect.ts +++ b/src/Archive/Redirect.ts @@ -31,7 +31,7 @@ const Redirect = { const archives = dict() for (data of Conf['archives']) { - var name, software, uid + let name, software, uid for (const key of ['boards', 'files']) { if (!(data[key] instanceof Array)) { data[key] = [] } } @@ -48,7 +48,7 @@ const Redirect = { for (boardID in Conf['selectedArchives']) { const record = Conf['selectedArchives'][boardID] for (const type in record) { - var archive + let archive const id = record[type] if ((archive = archives[JSON.stringify(id)]) && $.hasOwn(o, type)) { boards = type === 'file' ? archive.files : archive.boards @@ -89,7 +89,7 @@ const Redirect = { for (let i = 0; i < urls.length; i++) { url = urls[i] if (['[', '{'].includes(url[0])) { - var response + let response try { response = JSON.parse(url) } catch (err) { diff --git a/src/Filtering/Filter.ts b/src/Filtering/Filter.ts index 4f50680..470d7d0 100644 --- a/src/Filtering/Filter.ts +++ b/src/Filtering/Filter.ts @@ -69,7 +69,7 @@ const Filter = { } // 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. const boards = this.parseBoards(filter.match(/(?:^|;)\s*boards:([^;]+)/)?.[1]) diff --git a/src/Filtering/Recursive.ts b/src/Filtering/Recursive.ts index 23bcecf..6bbcc50 100644 --- a/src/Filtering/Recursive.ts +++ b/src/Filtering/Recursive.ts @@ -21,7 +21,7 @@ const Recursive = { node() { if (this.isClone || this.isFetchedQuote) { return } for (const quote of this.quotes) { - var obj + let obj if ((obj = Recursive.recursives[quote])) { for (let i = 0; i < obj.recursives.length; i++) { const recursive = obj.recursives[i] diff --git a/src/General/Get.ts b/src/General/Get.ts index a528558..ad32061 100644 --- a/src/General/Get.ts +++ b/src/General/Get.ts @@ -80,7 +80,7 @@ const Get = { // get all of their backlinks. if (Conf['Quote Backlinks']) { for (const quote of post.quotes) { - var qPost + let qPost if ((qPost = posts.get(quote))) { handleQuotes(qPost, 'backlinks') } } } diff --git a/src/General/Index.ts b/src/General/Index.ts index af0c07e..bd0fa80 100644 --- a/src/General/Index.ts +++ b/src/General/Index.ts @@ -612,7 +612,7 @@ const Index: Index = { const commands = hash.slice(1).split('/') const leftover = [] for (const command of commands) { - var mode, sort + let mode, sort if (mode = $.getOwn(Index.hashCommands.mode, command)) { state.mode = mode } else if (command === 'index') { @@ -929,7 +929,7 @@ const Index: Index = { Index.parsedThreads = dict() Index.replyData = dict() for (let i = 0; i < Index.liveThreadData.length; i++) { - var obj, results + let obj, results const data = Index.liveThreadData[i] Index.liveThreadDict[data.no] = data Index.threadPosition[data.no] = i @@ -972,9 +972,9 @@ const Index: Index = { const newThreads = [] let newPosts = [] for (const ID of threadIDs) { - var opRoot, thread + let opRoot, thread try { - var OP + let OP const threadData = Index.liveThreadDict[ID] if (thread = g.BOARD.threads.get(ID)) { @@ -1040,11 +1040,11 @@ const Index: Index = { let errors const posts = [] for (const thread of threads) { - var lastReplies + let lastReplies if (!(lastReplies = Index.liveThreadDict[thread.ID].last_replies)) { continue } const nodes = [] for (const data of lastReplies) { - var node, post + let node, post if ((post = thread.posts.get(data.no)) && !post.isFetchedQuote) { nodes.push(post.nodes.root) continue @@ -1123,8 +1123,8 @@ const Index: Index = { Index.sortedThreadIDs = (() => { switch (sortType) { case 'lastreply': case 'lastlong': - var repliesAvailable = liveThreadData.some(thread => thread.last_replies?.length) - var lastlong = function (thread) { + const repliesAvailable = liveThreadData.some(thread => thread.last_replies?.length) + const lastlong = function (thread) { if (!repliesAvailable) { 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 } } - var lastlongD = dict() + const lastlongD = dict() for (const thread of liveThreadData) { lastlongD[thread.no] = lastlong(thread).no } diff --git a/src/General/Settings.tsx b/src/General/Settings.tsx index 7dcdc59..bb5d4f9 100644 --- a/src/General/Settings.tsx +++ b/src/General/Settings.tsx @@ -1031,7 +1031,7 @@ vp-replace for (boardID in Conf['selectedArchives']) { const data = Conf['selectedArchives'][boardID] for (const type in data) { - var select + let select const id = data[type] if (select = $(`select[data-boardid='${boardID}'][data-type='${type}']`, tbody)) { select.value = JSON.stringify(id) diff --git a/src/General/Test.ts b/src/General/Test.ts index 99420ba..a3657fb 100644 --- a/src/General/Test.ts +++ b/src/General/Test.ts @@ -10,7 +10,7 @@ import Notice from "../classes/Notice" import Post from "../classes/Post" import Config from "../config/Config" 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 Menu from "../Menu/Menu" import Keybinds from "../Miscellaneous/Keybinds" @@ -25,7 +25,7 @@ const Test = { if (Conf['Menu']) { const a = $.el('a', - {textContent: 'Test HTML building'}) + { textContent: 'Test HTML building' }) $.on(a, 'click', this.cb.testOne) Menu.menu.addEntry({ el: a, @@ -37,17 +37,19 @@ const Test = { } const a2 = $.el('a', - {textContent: 'Test HTML building'}) + { textContent: 'Test HTML building' }) $.on(a2, 'click', this.cb.testAll) Header.menu.addEntry({ - el: a2}) + el: a2 + }) if (Unread.posts) { const testOrderLink = $.el('a', - {textContent: 'Test Post Order'}) + { textContent: 'Test Post Order' }) $.on(testOrderLink, 'click', this.cb.testOrder) Header.menu.addEntry({ - el: testOrderLink}) + el: testOrderLink + }) } return $.on(d, 'keydown', this.cb.keydown) @@ -78,7 +80,7 @@ const Test = { el.src = el.src.replace(/(spoiler-\w+)\d(\.png)$/, '$11$2') } for (el of $$('pre.prettyprinted', root2)) { - var nodes = $.X('.//br|.//wbr|.//text()', el) + let nodes = $.X('.//br|.//wbr|.//text()', el) i = 0 nodes = ((() => { const result = [] @@ -125,9 +127,9 @@ const Test = { testOne(post) { 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 } - const {posts} = this.response + const { posts } = this.response g.SITE.Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler for (const postData of posts) { if (postData.no === post.ID) { @@ -136,7 +138,7 @@ const Test = { const root = g.SITE.Build.post(obj) const t2 = new Date().getTime() 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 const x = post.normalizedOriginal @@ -154,7 +156,7 @@ const Test = { for (const key in Config.filter) { if ((!key === 'General') && !((key === 'MD5') && (post.board.ID === 'f'))) { 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])) { fail = true c.log(`${post.fullID} has filter bug in ${key}`) @@ -177,7 +179,7 @@ const Test = { }, testAll() { - g.posts.forEach(function(post) { + g.posts.forEach(function (post) { if (!post.isClone && !post.isFetchedQuote) { let abbr if (!((abbr = $('.abbr', post.nodes.comment)) && /Comment too long\./.test(abbr.textContent))) { @@ -215,17 +217,19 @@ const Test = { let x const list1 = ((() => { const result = [] - for (x of Unread.order.order()) { result.push(x.ID) + for (x of Unread.order.order()) { + result.push(x.ID) } return result })()) const list2 = ((() => { 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 })()) - const pass = (function() { + const pass = (function () { if (list1.length !== list2.length) { return false } for (let i = 0, end = list1.length; i < end; i++) { if (list1[i] !== list2[i]) { return false } diff --git a/src/Images/Gallery.ts b/src/Images/Gallery.ts index a1fbd7b..466fcd9 100644 --- a/src/Images/Gallery.ts +++ b/src/Images/Gallery.ts @@ -127,7 +127,7 @@ const Gallery = { $.on(window, 'resize', Gallery.cb.setHeight) for (const postThumb of $$(g.SITE.selectors.file.thumb)) { - var post + let post if (!(post = Get.postFromNode(postThumb))) { continue } for (const file of post.files) { if (file.thumb) { @@ -242,7 +242,7 @@ const Gallery = { if (Conf['Sauce'] && Sauce.links && (post = g.posts.get(file.dataset.post))) { const sauces = [] for (const link of Sauce.links) { - var node + let node if (node = Sauce.createSauceLink(link, post, post.files[+file.dataset.file])) { sauces.push($.tn(' '), node) } diff --git a/src/Images/Metadata.ts b/src/Images/Metadata.ts index b721877..1563ae9 100644 --- a/src/Images/Metadata.ts +++ b/src/Images/Metadata.ts @@ -24,7 +24,7 @@ const Metadata = { for (let i = 0; i < this.files.length; i++) { const file = this.files[i] if (/webm$/i.test(file.url)) { - var el + let el if (this.isClone) { el = $('.webm-title', file.text) @@ -77,7 +77,7 @@ const Metadata = { return n } - var i = 0 + let i = 0 while (i < data.length) { const element = readInt() let size = readInt() diff --git a/src/Images/Sauce.ts b/src/Images/Sauce.ts index e709dde..9b431f2 100644 --- a/src/Images/Sauce.ts +++ b/src/Images/Sauce.ts @@ -21,7 +21,7 @@ const Sauce = { const links = [] for (link of Conf['sauces'].split('\n')) { - var linkData + let linkData if ((link[0] !== '#') && (linkData = this.parseLink(link))) { links.push(linkData) } @@ -90,7 +90,7 @@ const Sauce = { if (!!parts['regexp'] && (!(matches = file.name.match(parts['regexp'])))) { return null } 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) { let type if (parameter[0] === '$') { @@ -147,10 +147,10 @@ const Sauce = { $.add(file.text, nodes) if (skipped.length) { - var observer = new MutationObserver(function () { + const observer = new MutationObserver(function () { if (file.text.dataset.md5) { for ([link, node] of skipped) { - var node2 + let node2 if (node2 = Sauce.createSauceLink(link, post, file)) { $.replace(node, node2) } diff --git a/src/Linkification/Embedding.ts b/src/Linkification/Embedding.ts index 2ec1166..b0f791e 100644 --- a/src/Linkification/Embedding.ts +++ b/src/Linkification/Embedding.ts @@ -64,7 +64,7 @@ const Embedding = { i = 0 items = $$('.linkify', post.nodes.comment) while ((el = items[i++])) { - var data + let data if (data = Embedding.services(el)) { Embedding.preview(data) } @@ -88,7 +88,7 @@ const Embedding = { services(link) { const { href } = link for (const type of Embedding.ordered_types) { - var match + let match if (match = type.regExp.exec(href)) { return { key: type.key, uid: match[1], options: match[2], link } } @@ -482,9 +482,9 @@ const Embedding = { default: return ['.webm', '.mp4'] } })() - for (var name of names.split(',')) { - for (var type of types) { - var base = `${name}${type}` + for (const name of names.split(',')) { + for (const type of types) { + const base = `${name}${type}` const urls = (() => { switch (host) { // list from src/common.py at http://loopvid.appspot.com/source.html @@ -621,7 +621,7 @@ const Embedding = { if ($.engine === 'gecko') { // XXX https://bugzilla.mozilla.org/show_bug.cgi?id=680823 el.style.cssText = 'border: none; width: 100%; height: 100%;' - var cont = $.el('div') + const cont = $.el('div') $.add(cont, el) return cont } else { diff --git a/src/Linkification/Linkify.ts b/src/Linkification/Linkify.ts index c7e8a7e..3849d6d 100644 --- a/src/Linkification/Linkify.ts +++ b/src/Linkification/Linkify.ts @@ -52,7 +52,7 @@ const Linkify = { let i = 0 const links = [] while ((node = snapshot.snapshotItem(i++))) { - var result + let result let { data } = node if (!data || (node.parentElement.nodeName === "A")) { continue } @@ -62,13 +62,13 @@ const Linkify = { let word = result[0] // End of node, not necessarily end of space-delimited string if ((length = index + word.length) === data.length) { - var saved + let saved test.lastIndex = 0 while (saved = snapshot.snapshotItem(i++)) { - var end + let end if ((saved.nodeName === 'BR') || ((saved.parentElement.nodeName === 'P') && !saved.previousSibling)) { - var part1, part2 + let part1, part2 if ( // link deliberately split (part1 = word.match(/(https?:\/\/)?([a-z\d-]+\.)*[a-z\d-]+$/i)) && diff --git a/src/Miscellaneous/CatalogLinks.ts b/src/Miscellaneous/CatalogLinks.ts index 03c2b31..87fd67f 100644 --- a/src/Miscellaneous/CatalogLinks.ts +++ b/src/Miscellaneous/CatalogLinks.ts @@ -29,7 +29,7 @@ const CatalogLinks = { })() $.ready(function () { for (const link of $$(selector)) { - var catalogURL + let catalogURL switch (link.pathname.replace(/\/+/g, '/')) { case `/${g.BOARD}/`: if (Conf['JSON Index']) { link.textContent = 'Index' } @@ -73,7 +73,7 @@ const CatalogLinks = { node() { for (const a of $$('a', this.nodes.comment)) { - var m + let m if (m = a.href.match(/^https?:\/\/(boards\.4chan(?:nel)?\.org\/[^\/]+)\/catalog(#s=.*)?/)) { a.href = `//${m[1]}/${m[2] || '#catalog'}` } @@ -104,7 +104,7 @@ const CatalogLinks = { for (const a of $$('a:not([data-only])', list)) { let { siteID, boardID } = a.dataset if (!siteID || !boardID) { - var VIEW; + let VIEW; ({ siteID, boardID, VIEW } = Site.parseURL(a)) if ( !siteID || !boardID || diff --git a/src/Miscellaneous/ExpandComment.ts b/src/Miscellaneous/ExpandComment.ts index 7c10d6b..9a5e6f0 100644 --- a/src/Miscellaneous/ExpandComment.ts +++ b/src/Miscellaneous/ExpandComment.ts @@ -1,6 +1,6 @@ import Callbacks from "../classes/Callbacks" import Get from "../General/Get" -import { Conf,g } from "../globals/globals" +import { Conf, g } from "../globals/globals" import $ from "../platform/$" import $$ from "../platform/$$" @@ -9,13 +9,13 @@ import $$ from "../platform/$$" * DS102: Remove unnecessary code created because of implicit returns * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ -var ExpandComment = { +const ExpandComment = { init() { if ((g.VIEW !== 'index') || !Conf['Comment Expansion'] || Conf['JSON Index']) { return } return Callbacks.Post.push({ name: 'Comment Expansion', - cb: this.node + cb: this.node }) }, @@ -42,7 +42,7 @@ var ExpandComment = { } if (!(a = $('.abbr > a', post.nodes.comment))) { return } 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) { @@ -55,7 +55,7 @@ var ExpandComment = { parse(req, a, post) { let postObj, spoilerRange - const {status} = req + const { status } = req if (![200, 304].includes(status)) { a.textContent = status ? `Error ${req.statusText} (${status})` : 'Connection Error' return @@ -76,7 +76,7 @@ var ExpandComment = { return } - const {comment} = post.nodes + const { comment } = post.nodes const clone = comment.cloneNode(false) clone.innerHTML = postObj.com // Fix pathnames @@ -84,9 +84,9 @@ var ExpandComment = { const href = quote.getAttribute('href') if (href[0] === '/') { continue } // Cross-board quote, or board link if (href[0] === '#') { - quote.href = `${a.pathname.split(/\/+/).splice(0,4).join('/')}${href}` + quote.href = `${a.pathname.split(/\/+/).splice(0, 4).join('/')}${href}` } 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 diff --git a/src/Miscellaneous/ExpandThread.ts b/src/Miscellaneous/ExpandThread.ts index 9b84eef..e9afe6b 100644 --- a/src/Miscellaneous/ExpandThread.ts +++ b/src/Miscellaneous/ExpandThread.ts @@ -39,7 +39,7 @@ const ExpandThread = { disconnect(refresh) { if ((g.VIEW === 'thread') || !Conf['Thread Expansion']) { return } for (const threadID in ExpandThread.statuses) { - var oldReq + let oldReq const status = ExpandThread.statuses[threadID] if (oldReq = status.req) { delete status.req @@ -112,7 +112,7 @@ const ExpandThread = { for (const reply of replies) { // rm clones if (Conf['Quote Inlining']) { - var inlined + let inlined while ((inlined = $('.inlined', reply))) { inlined.click() } } postsCount++ @@ -139,7 +139,7 @@ const ExpandThread = { const postsRoot = [] let filesCount = 0 for (const postData of req.response.posts) { - var post + let post if (postData.no === thread.ID) { continue } if ((post = thread.posts.get(postData.no)) && !post.isFetchedQuote) { if ('file' in post) { filesCount++ } diff --git a/src/Miscellaneous/Keybinds.ts b/src/Miscellaneous/Keybinds.ts index fa54444..c02e46d 100644 --- a/src/Miscellaneous/Keybinds.ts +++ b/src/Miscellaneous/Keybinds.ts @@ -182,7 +182,7 @@ const Keybinds = { // Images case Conf['Expand image']: 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) } break case Conf['Expand images']: @@ -232,7 +232,7 @@ const Keybinds = { break case Conf['Search form']: if (g.VIEW !== 'index') { return } - var searchInput = Index.enabled ? + const searchInput = Index.enabled ? Index.searchInput : g.SITE.selectors.searchBox ? $(g.SITE.selectors.searchBox) diff --git a/src/Monitoring/MarkNewIPs.ts b/src/Monitoring/MarkNewIPs.ts index d8cd4c2..6244106 100644 --- a/src/Monitoring/MarkNewIPs.ts +++ b/src/Monitoring/MarkNewIPs.ts @@ -24,7 +24,7 @@ const MarkNewIPs = { switch (ipCount - MarkNewIPs.ipCount) { case (postCount - MarkNewIPs.postCount) + deletedPosts.length: - var i = MarkNewIPs.ipCount + let i = MarkNewIPs.ipCount for (fullID of newPosts) { MarkNewIPs.markNew(g.posts.get(fullID), ++i) } diff --git a/src/Monitoring/ThreadWatcher.ts b/src/Monitoring/ThreadWatcher.ts index 8440b4e..a908c5a 100644 --- a/src/Monitoring/ThreadWatcher.ts +++ b/src/Monitoring/ThreadWatcher.ts @@ -247,7 +247,7 @@ const ThreadWatcher = { const siteID = g.SITE.ID const boardID = g.BOARD.ID 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. const data = db.data[siteID].boards[boardID][threadID] if (!data?.isDead && !e.detail.threads.includes(`${boardID}.${threadID}`)) { @@ -446,7 +446,7 @@ const ThreadWatcher = { for (thread of board) { const { threadID, data } = thread if (threads[threadID]) { - var index, modified, replies; + let index, modified, replies; ({ page, index, modified, replies } = threads[threadID]) if (Conf['Show Page']) { const lastPage = g.sites[siteID].isPrunedByAge?.({ siteID, boardID }) ? @@ -505,7 +505,7 @@ const ThreadWatcher = { if (!Conf['Require OP Quote Link'] && youOP) { quotesYou = true } else if (QuoteYou.db && postObj.com) { - var match + let match const regexp = site.regexp.quotelinkHTML regexp.lastIndex = 0 while (match = regexp.exec(postObj.com)) { @@ -550,7 +550,7 @@ const ThreadWatcher = { for (const siteID in ThreadWatcher.db.data) { const boards = ThreadWatcher.db.data[siteID] for (const boardID in boards.boards) { - var cont + let cont const threads = boards.boards[boardID] if (Conf['Current Board'] && ((siteID !== g.SITE.ID) || (boardID !== g.BOARD.ID))) { continue @@ -664,7 +664,7 @@ const ThreadWatcher = { ThreadWatcher.setPrefixes(threads) for (const { siteID, boardID, threadID, data } of threads) { // 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) { ThreadWatcher.db.extend({ boardID, threadID, val: { excerpt: Get.threadExcerpt(thread) } }) } @@ -684,7 +684,7 @@ const ThreadWatcher = { const isWatched = ThreadWatcher.isWatched(thread) if (thread.OP) { for (const post of [thread.OP, ...Array.from(thread.OP.clones)]) { - var toggler + let toggler if (toggler = $('.watch-thread-link', post.nodes.info)) { ThreadWatcher.setToggler(toggler, isWatched) } diff --git a/src/Posting/Captcha.ts b/src/Posting/Captcha.ts index e377091..307b8c0 100644 --- a/src/Posting/Captcha.ts +++ b/src/Posting/Captcha.ts @@ -318,7 +318,7 @@ const Captcha = { afterSetup(mutations) { for (const mutation of mutations) { 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 (textarea = $.x('./descendant-or-self::textarea', node)) { this.setupTextArea(textarea) } } diff --git a/src/Posting/QR.ts b/src/Posting/QR.ts index d553ac5..baf6fcd 100644 --- a/src/Posting/QR.ts +++ b/src/Posting/QR.ts @@ -80,7 +80,7 @@ const QR = { captcha: null, postingIsEnabled: false, nodes: null, - posts: null, + posts: 0, shortcut: null, link: '', min_width: 0, @@ -1480,7 +1480,7 @@ const QR = { if (window.Tegaki) { return document.querySelector('#qr .oekaki').hidden = false } - }) + }, 'oekaki') }, load(cb) { @@ -1529,7 +1529,7 @@ const QR = { height: getHeight(), bgColor: getBgColor(), }) - }) + }, 'oekaki') }, button() { @@ -1587,18 +1587,21 @@ const QR = { } else { return cb(E) } - })) + }, 0)) }, toggle() { return QR.oekaki.load(() => QR.nodes.oekaki.hidden = !QR.nodes.oekaki.hidden) } }, - email: null, + email: { + }, + sub: { + }, persona: { pwd: '', - always: false, + always: [], types: { name: [""], email: [""], @@ -1689,7 +1692,6 @@ const QR = { com: string spoiler: boolean name: string - email: string fileUrl: string fileThumb: string nodes: { el: HTMLElement; rm: HTMLElement; spoiler: HTMLInputElement; span: HTMLElement } @@ -1752,12 +1754,12 @@ const QR = { : persona.name - this.email = 'email' in QR.persona.always ? + QR.email = 'email' in QR.persona.always ? QR.persona.always.email : '' - this.sub = 'sub' in QR.persona.always ? + QR.sub = 'sub' in QR.persona.always ? QR.persona.always.sub : '' diff --git a/src/Quotelinks/QuoteBacklink.ts b/src/Quotelinks/QuoteBacklink.ts index c757e88..0a2cace 100644 --- a/src/Quotelinks/QuoteBacklink.ts +++ b/src/Quotelinks/QuoteBacklink.ts @@ -49,7 +49,7 @@ const QuoteBacklink = { ) if (markYours) { $.add(a, QuoteYou.mark.cloneNode(true)) } for (const quote of this.quotes) { - var post + let post const containers = [QuoteBacklink.getContainer(quote)] if ((post = g.posts.get(quote)) && post.nodes.backlinkContainer) { // Don't add OP clones when OP Backlinks is disabled, diff --git a/src/classes/Post.ts b/src/classes/Post.ts index 2d62493..df82a33 100644 --- a/src/classes/Post.ts +++ b/src/classes/Post.ts @@ -87,7 +87,7 @@ export default class Post { if (!this.isReply) { this.thread.OP = this for (const key of ['isSticky', 'isClosed', 'isArchived']) { - var selector: any + let selector: any if (selector = g.SITE.selectors.icons[key]) { this.thread[key] = !!$(selector, this.nodes.info) } diff --git a/src/meta/eventPage.ts b/src/meta/eventPage.ts index da37866..2f32791 100644 --- a/src/meta/eventPage.ts +++ b/src/meta/eventPage.ts @@ -37,8 +37,8 @@ const handlers = { xhr.responseType = request.responseType; xhr.timeout = request.timeout; const object = request.headers || {}; - for (var key in object) { - var value = object[key]; + for (let key in object) { + let value = object[key]; xhr.setRequestHeader(key, value); } xhr.addEventListener('load', function () { diff --git a/src/meta/metadata.js b/src/meta/metadata.js index 061f7ec..91f0df9 100644 --- a/src/meta/metadata.js +++ b/src/meta/metadata.js @@ -29,7 +29,7 @@ export default async function generateMetadata(packageJson, channel) { output += (function () { function expand(items, regex, substitutions) { - var results = []; + let results = []; items.forEach(function (item) { if (regex.test(item)) { substitutions.forEach(function (s) { diff --git a/src/platform/$.ts b/src/platform/$.ts index af7b7cc..4311c53 100644 --- a/src/platform/$.ts +++ b/src/platform/$.ts @@ -848,7 +848,7 @@ if (platform === 'crx') { $.on($.syncChannel, 'message', e => (() => { const result = [] for (const key in e.data) { - var cb + let cb const val = e.data[key] if (cb = $.syncing[key]) { result.push(cb(dict.json(JSON.stringify(val)), key)) diff --git a/src/platform/CrossOrigin.ts b/src/platform/CrossOrigin.ts index b462881..6bb11e2 100644 --- a/src/platform/CrossOrigin.ts +++ b/src/platform/CrossOrigin.ts @@ -42,7 +42,7 @@ const CrossOrigin = { return cb(null) } } - }) + }, cb) } if ((typeof window.GM_xmlhttpRequest === 'undefined' || window.GM_xmlhttpRequest === null)) { fallback() @@ -109,6 +109,11 @@ const CrossOrigin = { Request: (function () { const Request = class Request { + statusText: string + response: any + status: number + responseHeaderString: string + responseHeaders: any static initClass() { this.prototype.status = 0 this.prototype.statusText = '' @@ -119,7 +124,7 @@ const CrossOrigin = { if ((this.responseHeaders == null) && (this.responseHeaderString != null)) { this.responseHeaders = dict() for (const header of this.responseHeaderString.split('\r\n')) { - var i + let i if ((i = header.indexOf(':')) >= 0) { const key = header.slice(0, i).trim().toLowerCase() const val = header.slice(i + 1).trim() @@ -193,7 +198,12 @@ const CrossOrigin = { try { gmReq = (GM?.xmlHttpRequest || GM_xmlhttpRequest)(gmOptions) } 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')) { diff --git a/src/site/SW.tinyboard.ts b/src/site/SW.tinyboard.ts index a63cf3d..8985b17 100644 --- a/src/site/SW.tinyboard.ts +++ b/src/site/SW.tinyboard.ts @@ -89,15 +89,7 @@ const SWTinyboard = { return Main.mounted(true) }, awaitBoard(cb) { - let reactUI - 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() - } + return Main.mounted(true).then(cb) }, urls: { diff --git a/src/site/SW.yotsuba.tsx b/src/site/SW.yotsuba.tsx index 77655bb..20f783e 100644 --- a/src/site/SW.yotsuba.tsx +++ b/src/site/SW.yotsuba.tsx @@ -131,7 +131,7 @@ const SWYotsuba = { $\ `), quotelinkHTML: - /]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^\/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g, + /]*\bhref="(?:(?:\/\/boards\.4chan(?:nel)?\.org)?\/([^/]+)\/thread\/)?(\d+)?(?:#p(\d+))?"/g, pass: /^https?:\/\/www\.4chan(?:nel)?\.org\/+pass(?:$|[?#])/, captcha: diff --git a/src/site/Site.ts b/src/site/Site.ts index b52ff89..5766f1f 100644 --- a/src/site/Site.ts +++ b/src/site/Site.ts @@ -72,7 +72,7 @@ const Site = { set(hostname) { for (const ID in Conf['siteProperties']) { - var site + let site const properties = Conf['siteProperties'][ID] if (properties.canonical) { continue } const {