From a214f51755bb5c1e6ad569601b48c30047ae2bd6 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 9 Apr 2019 06:49:13 -0700 Subject: [PATCH] Move Build to SW.yotsuba.Build. --- src/Filtering/Filter.coffee | 2 +- src/General/Index.coffee | 28 +++++++++---------- src/General/Test.coffee | 6 ++-- src/Miscellaneous/ExpandComment.coffee | 2 +- src/Miscellaneous/ExpandThread.coffee | 14 +++++----- src/Miscellaneous/FileInfo.coffee | 2 +- src/Monitoring/ReplyPruning.coffee | 4 +-- src/Monitoring/ThreadUpdater.coffee | 4 +-- src/Monitoring/ThreadWatcher.coffee | 9 +++--- src/Quotelinks/QuoteBacklink.coffee | 2 +- src/Quotelinks/Quotify.coffee | 4 +-- src/classes/Fetcher.coffee | 8 +++--- src/classes/Thread.coffee | 2 +- src/site/SW.tinyboard.coffee | 9 ++++++ .../SW.yotsuba.Build.coffee} | 2 ++ .../SW.yotsuba.Build}/CatalogReply.html | 0 .../SW.yotsuba.Build}/CatalogThread.html | 0 .../Build => site/SW.yotsuba.Build}/File.html | 0 .../Build => site/SW.yotsuba.Build}/Post.html | 0 .../SW.yotsuba.Build}/PostInfo.html | 0 20 files changed, 55 insertions(+), 43 deletions(-) rename src/{General/Build.coffee => site/SW.yotsuba.Build.coffee} (99%) rename src/{General/Build => site/SW.yotsuba.Build}/CatalogReply.html (100%) rename src/{General/Build => site/SW.yotsuba.Build}/CatalogThread.html (100%) rename src/{General/Build => site/SW.yotsuba.Build}/File.html (100%) rename src/{General/Build => site/SW.yotsuba.Build}/Post.html (100%) rename src/{General/Build => site/SW.yotsuba.Build}/PostInfo.html (100%) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index d0cb2ce64..e4af3055a 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -178,7 +178,7 @@ Filter = pass: (post) -> post.info.pass email: (post) -> post.info.email subject: (post) -> post.info.subject or (if post.isReply then undefined else '') - comment: (post) -> (post.info.comment ?= Build.parseComment post.info.commentHTML.innerHTML) + comment: (post) -> (post.info.comment ?= g.sites[post.siteID]?.Build?.parseComment?(post.info.commentHTML.innerHTML)) flag: (post) -> post.info.flag filename: (post) -> post.file?.name dimensions: (post) -> post.file?.dimensions diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 99bf91638..eececd6b8 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -141,13 +141,13 @@ Index = d.title = d.title.replace /\ -\ Page\ \d+/, '' $.onExists doc, '.board > .thread > .postContainer, .board + *', -> - Build.hat = $ '.board > .thread > img:first-child' - if Build.hat + g.SITE.Build.hat = $ '.board > .thread > img:first-child' + if g.SITE.Build.hat g.BOARD.threads.forEach (thread) -> if thread.nodes.root - $.prepend thread.nodes.root, Build.hat.cloneNode false + $.prepend thread.nodes.root, g.SITE.Build.hat.cloneNode false $.addClass doc, 'hats-enabled' - $.addStyle ".catalog-thread::after {background-image: url(#{Build.hat.src});}" + $.addStyle ".catalog-thread::after {background-image: url(#{g.SITE.Build.hat.src});}" board = $ '.board' $.replace board, Index.root @@ -663,7 +663,7 @@ Index = for data, i in Index.liveThreadData Index.liveThreadDict[data.no] = data Index.threadPosition[data.no] = i - Index.parsedThreads[data.no] = obj = Build.parseJSON data, g.BOARD.ID + Index.parsedThreads[data.no] = obj = g.SITE.Build.parseJSON data, g.BOARD.ID obj.filterResults = results = Filter.test obj obj.isOnTop = results.top obj.isHidden = results.hide or ThreadHiding.isHidden(obj.boardID, obj.threadID) @@ -671,7 +671,7 @@ Index = for reply in data.last_replies Index.replyData["#{g.BOARD}.#{reply.no}"] = reply if Index.liveThreadData[0] - Build.spoilerRange[g.BOARD.ID] = Index.liveThreadData[0].custom_spoiler + g.SITE.Build.spoilerRange[g.BOARD.ID] = Index.liveThreadData[0].custom_spoiler g.BOARD.threads.forEach (thread) -> (thread.collect() unless thread.ID in Index.liveThreadIDs) $.event 'IndexUpdate', @@ -685,7 +685,7 @@ Index = Index.parsedThreads[threadID].isHidden isHiddenReply: (threadID, replyData) -> - PostHiding.isHidden(g.BOARD.ID, threadID, replyData.no) or Filter.isHidden(Build.parseJSON replyData, g.BOARD.ID) + PostHiding.isHidden(g.BOARD.ID, threadID, replyData.no) or Filter.isHidden(g.SITE.Build.parseJSON replyData, g.BOARD.ID) lastPost: (threadID) -> threadData = Index.liveThreadDict[threadID] @@ -720,12 +720,12 @@ Index = thread.setPage(Index.threadPosition[ID] // Index.threadsNumPerPage + 1) else obj = Index.parsedThreads[ID] - OP = new Post Build.post(obj), thread, g.BOARD + OP = new Post g.SITE.Build.post(obj), thread, g.BOARD OP.filterResults = obj.filterResults newPosts.push OP unless isCatalog and thread.nodes.root - Build.thread thread, threadData, withReplies + g.SITE.Build.thread thread, threadData, withReplies catch err # Skip posts that we failed to parse. errors = [] unless errors @@ -753,7 +753,7 @@ Index = if (post = thread.posts[data.no]) and not post.isFetchedQuote nodes.push post.nodes.root continue - nodes.push node = Build.postFromObject data, thread.board.ID + nodes.push node = g.SITE.Build.postFromObject data, thread.board.ID try posts.push new Post node, thread, thread.board catch err @@ -772,7 +772,7 @@ Index = for thread in threads when !thread.catalogView {ID} = thread page = Index.threadPosition[ID] // Index.threadsNumPerPage + 1 - root = Build.catalogThread thread, Index.liveThreadDict[ID], page + root = g.SITE.Build.catalogThread thread, Index.liveThreadDict[ID], page catalogThreads.push new CatalogThread root, thread Main.callbackNodes 'CatalogThread', catalogThreads return @@ -796,7 +796,7 @@ Index = replies = [] for data in lastReplies continue if Index.isHiddenReply thread.ID, data - reply = Build.catalogReply thread, data + reply = g.SITE.Build.catalogReply thread, data RelativeDates.update $('time', reply) $.on $('.catalog-reply-preview', reply), 'mouseover', QuotePreview.mouseover replies.push reply @@ -820,7 +820,7 @@ Index = lastlong = (thread) -> for r, i in (thread.last_replies or []) by -1 continue if Index.isHiddenReply thread.no, r - len = if r.com then Build.parseComment(r.com).replace(/[^a-z]/ig, '').length else 0 + len = if r.com then g.SITE.Build.parseComment(r.com).replace(/[^a-z]/ig, '').length else 0 if len >= Index.lastLongThresholds[+!!r.ext] return r if thread.omitted_posts then thread.last_replies[0] else thread @@ -949,7 +949,7 @@ Index = searchMatch: (obj, keywords) -> {info, file} = obj - info.comment ?= Build.parseComment info.commentHTML.innerHTML + info.comment ?= g.SITE.Build.parseComment info.commentHTML.innerHTML text = [] for key in ['comment', 'subject', 'name', 'tripcode'] text.push info[key] if key of info diff --git a/src/General/Test.coffee b/src/General/Test.coffee index 60b1ddd87..a7f0343d0 100644 --- a/src/General/Test.coffee +++ b/src/General/Test.coffee @@ -68,12 +68,12 @@ Test = $.cache g.SITE.urls.threadJSON({boardID: post.boardID, threadID: post.threadID}), -> return unless @response {posts} = @response - Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler + g.SITE.Build.spoilerRange[post.board.ID] = posts[0].custom_spoiler for postData in posts if postData.no is post.ID t1 = new Date().getTime() - obj = Build.parseJSON postData, post.board.ID - root = Build.post obj + obj = g.SITE.Build.parseJSON postData, post.board.ID + root = g.SITE.Build.post obj t2 = new Date().getTime() Test.time += t2 - t1 post2 = new Post root, post.thread, post.board, 'forBuildTest' diff --git a/src/Miscellaneous/ExpandComment.coffee b/src/Miscellaneous/ExpandComment.coffee index 3bbbd3d7b..dbf473c18 100644 --- a/src/Miscellaneous/ExpandComment.coffee +++ b/src/Miscellaneous/ExpandComment.coffee @@ -40,7 +40,7 @@ ExpandComment = posts = req.response.posts if spoilerRange = posts[0].custom_spoiler - Build.spoilerRange[g.BOARD] = spoilerRange + g.SITE.Build.spoilerRange[g.BOARD] = spoilerRange for postObj in posts break if postObj.no is post.ID diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index 9a270a62d..3ac687784 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -11,7 +11,7 @@ ExpandThread = setButton: (thread) -> return if not (thread.nodes.root and (a = $ '.summary', thread.nodes.root)) - a.textContent = Build.summaryText '+', a.textContent.match(/\d+/g)... + a.textContent = g.SITE.Build.summaryText '+', a.textContent.match(/\d+/g)... a.style.cursor = 'pointer' $.on a, 'click', ExpandThread.cbToggle @@ -53,7 +53,7 @@ ExpandThread = expand: (thread, a) -> ExpandThread.statuses[thread] = status = {} - a.textContent = Build.summaryText '...', a.textContent.match(/\d+/g)... + a.textContent = g.SITE.Build.summaryText '...', a.textContent.match(/\d+/g)... status.req = $.cache g.SITE.urls.threadJSON({boardID: thread.board.ID, threadID: thread.ID}), -> return if @ isnt status.req # aborted delete status.req @@ -65,7 +65,7 @@ ExpandThread = if (oldReq = status.req) delete status.req oldReq.abort() - a.textContent = Build.summaryText '+', a.textContent.match(/\d+/g)... if a + a.textContent = g.SITE.Build.summaryText '+', a.textContent.match(/\d+/g)... if a return replies = $$ '.thread > .replyContainer', threadRoot @@ -88,7 +88,7 @@ ExpandThread = $.rm reply if Index.enabled # otherwise handled by Main.addPosts $.event 'PostsRemoved', null, a.parentNode - a.textContent = Build.summaryText '+', postsCount, filesCount + a.textContent = g.SITE.Build.summaryText '+', postsCount, filesCount $.rm $('.summary-bottom', threadRoot) parse: (req, thread, a) -> @@ -96,7 +96,7 @@ ExpandThread = a.textContent = if req.status then "Error #{req.statusText} (#{req.status})" else 'Connection Error' return - Build.spoilerRange[thread.board] = req.response.posts[0].custom_spoiler + g.SITE.Build.spoilerRange[thread.board] = req.response.posts[0].custom_spoiler posts = [] postsRoot = [] @@ -108,7 +108,7 @@ ExpandThread = {root} = post.nodes postsRoot.push root continue - root = Build.postFromObject postData, thread.board.ID + root = g.SITE.Build.postFromObject postData, thread.board.ID post = new Post root, thread, thread.board filesCount++ if 'file' of post posts.push post @@ -118,7 +118,7 @@ ExpandThread = $.event 'PostsInserted', null, a.parentNode postsCount = postsRoot.length - a.textContent = Build.summaryText '-', postsCount, filesCount + a.textContent = g.SITE.Build.summaryText '-', postsCount, filesCount if root a2 = a.cloneNode true diff --git a/src/Miscellaneous/FileInfo.coffee b/src/Miscellaneous/FileInfo.coffee index 5f8332b6f..d62c6411b 100644 --- a/src/Miscellaneous/FileInfo.coffee +++ b/src/Miscellaneous/FileInfo.coffee @@ -45,7 +45,7 @@ FileInfo = L: -> <%= html('&{FileInfo.formatters.N.call(this)}') %> n: -> fullname = @file.name - shortname = Build.shortFilename @file.name, @isReply + shortname = g.SITE.Build.shortFilename @file.name, @isReply if fullname is shortname <%= html('${fullname}') %> else diff --git a/src/Monitoring/ReplyPruning.coffee b/src/Monitoring/ReplyPruning.coffee index e4c9f798f..b9a6b1d2e 100644 --- a/src/Monitoring/ReplyPruning.coffee +++ b/src/Monitoring/ReplyPruning.coffee @@ -125,9 +125,9 @@ ReplyPruning = $.event 'PostsInserted', null, ReplyPruning.summary.parentNode ReplyPruning.summary.textContent = if ReplyPruning.active - Build.summaryText '+', ReplyPruning.hidden, ReplyPruning.hiddenFiles + g.SITE.Build.summaryText '+', ReplyPruning.hidden, ReplyPruning.hiddenFiles else - Build.summaryText '-', ReplyPruning.total, ReplyPruning.totalFiles + g.SITE.Build.summaryText '-', ReplyPruning.total, ReplyPruning.totalFiles ReplyPruning.summary.hidden = (ReplyPruning.total <= +Conf["Max Replies"]) # Maintain position in thread when posts are added/removed above diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 74925d5e7..d4cbf5abc 100644 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -267,7 +267,7 @@ ThreadUpdater = return if postObjects[postObjects.length-1].no < lastPost and new Date(req.getResponseHeader('Last-Modified')) - thread.posts[lastPost].info.date < 30 * $.SECOND - Build.spoilerRange[board] = OP.custom_spoiler + g.SITE.Build.spoilerRange[board] = OP.custom_spoiler thread.setStatus 'Archived', !!OP.archived ThreadUpdater.updateThreadStatus 'Sticky', !!OP.sticky ThreadUpdater.updateThreadStatus 'Closed', !!OP.closed @@ -295,7 +295,7 @@ ThreadUpdater = continue newPosts.push "#{board}.#{ID}" - node = Build.postFromObject postObject, board.ID + node = g.SITE.Build.postFromObject postObject, board.ID posts.push new Post node, thread, board # Fetching your own posts after posting delete ThreadUpdater.postID if ThreadUpdater.postID is ID diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index e9d06ef98..d43347c36 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -325,6 +325,7 @@ ThreadWatcher = ThreadWatcher.fetch url, {siteID, force}, [thread], ThreadWatcher.parseStatus parseStatus: ({siteID, boardID, threadID, data}) -> + site = g.sites[siteID] if @status is 200 and @response last = @response.posts[@response.posts.length-1].no replies = @response.posts.length-1 @@ -346,14 +347,14 @@ ThreadWatcher = unread++ - if !quotingYou and !Conf['Require OP Quote Link'] and youOP and not Filter.isHidden(Build.parseJSON postObj, boardID, siteID) + if !quotingYou and !Conf['Require OP Quote Link'] and youOP and not Filter.isHidden(site.Build.parseJSON postObj, boardID, siteID) quotingYou = true continue continue unless !quotingYou and QuoteYou.db and postObj.com quotesYou = false - regexp = g.sites[siteID].regexp.quotelinkHTML + regexp = site.regexp.quotelinkHTML regexp.lastIndex = 0 while match = regexp.exec postObj.com if QuoteYou.db.get { @@ -364,13 +365,13 @@ ThreadWatcher = } quotesYou = true break - if quotesYou and not Filter.isHidden(Build.parseJSON postObj, boardID, siteID) + if quotesYou and not Filter.isHidden(site.Build.parseJSON postObj, boardID, siteID) quotingYou = true ThreadWatcher.update siteID, boardID, threadID, {last, replies, isDead, unread, quotingYou} else if @status is 404 - if g.sites[siteID].mayLackJSON and !data.last? + if site.mayLackJSON and !data.last? ThreadWatcher.update siteID, boardID, threadID, {last: -1} else ThreadWatcher.update siteID, boardID, threadID, {isDead: true} diff --git a/src/Quotelinks/QuoteBacklink.coffee b/src/Quotelinks/QuoteBacklink.coffee index 50eb97dd2..4d3f8f856 100644 --- a/src/Quotelinks/QuoteBacklink.coffee +++ b/src/Quotelinks/QuoteBacklink.coffee @@ -29,7 +29,7 @@ QuoteBacklink = return if @isClone or !@quotes.length or @isRebuilt markYours = Conf['Mark Quotes of You'] and QuoteYou.isYou(@) a = $.el 'a', - href: Build.postURL @board.ID, @thread.ID, @ID + href: g.SITE.Build.postURL @board.ID, @thread.ID, @ID className: if @isHidden then 'filtered backlink' else 'backlink' textContent: Conf['backlink'].replace(/%(?:id|%)/g, (x) => ({'%id': @ID, '%%': '%'})[x]) $.add a, QuoteYou.mark.cloneNode(true) if markYours diff --git a/src/Quotelinks/Quotify.coffee b/src/Quotelinks/Quotify.coffee index b088ea6c6..a72fb15b0 100644 --- a/src/Quotelinks/Quotify.coffee +++ b/src/Quotelinks/Quotify.coffee @@ -59,13 +59,13 @@ Quotify = # Don't (Dead) when quotifying in an archived post, # and we know the post still exists. a = $.el 'a', - href: Build.postURL boardID, post.thread.ID, postID + href: g.SITE.Build.postURL boardID, post.thread.ID, postID className: 'quotelink' textContent: quote else # Replace the .deadlink span if we can redirect. a = $.el 'a', - href: Build.postURL boardID, post.thread.ID, postID + href: g.SITE.Build.postURL boardID, post.thread.ID, postID className: 'quotelink deadlink' textContent: quote $.add a, Post.deadMark.cloneNode(true) diff --git a/src/classes/Fetcher.coffee b/src/classes/Fetcher.coffee index d61e50d96..10e1226ee 100644 --- a/src/classes/Fetcher.coffee +++ b/src/classes/Fetcher.coffee @@ -7,7 +7,7 @@ class Fetcher # 4chan X catalog data if (post = Index.replyData?["#{@boardID}.#{@postID}"]) and (thread = g.threads["#{@boardID}.#{@threadID}"]) board = g.boards[@boardID] - post = new Post Build.postFromObject(post, @boardID), thread, board + post = new Post g.SITE.Build.postFromObject(post, @boardID), thread, board post.isFetchedQuote = true Main.callbackNodes 'Post', [post] @insert post @@ -74,7 +74,7 @@ class Fetcher return {posts} = req.response - Build.spoilerRange[@boardID] = posts[0].custom_spoiler + g.SITE.Build.spoilerRange[@boardID] = posts[0].custom_spoiler for post in posts break if post.no is @postID # we found it! @@ -99,7 +99,7 @@ class Fetcher new Board @boardID thread = g.threads["#{@boardID}.#{@threadID}"] or new Thread @threadID, board - post = new Post Build.postFromObject(post, @boardID), thread, board + post = new Post g.SITE.Build.postFromObject(post, @boardID), thread, board post.isFetchedQuote = true Main.callbackNodes 'Post', [post] @insert post @@ -214,7 +214,7 @@ class Fetcher new Board @boardID thread = g.threads["#{@boardID}.#{@threadID}"] or new Thread @threadID, board - post = new Post Build.post(o), thread, board + post = new Post g.SITE.Build.post(o), thread, board post.kill() post.file.thumbURL = o.file.thumbURL if post.file post.isFetchedQuote = true diff --git a/src/classes/Thread.coffee b/src/classes/Thread.coffee index d5e05d691..25f97d0dc 100644 --- a/src/classes/Thread.coffee +++ b/src/classes/Thread.coffee @@ -58,7 +58,7 @@ class Thread $.rm $ ".#{typeLC}Icon", @catalogView.nodes.icons if @catalogView return icon = $.el 'img', - src: "#{Build.staticPath}#{typeLC}#{Build.gifIcon}" + src: "#{g.SITE.Build.staticPath}#{typeLC}#{g.SITE.Build.gifIcon}" alt: type title: type className: "#{typeLC}Icon retina" diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index 715cde595..43ec59b50 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -117,6 +117,15 @@ SW.tinyboard = quotelinkHTML: /]*\bhref="[^"]*\/([^\/]+)\/res\/(\d+)\.\w+#(\d+)"/g + Build: + parseJSON: -> + SW.yotsuba.Build.parseJSON.apply SW.yotsuba.Build, arguments + parseComment: (html) -> + html = html + .replace(//gi, '\n') + .replace(/<[^>]*>/g, '') + $.unescape html + bgColoredEl: -> $.el 'div', className: 'post reply' diff --git a/src/General/Build.coffee b/src/site/SW.yotsuba.Build.coffee similarity index 99% rename from src/General/Build.coffee rename to src/site/SW.yotsuba.Build.coffee index 282c428a3..73ca88070 100644 --- a/src/General/Build.coffee +++ b/src/site/SW.yotsuba.Build.coffee @@ -256,3 +256,5 @@ Build = link = Build.postURL thread.board.ID, thread.ID, data.no $.el 'div', {className: 'catalog-reply'}, <%= readHTML('CatalogReply.html') %> + +SW.yotsuba.Build = Build diff --git a/src/General/Build/CatalogReply.html b/src/site/SW.yotsuba.Build/CatalogReply.html similarity index 100% rename from src/General/Build/CatalogReply.html rename to src/site/SW.yotsuba.Build/CatalogReply.html diff --git a/src/General/Build/CatalogThread.html b/src/site/SW.yotsuba.Build/CatalogThread.html similarity index 100% rename from src/General/Build/CatalogThread.html rename to src/site/SW.yotsuba.Build/CatalogThread.html diff --git a/src/General/Build/File.html b/src/site/SW.yotsuba.Build/File.html similarity index 100% rename from src/General/Build/File.html rename to src/site/SW.yotsuba.Build/File.html diff --git a/src/General/Build/Post.html b/src/site/SW.yotsuba.Build/Post.html similarity index 100% rename from src/General/Build/Post.html rename to src/site/SW.yotsuba.Build/Post.html diff --git a/src/General/Build/PostInfo.html b/src/site/SW.yotsuba.Build/PostInfo.html similarity index 100% rename from src/General/Build/PostInfo.html rename to src/site/SW.yotsuba.Build/PostInfo.html