diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 721705b7f..553df4940 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -8111,8 +8111,9 @@ if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } - if (Conf['Title Link']) { + if (Conf['Link Title']) { $.sync('CachedTitles', Linkify.titleSync); + this.clean(); } return Post.callbacks.push({ name: 'Linkify', @@ -8328,6 +8329,26 @@ titleSync: function(value) { return Conf['CachedTitles'] = value; }, + clean: function() { + var age, name, pruned, uid, _ref, _ref1; + pruned = false; + c.log('cleaning'); + c.log(Object.keys(Conf.CachedTitles).length); + _ref = Conf['CachedTitles']; + for (uid in _ref) { + _ref1 = _ref[uid], name = _ref1[0], age = _ref1[1]; + if (!(age + $.DAY > Date.now())) { + continue; + } + pruned = true; + delete Conf['CachedTitles'][uid]; + } + c.log(Object.keys(Conf.CachedTitles).length); + c.log('cleaned'); + if (pruned) { + return $.set('CachedTitles', Conf['CachedTitles']); + } + }, cb: { toggle: function() { var string, _ref; diff --git a/builds/crx/script.js b/builds/crx/script.js index 408a1f96f..9210a9780 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -8162,8 +8162,9 @@ if (Conf['Comment Expansion']) { ExpandComment.callbacks.push(this.node); } - if (Conf['Title Link']) { + if (Conf['Link Title']) { $.sync('CachedTitles', Linkify.titleSync); + this.clean(); } return Post.callbacks.push({ name: 'Linkify', @@ -8379,6 +8380,26 @@ titleSync: function(value) { return Conf['CachedTitles'] = value; }, + clean: function() { + var age, name, pruned, uid, _ref, _ref1; + pruned = false; + c.log('cleaning'); + c.log(Object.keys(Conf.CachedTitles).length); + _ref = Conf['CachedTitles']; + for (uid in _ref) { + _ref1 = _ref[uid], name = _ref1[0], age = _ref1[1]; + if (!(age + $.DAY > Date.now())) { + continue; + } + pruned = true; + delete Conf['CachedTitles'][uid]; + } + c.log(Object.keys(Conf.CachedTitles).length); + c.log('cleaned'); + if (pruned) { + return $.set('CachedTitles', Conf['CachedTitles']); + } + }, cb: { toggle: function() { var string, _ref; diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index 2976c1072..1a1c1e807 100755 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -5,8 +5,9 @@ Linkify = if Conf['Comment Expansion'] ExpandComment.callbacks.push @node - if Conf['Title Link'] + if Conf['Link Title'] $.sync 'CachedTitles', Linkify.titleSync + @clean() Post.callbacks.push name: 'Linkify' @@ -190,7 +191,7 @@ Linkify = embed.dataset.title = title[0] else try - $.cache service.api(uid), + $.cache service.api(uid), -> title = Linkify.cb.title @, data , responseType: 'json' @@ -205,6 +206,13 @@ Linkify = titleSync: (value) -> Conf['CachedTitles'] = value + clean: -> + pruned = false + for uid, [name, age] of Conf['CachedTitles'] when age + $.DAY > Date.now() + pruned = true + delete Conf['CachedTitles'][uid] + $.set 'CachedTitles', Conf['CachedTitles'] if pruned + cb: toggle: -> [string, @textContent] = if $.hasClass @, "embedded"