diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9c17f22..012f79909 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ -Sometimes the changelog has notes (not comprehensive) acknowledging people's work. This does not mean the changes are their fault, only that their code was used. All changes to the script are chosen by and the fault of the maintainer (ccd0). +### v1.13.15 + +**v1.13.15.0** *(2017-12-11)* - [[Userscript](https://raw.githubusercontent.com/ccd0/4chan-x/1.13.15.0/builds/4chan-X-noupdate.user.js)] [[Chrome extension](https://raw.githubusercontent.com/ccd0/4chan-x/1.13.15.0/builds/4chan-X-noupdate.crx)] +- Based on v1.13.14.12. +- Better protection against race conditions that can lead to data loss. + ### v1.13.14 **v1.13.14.12** *(2017-12-10)* - [[Userscript](https://raw.githubusercontent.com/ccd0/4chan-x/1.13.14.12/builds/4chan-X-noupdate.user.js)] [[Chrome extension](https://raw.githubusercontent.com/ccd0/4chan-x/1.13.14.12/builds/4chan-X-noupdate.crx)] diff --git a/builds/4chan-X-beta.crx b/builds/4chan-X-beta.crx index 7137c59b8..52bcf72a2 100644 Binary files a/builds/4chan-X-beta.crx and b/builds/4chan-X-beta.crx differ diff --git a/builds/4chan-X-beta.meta.js b/builds/4chan-X-beta.meta.js index 2ad871b5b..4f51f1af2 100644 --- a/builds/4chan-X-beta.meta.js +++ b/builds/4chan-X-beta.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X beta -// @version 1.13.14.12 +// @version 1.13.15.0 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X-beta.user.js b/builds/4chan-X-beta.user.js index bc65421ee..0fa7c78e3 100644 --- a/builds/4chan-X-beta.user.js +++ b/builds/4chan-X-beta.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X beta -// @version 1.13.14.12 +// @version 1.13.15.0 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -159,7 +159,7 @@ docSet = function() { }; g = { - VERSION: '1.13.14.12', + VERSION: '1.13.15.0', NAMESPACE: '4chan X.', boards: {} }; @@ -5621,35 +5621,91 @@ DataBoard = (function() { $.on(d, '4chanXInitFinished', init); } - DataBoard.prototype.save = function(cb) { - return $.set(this.key, this.data, cb); + DataBoard.prototype.changes = []; + + DataBoard.prototype.save = function(change, cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + change(); + changes = this.changes; + changes.push(change); + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + return $.set(_this.key, _this.data, function() { + _this.changes = []; + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }); + }; + })(this)); + }; + + DataBoard.prototype.forceSync = function(cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + changes = this.changes; + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }; + })(this)); }; DataBoard.prototype["delete"] = function(arg) { - var boardID, postID, ref, threadID; + var boardID, postID, threadID; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID; - $.forceSync(this.key); - if (postID) { - if (!((ref = this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { - return; - } - delete this.data.boards[boardID][threadID][postID]; - this.deleteIfEmpty({ - boardID: boardID, - threadID: threadID - }); - } else if (threadID) { - if (!this.data.boards[boardID]) { - return; - } - delete this.data.boards[boardID][threadID]; - this.deleteIfEmpty({ - boardID: boardID - }); - } else { - delete this.data.boards[boardID]; - } - return this.save(); + return this.save((function(_this) { + return function() { + var ref; + if (postID) { + if (!((ref = _this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { + return; + } + delete _this.data.boards[boardID][threadID][postID]; + return _this.deleteIfEmpty({ + boardID: boardID, + threadID: threadID + }); + } else if (threadID) { + if (!_this.data.boards[boardID]) { + return; + } + delete _this.data.boards[boardID][threadID]; + return _this.deleteIfEmpty({ + boardID: boardID + }); + } else { + return delete _this.data.boards[boardID]; + } + }; + })(this)); }; DataBoard.prototype.deleteIfEmpty = function(arg) { @@ -5668,45 +5724,59 @@ DataBoard = (function() { }; DataBoard.prototype.set = function(data, cb) { - $.forceSync(this.key); - return this.setUnsafe(data, cb); + return this.save((function(_this) { + return function() { + return _this.setUnsafe(data); + }; + })(this), cb); }; - DataBoard.prototype.setUnsafe = function(arg, cb) { + DataBoard.prototype.setUnsafe = function(arg) { var base, base1, base2, boardID, postID, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val; if (postID !== void 0) { - ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; + return ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; } else if (threadID !== void 0) { - ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; + return ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; } else { - this.data.boards[boardID] = val; + return this.data.boards[boardID] = val; } - return this.save(cb); }; DataBoard.prototype.extend = function(arg, cb) { - var boardID, i, key, len, oldVal, postID, ref, rm, threadID, val; + var boardID, postID, rm, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val, rm = arg.rm; - $.forceSync(this.key); - oldVal = this.get({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: {} - }); - ref = rm || []; - for (i = 0, len = ref.length; i < len; i++) { - key = ref[i]; - delete oldVal[key]; - } - $.extend(oldVal, val); - return this.setUnsafe({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: oldVal - }, cb); + return this.save((function(_this) { + return function() { + var i, key, len, oldVal, ref; + oldVal = _this.get({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: {} + }); + ref = rm || []; + for (i = 0, len = ref.length; i < len; i++) { + key = ref[i]; + delete oldVal[key]; + } + $.extend(oldVal, val); + return _this.setUnsafe({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: oldVal + }); + }; + })(this), cb); + }; + + DataBoard.prototype.setLastChecked = function() { + return this.save((function(_this) { + return function() { + return _this.data.lastChecked = Date.now(); + }; + })(this)); }; DataBoard.prototype.get = function(arg) { @@ -5732,13 +5802,8 @@ DataBoard = (function() { return val || defaultValue; }; - DataBoard.prototype.forceSync = function() { - return $.forceSync(this.key); - }; - DataBoard.prototype.clean = function() { var boardID, now, ref, ref1, val; - $.forceSync(this.key); ref = this.data.boards; for (boardID in ref) { val = ref[boardID]; @@ -5804,7 +5869,7 @@ DataBoard = (function() { this.deleteIfEmpty({ boardID: boardID }); - return this.save(); + return $.set(this.key, this.data); }; DataBoard.prototype.onSync = function(data) { @@ -19331,8 +19396,7 @@ ThreadWatcher = (function() { now = Date.now(); if (!((now - interval < (ref = db.data.lastChecked || 0) && ref <= now))) { ThreadWatcher.fetchAllStatus(); - db.data.lastChecked = now; - db.save(); + db.setLastChecked(); } return ThreadWatcher.timeout = setTimeout(ThreadWatcher.fetchAuto, interval); }, @@ -19344,19 +19408,26 @@ ThreadWatcher = (function() { } }, fetchAllStatus: function() { - var i, len, ref, thread, threads; - ThreadWatcher.db.forceSync(); - ThreadWatcher.unreaddb.forceSync(); - if ((ref = QuoteYou.db) != null) { - ref.forceSync(); - } - if (!(threads = ThreadWatcher.getAll()).length) { - return; - } - for (i = 0, len = threads.length; i < len; i++) { - thread = threads[i]; - ThreadWatcher.fetchStatus(thread); + var db, dbs, i, len, n, results; + dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(function(x) { + return x; + }); + n = 0; + results = []; + for (i = 0, len = dbs.length; i < len; i++) { + db = dbs[i]; + results.push(db.forceSync(function() { + var j, len1, thread, threads; + if ((++n) === dbs.length) { + threads = ThreadWatcher.getAll(); + for (j = 0, len1 = threads.length; j < len1; j++) { + thread = threads[j]; + ThreadWatcher.fetchStatus(thread); + } + } + })); } + return results; }, fetchStatus: function(thread, force) { var boardID, data, req, threadID; @@ -24281,9 +24352,11 @@ QuoteYou = (function() { return Conf['Remember Your Posts'] = enabled; }); $.on(d, 'QRPostSuccessful', function(e) { - var boardID, postID, ref, threadID; - $.forceSync('Remember Your Posts'); - if (Conf['Remember Your Posts']) { + return $.get('Remember Your Posts', Conf['Remember Your Posts'], function(items) { + var boardID, postID, ref, threadID; + if (!items['Remember Your Posts']) { + return; + } ref = e.detail, boardID = ref.boardID, threadID = ref.threadID, postID = ref.postID; return QuoteYou.db.set({ boardID: boardID, @@ -24291,7 +24364,7 @@ QuoteYou = (function() { postID: postID, val: true }); - } + }); }); if ((ref = g.VIEW) !== 'index' && ref !== 'thread' && ref !== 'archive') { return; diff --git a/builds/4chan-X-noupdate.crx b/builds/4chan-X-noupdate.crx index b1dd654fe..4ffed1809 100644 Binary files a/builds/4chan-X-noupdate.crx and b/builds/4chan-X-noupdate.crx differ diff --git a/builds/4chan-X-noupdate.user.js b/builds/4chan-X-noupdate.user.js index 8bfe0dce8..b8bfd145a 100644 --- a/builds/4chan-X-noupdate.user.js +++ b/builds/4chan-X-noupdate.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.13.14.12 +// @version 1.13.15.0 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -159,7 +159,7 @@ docSet = function() { }; g = { - VERSION: '1.13.14.12', + VERSION: '1.13.15.0', NAMESPACE: '4chan X.', boards: {} }; @@ -5621,35 +5621,91 @@ DataBoard = (function() { $.on(d, '4chanXInitFinished', init); } - DataBoard.prototype.save = function(cb) { - return $.set(this.key, this.data, cb); + DataBoard.prototype.changes = []; + + DataBoard.prototype.save = function(change, cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + change(); + changes = this.changes; + changes.push(change); + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + return $.set(_this.key, _this.data, function() { + _this.changes = []; + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }); + }; + })(this)); + }; + + DataBoard.prototype.forceSync = function(cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + changes = this.changes; + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }; + })(this)); }; DataBoard.prototype["delete"] = function(arg) { - var boardID, postID, ref, threadID; + var boardID, postID, threadID; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID; - $.forceSync(this.key); - if (postID) { - if (!((ref = this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { - return; - } - delete this.data.boards[boardID][threadID][postID]; - this.deleteIfEmpty({ - boardID: boardID, - threadID: threadID - }); - } else if (threadID) { - if (!this.data.boards[boardID]) { - return; - } - delete this.data.boards[boardID][threadID]; - this.deleteIfEmpty({ - boardID: boardID - }); - } else { - delete this.data.boards[boardID]; - } - return this.save(); + return this.save((function(_this) { + return function() { + var ref; + if (postID) { + if (!((ref = _this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { + return; + } + delete _this.data.boards[boardID][threadID][postID]; + return _this.deleteIfEmpty({ + boardID: boardID, + threadID: threadID + }); + } else if (threadID) { + if (!_this.data.boards[boardID]) { + return; + } + delete _this.data.boards[boardID][threadID]; + return _this.deleteIfEmpty({ + boardID: boardID + }); + } else { + return delete _this.data.boards[boardID]; + } + }; + })(this)); }; DataBoard.prototype.deleteIfEmpty = function(arg) { @@ -5668,45 +5724,59 @@ DataBoard = (function() { }; DataBoard.prototype.set = function(data, cb) { - $.forceSync(this.key); - return this.setUnsafe(data, cb); + return this.save((function(_this) { + return function() { + return _this.setUnsafe(data); + }; + })(this), cb); }; - DataBoard.prototype.setUnsafe = function(arg, cb) { + DataBoard.prototype.setUnsafe = function(arg) { var base, base1, base2, boardID, postID, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val; if (postID !== void 0) { - ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; + return ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; } else if (threadID !== void 0) { - ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; + return ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; } else { - this.data.boards[boardID] = val; + return this.data.boards[boardID] = val; } - return this.save(cb); }; DataBoard.prototype.extend = function(arg, cb) { - var boardID, i, key, len, oldVal, postID, ref, rm, threadID, val; + var boardID, postID, rm, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val, rm = arg.rm; - $.forceSync(this.key); - oldVal = this.get({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: {} - }); - ref = rm || []; - for (i = 0, len = ref.length; i < len; i++) { - key = ref[i]; - delete oldVal[key]; - } - $.extend(oldVal, val); - return this.setUnsafe({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: oldVal - }, cb); + return this.save((function(_this) { + return function() { + var i, key, len, oldVal, ref; + oldVal = _this.get({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: {} + }); + ref = rm || []; + for (i = 0, len = ref.length; i < len; i++) { + key = ref[i]; + delete oldVal[key]; + } + $.extend(oldVal, val); + return _this.setUnsafe({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: oldVal + }); + }; + })(this), cb); + }; + + DataBoard.prototype.setLastChecked = function() { + return this.save((function(_this) { + return function() { + return _this.data.lastChecked = Date.now(); + }; + })(this)); }; DataBoard.prototype.get = function(arg) { @@ -5732,13 +5802,8 @@ DataBoard = (function() { return val || defaultValue; }; - DataBoard.prototype.forceSync = function() { - return $.forceSync(this.key); - }; - DataBoard.prototype.clean = function() { var boardID, now, ref, ref1, val; - $.forceSync(this.key); ref = this.data.boards; for (boardID in ref) { val = ref[boardID]; @@ -5804,7 +5869,7 @@ DataBoard = (function() { this.deleteIfEmpty({ boardID: boardID }); - return this.save(); + return $.set(this.key, this.data); }; DataBoard.prototype.onSync = function(data) { @@ -19331,8 +19396,7 @@ ThreadWatcher = (function() { now = Date.now(); if (!((now - interval < (ref = db.data.lastChecked || 0) && ref <= now))) { ThreadWatcher.fetchAllStatus(); - db.data.lastChecked = now; - db.save(); + db.setLastChecked(); } return ThreadWatcher.timeout = setTimeout(ThreadWatcher.fetchAuto, interval); }, @@ -19344,19 +19408,26 @@ ThreadWatcher = (function() { } }, fetchAllStatus: function() { - var i, len, ref, thread, threads; - ThreadWatcher.db.forceSync(); - ThreadWatcher.unreaddb.forceSync(); - if ((ref = QuoteYou.db) != null) { - ref.forceSync(); - } - if (!(threads = ThreadWatcher.getAll()).length) { - return; - } - for (i = 0, len = threads.length; i < len; i++) { - thread = threads[i]; - ThreadWatcher.fetchStatus(thread); + var db, dbs, i, len, n, results; + dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(function(x) { + return x; + }); + n = 0; + results = []; + for (i = 0, len = dbs.length; i < len; i++) { + db = dbs[i]; + results.push(db.forceSync(function() { + var j, len1, thread, threads; + if ((++n) === dbs.length) { + threads = ThreadWatcher.getAll(); + for (j = 0, len1 = threads.length; j < len1; j++) { + thread = threads[j]; + ThreadWatcher.fetchStatus(thread); + } + } + })); } + return results; }, fetchStatus: function(thread, force) { var boardID, data, req, threadID; @@ -24281,9 +24352,11 @@ QuoteYou = (function() { return Conf['Remember Your Posts'] = enabled; }); $.on(d, 'QRPostSuccessful', function(e) { - var boardID, postID, ref, threadID; - $.forceSync('Remember Your Posts'); - if (Conf['Remember Your Posts']) { + return $.get('Remember Your Posts', Conf['Remember Your Posts'], function(items) { + var boardID, postID, ref, threadID; + if (!items['Remember Your Posts']) { + return; + } ref = e.detail, boardID = ref.boardID, threadID = ref.threadID, postID = ref.postID; return QuoteYou.db.set({ boardID: boardID, @@ -24291,7 +24364,7 @@ QuoteYou = (function() { postID: postID, val: true }); - } + }); }); if ((ref = g.VIEW) !== 'index' && ref !== 'thread' && ref !== 'archive') { return; diff --git a/builds/4chan-X.crx b/builds/4chan-X.crx index 5a9cb9719..d995b7206 100644 Binary files a/builds/4chan-X.crx and b/builds/4chan-X.crx differ diff --git a/builds/4chan-X.meta.js b/builds/4chan-X.meta.js index b09825048..f990f4b32 100644 --- a/builds/4chan-X.meta.js +++ b/builds/4chan-X.meta.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.13.14.12 +// @version 1.13.15.0 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 205bdb8d0..0684de491 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name 4chan X -// @version 1.13.14.12 +// @version 1.13.15.0 // @minGMVer 1.14 // @minFFVer 26 // @namespace 4chan-X @@ -159,7 +159,7 @@ docSet = function() { }; g = { - VERSION: '1.13.14.12', + VERSION: '1.13.15.0', NAMESPACE: '4chan X.', boards: {} }; @@ -5621,35 +5621,91 @@ DataBoard = (function() { $.on(d, '4chanXInitFinished', init); } - DataBoard.prototype.save = function(cb) { - return $.set(this.key, this.data, cb); + DataBoard.prototype.changes = []; + + DataBoard.prototype.save = function(change, cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + change(); + changes = this.changes; + changes.push(change); + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + return $.set(_this.key, _this.data, function() { + _this.changes = []; + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }); + }; + })(this)); + }; + + DataBoard.prototype.forceSync = function(cb) { + var changes, snapshot1; + snapshot1 = JSON.stringify(this.data); + changes = this.changes; + return $.get(this.key, { + boards: {} + }, (function(_this) { + return function(items) { + var c, i, len, snapshot2; + _this.data = items[_this.key]; + snapshot2 = JSON.stringify(_this.data); + for (i = 0, len = changes.length; i < len; i++) { + c = changes[i]; + c(); + } + if (snapshot1 !== snapshot2) { + if (typeof _this.sync === "function") { + _this.sync(); + } + } + return typeof cb === "function" ? cb() : void 0; + }; + })(this)); }; DataBoard.prototype["delete"] = function(arg) { - var boardID, postID, ref, threadID; + var boardID, postID, threadID; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID; - $.forceSync(this.key); - if (postID) { - if (!((ref = this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { - return; - } - delete this.data.boards[boardID][threadID][postID]; - this.deleteIfEmpty({ - boardID: boardID, - threadID: threadID - }); - } else if (threadID) { - if (!this.data.boards[boardID]) { - return; - } - delete this.data.boards[boardID][threadID]; - this.deleteIfEmpty({ - boardID: boardID - }); - } else { - delete this.data.boards[boardID]; - } - return this.save(); + return this.save((function(_this) { + return function() { + var ref; + if (postID) { + if (!((ref = _this.data.boards[boardID]) != null ? ref[threadID] : void 0)) { + return; + } + delete _this.data.boards[boardID][threadID][postID]; + return _this.deleteIfEmpty({ + boardID: boardID, + threadID: threadID + }); + } else if (threadID) { + if (!_this.data.boards[boardID]) { + return; + } + delete _this.data.boards[boardID][threadID]; + return _this.deleteIfEmpty({ + boardID: boardID + }); + } else { + return delete _this.data.boards[boardID]; + } + }; + })(this)); }; DataBoard.prototype.deleteIfEmpty = function(arg) { @@ -5668,45 +5724,59 @@ DataBoard = (function() { }; DataBoard.prototype.set = function(data, cb) { - $.forceSync(this.key); - return this.setUnsafe(data, cb); + return this.save((function(_this) { + return function() { + return _this.setUnsafe(data); + }; + })(this), cb); }; - DataBoard.prototype.setUnsafe = function(arg, cb) { + DataBoard.prototype.setUnsafe = function(arg) { var base, base1, base2, boardID, postID, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val; if (postID !== void 0) { - ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; + return ((base = ((base1 = this.data.boards)[boardID] || (base1[boardID] = {})))[threadID] || (base[threadID] = {}))[postID] = val; } else if (threadID !== void 0) { - ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; + return ((base2 = this.data.boards)[boardID] || (base2[boardID] = {}))[threadID] = val; } else { - this.data.boards[boardID] = val; + return this.data.boards[boardID] = val; } - return this.save(cb); }; DataBoard.prototype.extend = function(arg, cb) { - var boardID, i, key, len, oldVal, postID, ref, rm, threadID, val; + var boardID, postID, rm, threadID, val; boardID = arg.boardID, threadID = arg.threadID, postID = arg.postID, val = arg.val, rm = arg.rm; - $.forceSync(this.key); - oldVal = this.get({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: {} - }); - ref = rm || []; - for (i = 0, len = ref.length; i < len; i++) { - key = ref[i]; - delete oldVal[key]; - } - $.extend(oldVal, val); - return this.setUnsafe({ - boardID: boardID, - threadID: threadID, - postID: postID, - val: oldVal - }, cb); + return this.save((function(_this) { + return function() { + var i, key, len, oldVal, ref; + oldVal = _this.get({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: {} + }); + ref = rm || []; + for (i = 0, len = ref.length; i < len; i++) { + key = ref[i]; + delete oldVal[key]; + } + $.extend(oldVal, val); + return _this.setUnsafe({ + boardID: boardID, + threadID: threadID, + postID: postID, + val: oldVal + }); + }; + })(this), cb); + }; + + DataBoard.prototype.setLastChecked = function() { + return this.save((function(_this) { + return function() { + return _this.data.lastChecked = Date.now(); + }; + })(this)); }; DataBoard.prototype.get = function(arg) { @@ -5732,13 +5802,8 @@ DataBoard = (function() { return val || defaultValue; }; - DataBoard.prototype.forceSync = function() { - return $.forceSync(this.key); - }; - DataBoard.prototype.clean = function() { var boardID, now, ref, ref1, val; - $.forceSync(this.key); ref = this.data.boards; for (boardID in ref) { val = ref[boardID]; @@ -5804,7 +5869,7 @@ DataBoard = (function() { this.deleteIfEmpty({ boardID: boardID }); - return this.save(); + return $.set(this.key, this.data); }; DataBoard.prototype.onSync = function(data) { @@ -19331,8 +19396,7 @@ ThreadWatcher = (function() { now = Date.now(); if (!((now - interval < (ref = db.data.lastChecked || 0) && ref <= now))) { ThreadWatcher.fetchAllStatus(); - db.data.lastChecked = now; - db.save(); + db.setLastChecked(); } return ThreadWatcher.timeout = setTimeout(ThreadWatcher.fetchAuto, interval); }, @@ -19344,19 +19408,26 @@ ThreadWatcher = (function() { } }, fetchAllStatus: function() { - var i, len, ref, thread, threads; - ThreadWatcher.db.forceSync(); - ThreadWatcher.unreaddb.forceSync(); - if ((ref = QuoteYou.db) != null) { - ref.forceSync(); - } - if (!(threads = ThreadWatcher.getAll()).length) { - return; - } - for (i = 0, len = threads.length; i < len; i++) { - thread = threads[i]; - ThreadWatcher.fetchStatus(thread); + var db, dbs, i, len, n, results; + dbs = [ThreadWatcher.db, ThreadWatcher.unreaddb, QuoteYou.db].filter(function(x) { + return x; + }); + n = 0; + results = []; + for (i = 0, len = dbs.length; i < len; i++) { + db = dbs[i]; + results.push(db.forceSync(function() { + var j, len1, thread, threads; + if ((++n) === dbs.length) { + threads = ThreadWatcher.getAll(); + for (j = 0, len1 = threads.length; j < len1; j++) { + thread = threads[j]; + ThreadWatcher.fetchStatus(thread); + } + } + })); } + return results; }, fetchStatus: function(thread, force) { var boardID, data, req, threadID; @@ -24281,9 +24352,11 @@ QuoteYou = (function() { return Conf['Remember Your Posts'] = enabled; }); $.on(d, 'QRPostSuccessful', function(e) { - var boardID, postID, ref, threadID; - $.forceSync('Remember Your Posts'); - if (Conf['Remember Your Posts']) { + return $.get('Remember Your Posts', Conf['Remember Your Posts'], function(items) { + var boardID, postID, ref, threadID; + if (!items['Remember Your Posts']) { + return; + } ref = e.detail, boardID = ref.boardID, threadID = ref.threadID, postID = ref.postID; return QuoteYou.db.set({ boardID: boardID, @@ -24291,7 +24364,7 @@ QuoteYou = (function() { postID: postID, val: true }); - } + }); }); if ((ref = g.VIEW) !== 'index' && ref !== 'thread' && ref !== 'archive') { return; diff --git a/builds/4chan-X.zip b/builds/4chan-X.zip index c28c71d91..d1f79560b 100644 Binary files a/builds/4chan-X.zip and b/builds/4chan-X.zip differ diff --git a/builds/updates-beta.json b/builds/updates-beta.json index 970ff8001..9ce06f749 100644 --- a/builds/updates-beta.json +++ b/builds/updates-beta.json @@ -3,7 +3,7 @@ "4chan-x@4chan-x.net": { "updates": [ { - "version": "1.13.14.12", + "version": "1.13.15.0", "update_link": "https://www.4chan-x.net/builds/4chan-X-beta.crx" } ] diff --git a/builds/updates-beta.xml b/builds/updates-beta.xml index e64ceeb37..540944d09 100644 --- a/builds/updates-beta.xml +++ b/builds/updates-beta.xml @@ -1,7 +1,7 @@ - + diff --git a/builds/updates.json b/builds/updates.json index caeb93f16..7df4cc049 100644 --- a/builds/updates.json +++ b/builds/updates.json @@ -3,7 +3,7 @@ "4chan-x@4chan-x.net": { "updates": [ { - "version": "1.13.14.12", + "version": "1.13.15.0", "update_link": "https://www.4chan-x.net/builds/4chan-X.crx" } ] diff --git a/builds/updates.xml b/builds/updates.xml index fdfa326ad..ace0461b1 100644 --- a/builds/updates.xml +++ b/builds/updates.xml @@ -1,7 +1,7 @@ - + diff --git a/version.json b/version.json index 8701023af..5124a6cc5 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "version": "1.13.14.12", - "date": "2017-12-10T05:43:12.525Z" + "version": "1.13.15.0", + "date": "2017-12-11T19:32:54.527Z" } \ No newline at end of file