From 5dd3cc38d0749ce1869671d38f23f75a35fb3bd6 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Sat, 16 Feb 2013 00:02:01 +0100 Subject: [PATCH] Kill each clones when we kill a post too. --- 4chan_x.user.js | 52 +++++++++++++++++++++++++-------------------- src/features.coffee | 14 ++++++------ src/main.coffee | 34 ++++++++++++++++------------- 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index ab5b191f4..9b63c5296 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -20,7 +20,7 @@ // @icon data:image/gif;base64,R0lGODlhEAAQAKECAAAAAGbMM////////yH5BAEKAAIALAAAAAAQABAAAAIxlI+pq+D9DAgUoFkPDlbs7lGiI2bSVnKglnJMOL6omczxVZK3dH/41AG6Lh7i6qUoAAA7 // ==/UserScript== -/* 4chan X Alpha - Version 3.0.0 - 2013-02-15 +/* 4chan X Alpha - Version 3.0.0 - 2013-02-16 * http://mayhemydg.github.com/4chan-x/ * * Copyright (c) 2009-2011 James Campos @@ -3364,7 +3364,7 @@ var markStale, setOwnTimeout, update; setOwnTimeout = function(diff) { var delay; - delay = diff >= $.DAY ? diff % $.DAY : diff >= $.HOUR ? diff % $.HOUR : diff >= $.MINUTE ? diff % $.MINUTE : diff % $.SECOND; + delay = diff < $.MINUTE ? diff % $.SECOND : diff < $.HOUR ? diff % $.MINUTE : diff < $.DAY ? diff % $.HOUR : diff % $.DAY; return setTimeout(markStale, delay); }; update = function(now) { @@ -5285,34 +5285,40 @@ } } - Post.prototype.kill = function(img) { - var now, quotelink, strong, _i, _len, _ref; - now = new Date(); - if (this.file && !this.file.isDead) { + Post.prototype.kill = function(file, now) { + var clone, quotelink, strong, _i, _j, _len, _len1, _ref, _ref1; + now || (now = new Date()); + if (file) { this.file.isDead = true; this.file.timeOfDeath = now; - $.after($('input', this.nodes.info), $.el('strong', { - className: 'warning', - textContent: '[File deleted]' - })); - } - if (img) { - return; - } - this.isDead = true; - this.timeOfDeath = now; - $.addClass(this.nodes.root, 'dead'); - if (strong = $('strong.warning', this.nodes.info)) { - strong.textContent = '[Deleted]'; + $.addClass(this.nodes.root, 'deleted-file'); } else { - $.after($('input', this.nodes.info), $.el('strong', { + this.isDead = true; + this.timeOfDeath = now; + $.addClass(this.nodes.root, 'deleted-post'); + } + if (!(strong = $('strong.warning', this.nodes.info))) { + strong = $.el('strong', { className: 'warning', textContent: '[Deleted]' - })); + }); + $.after($('input', this.nodes.info), strong); } - _ref = Get.allQuotelinksLinkingTo(this); + strong.textContent = file ? '[File deleted]' : '[Deleted]'; + if (this.isClone) { + return; + } + _ref = this.clones; for (_i = 0, _len = _ref.length; _i < _len; _i++) { - quotelink = _ref[_i]; + clone = _ref[_i]; + clone.kill(file, now); + } + if (file) { + return; + } + _ref1 = Get.allQuotelinksLinkingTo(this); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + quotelink = _ref1[_j]; if ($.hasClass(quotelink, 'deadlink')) { continue; } diff --git a/src/features.coffee b/src/features.coffee index a3ba9956c..3a261a133 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -2079,14 +2079,14 @@ RelativeDates = # re-add `update()` to the stale list later. setUpdate: (post) -> setOwnTimeout = (diff) -> - delay = if diff >= $.DAY - diff % $.DAY - else if diff >= $.HOUR - diff % $.HOUR - else if diff >= $.MINUTE - diff % $.MINUTE - else + delay = if diff < $.MINUTE diff % $.SECOND + else if diff < $.HOUR + diff % $.MINUTE + else if diff < $.DAY + diff % $.HOUR + else + diff % $.DAY setTimeout markStale, delay update = (now) -> diff --git a/src/main.coffee b/src/main.coffee index 4edb6d432..7b69cb7d2 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -145,25 +145,29 @@ class Post g.posts["#{board}.#{@}"] = thread.posts[@] = board.posts[@] = @ @kill() if that.isArchived - kill: (img) -> - now = new Date() - if @file and !@file.isDead + kill: (file, now) -> + now or= new Date() + if file @file.isDead = true @file.timeOfDeath = now - $.after $('input', @nodes.info), $.el 'strong', - className: 'warning' - textContent: '[File deleted]' - return if img - @isDead = true - @timeOfDeath = now - $.addClass @nodes.root, 'dead' - if strong = $ 'strong.warning', @nodes.info - strong.textContent = '[Deleted]' + $.addClass @nodes.root, 'deleted-file' else - $.after $('input', @nodes.info), $.el 'strong', - className: 'warning' - textContent: '[Deleted]' + @isDead = true + @timeOfDeath = now + $.addClass @nodes.root, 'deleted-post' + unless strong = $ 'strong.warning', @nodes.info + strong = $.el 'strong', + className: 'warning' + textContent: '[Deleted]' + $.after $('input', @nodes.info), strong + strong.textContent = if file then '[File deleted]' else '[Deleted]' + + return if @isClone + for clone in @clones + clone.kill file, now + + return if file # Get quotelinks/backlinks to this post # and paint them (Dead). for quotelink in Get.allQuotelinksLinkingTo @