From 8cd6598e003025326f8a419e7a10fae37de4dda8 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 26 Jan 2012 04:15:42 +0100 Subject: [PATCH] Auto Watch on thread creation. --- 4chan_x.user.js | 12 ++++++++++-- script.coffee | 12 +++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8b4e35663..a55f9494e 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1724,7 +1724,10 @@ $.set('qr.persona', persona); _ref = b.lastChild.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], postNumber = _ref[2]; if (thread === '0') { - window.open("/" + g.BOARD + "/res/" + postNumber, '_self'); + if (conf['Thread Watcher'] && conf['Auto Watch']) { + $.set('autoWatch', postNumber); + } + location.pathname = "/" + g.BOARD + "/res/" + postNumber; } else { qr.cooldown.auto = qr.replies.length > 1; qr.cooldown.set(/sage/i.test(reply.email) ? 60 : 30); @@ -2381,7 +2384,12 @@ $.on(favicon, 'click', watcher.cb.toggle); $.before(input, favicon); } - watcher.refresh(); + if (g.THREAD_ID === $.get('autoWatch', 0)) { + watcher.watch(g.THREAD_ID); + $["delete"]('autoWatch'); + } else { + watcher.refresh(); + } return $.on(window, 'storage', function(e) { if (e.key === ("" + NAMESPACE + "watched")) return watcher.refresh(); }); diff --git a/script.coffee b/script.coffee index 7fe68788e..f801898aa 100644 --- a/script.coffee +++ b/script.coffee @@ -1300,8 +1300,10 @@ qr = [_, thread, postNumber] = b.lastChild.textContent.match /thread:(\d+),no:(\d+)/ if thread is '0' # new thread + if conf['Thread Watcher'] and conf['Auto Watch'] + $.set 'autoWatch', postNumber # auto-noko - window.open "/#{g.BOARD}/res/#{postNumber}", '_self' + location.pathname = "/#{g.BOARD}/res/#{postNumber}" else # Enable auto-posting if we have stuff to post, disable it otherwise. qr.cooldown.auto = qr.replies.length > 1 @@ -1862,8 +1864,12 @@ watcher = $.on favicon, 'click', watcher.cb.toggle $.before input, favicon - #populate watcher, display watch buttons - watcher.refresh() + if g.THREAD_ID is $.get 'autoWatch', 0 + watcher.watch g.THREAD_ID + $.delete 'autoWatch' + else + #populate watcher, display watch buttons + watcher.refresh() $.on window, 'storage', (e) -> watcher.refresh() if e.key is "#{NAMESPACE}watched"