From bb8fab20b08501bff94e3ab9931b9e94dc85026a Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 11 Aug 2019 21:22:19 -0700 Subject: [PATCH] Make date parsing work on onesixtwo.club. --- src/classes/Post.coffee | 4 +--- src/site/SW.tinyboard.coffee | 7 +++++++ src/site/SW.yotsuba.coffee | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index 3a0ad5e44..821130a0b 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -39,9 +39,7 @@ class Post flagCode: @nodes.flag?.className.match(/flag-(\w+)/)?[1].toUpperCase() flagCodeTroll: @nodes.flag?.src?.match(/(\w+)\.gif$/)?[1].toUpperCase() flag: @nodes.flag?.title - date: if @nodes.date then new Date(@nodes.date.getAttribute('datetime')?.trim() or (@nodes.date.dataset.utc * 1000)) - - delete @info.date if @info.date and isNaN(@info.date.getTime()) + date: if @nodes.date then g.SITE.parseDate(@nodes.date) if Conf['Anonymize'] @info.nameBlock = 'Anonymous' diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index be137eea9..cf41d0006 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -174,6 +174,13 @@ SW.tinyboard = $.replace nextSibling, uniqueID $.add uniqueID, nextSibling + parseDate: (node) -> + date = Date.parse(node.getAttribute('datetime')?.trim()) + return new Date(date) unless isNaN(date) + date = Date.parse(node.textContent.trim() + ' UTC') # e.g. onesixtwo.club + return new Date(date) unless isNaN(date) + undefined + parseFile: (post, file) -> {text, link, thumb} = file return false if $.x("ancestor::#{@xpath.postContainer}[1]", text) isnt post.nodes.root # file belongs to a reply diff --git a/src/site/SW.yotsuba.coffee b/src/site/SW.yotsuba.coffee index 1d8e828cd..cb5b2e2df 100644 --- a/src/site/SW.yotsuba.coffee +++ b/src/site/SW.yotsuba.coffee @@ -174,6 +174,9 @@ SW.yotsuba = for type in ['Sticky', 'Closed'] when (icon = $ "img[alt=#{type}]", nodes.info) $.addClass icon, "#{type.toLowerCase()}Icon", 'retina' + parseDate: (node) -> + new Date(node.dataset.utc * 1000) + parseFile: (post, file) -> {text, link, thumb} = file return false if not (info = link.nextSibling?.textContent.match /\(([\d.]+ [KMG]?B).*\)/)