Cooldown with the normal post form. close #149

This commit is contained in:
Nicolas Stepien 2011-06-26 03:25:30 +02:00
parent 1c9a0a6412
commit e6dc2f5a58
3 changed files with 77 additions and 14 deletions

View File

@ -1144,14 +1144,33 @@
};
cooldown = {
init: function() {
var input, time, _, _ref;
if (location.search) {
_ref = location.search.match(/cooldown=(\d+)/), _ = _ref[0], time = _ref[1];
if ($.getValue(g.BOARD + '/cooldown', 0 < time)) {
$.setValue(g.BOARD + '/cooldown', time);
}
}
if (Date.now() < $.getValue(g.BOARD + '/cooldown', 0)) {
cooldown.start();
}
return $.bind(window, 'storage', function(e) {
$.bind(window, 'storage', function(e) {
if (e.key === ("" + NAMESPACE + g.BOARD + "/cooldown")) {
return cooldown.start();
}
});
input = $('.postarea input[name=email]');
if (/sage/i.test(input.value)) {
$('.postarea form').action = "http://sys.4chan.org/" + g.BOARD + "/post?sage";
}
return $.bind(input, 'keyup', cooldown.sage);
},
sage: function() {
if (/sage/i.test(this.value)) {
return $('.postarea form').action = "http://sys.4chan.org/" + g.BOARD + "/post?sage";
} else {
return $('.postarea form').action = "http://sys.4chan.org/" + g.BOARD + "/post";
}
},
start: function() {
var submit, _i, _len, _ref;
@ -1345,7 +1364,7 @@
return qr.autohide.set();
},
sys: function() {
var c, id, otoNoko, otoNokoPattern, otoWatchPattern, recaptcha, thread, _, _ref;
var c, duration, id, noko, otoNoko, otoWatch, recaptcha, thread, _, _ref;
if (recaptcha = $('#recaptcha_response_field')) {
$.bind(recaptcha, 'keydown', Recaptcha.listener);
return;
@ -1365,17 +1384,30 @@
c = $('b').lastChild;
if (c.nodeType === 8) {
_ref = c.textContent.match(/thread:(\d+),no:(\d+)/), _ = _ref[0], thread = _ref[1], id = _ref[2];
otoNokoPattern = new RegExp("" + NAMESPACE + "auto_noko=true");
otoWatchPattern = new RegExp("" + NAMESPACE + "auto_watch=true");
otoNoko = otoNokoPattern.test(d.cookie);
otoNoko = new RegExp("" + NAMESPACE + "auto_noko=true");
otoWatch = new RegExp("" + NAMESPACE + "auto_watch=true");
cooldown = new RegExp("" + NAMESPACE + "cooldown=true");
noko = otoNoko.test(d.cookie);
if (thread === '0') {
if (otoWatchPattern.test(d.cookie)) {
if (otoWatch.test(d.cookie)) {
return window.location = "http://boards.4chan.org/" + g.BOARD + "/res/" + id + "#watch";
} else if (otoNoko) {
} else if (noko) {
return window.location = "http://boards.4chan.org/" + g.BOARD + "/res/" + id;
}
} else if (otoNoko) {
} else if (cooldown.test(d.cookie)) {
duration = Date.now() + 30000;
if (/sage/.test(location.search)) {
duration += 30000;
}
if (noko) {
return window.location = "http://boards.4chan.org/" + g.BOARD + "/res/" + thread + "?cooldown=" + duration + "#" + id;
} else {
return window.location = "http://boards.4chan.org/" + g.BOARD + "?cooldown=" + duration;
}
} else if (noko) {
return window.location = "http://boards.4chan.org/" + g.BOARD + "/res/" + thread + "#" + id;
} else {
return window.location = "http://boards.4chan.org/" + g.BOARD;
}
}
}
@ -2676,6 +2708,9 @@
}
if ($.config('Cooldown')) {
cooldown.init();
d.cookie = "" + NAMESPACE + "cooldown=true;path=/;domain=.4chan.org";
} else {
d.cookie = "" + NAMESPACE + "cooldown=false;path=/;domain=.4chan.org";
}
if ($.config('Image Expansion')) {
imgExpand.init();

View File

@ -4,6 +4,7 @@
- optional auto noko
- fix options centering on Opera
- fix append '#watch' only when auto watch is enabled
- fix cooldown with the normal post form
- aeosynth:
- keep options dialog at constant size
- drop firefox 3.6 support (again...)

View File

@ -911,9 +911,23 @@ options =
cooldown =
init: ->
if location.search
[_, time] = location.search.match /cooldown=(\d+)/
$.setValue g.BOARD+'/cooldown', time if $.getValue g.BOARD+'/cooldown', 0 < time
cooldown.start() if Date.now() < $.getValue g.BOARD+'/cooldown', 0
$.bind window, 'storage', (e) -> cooldown.start() if e.key is "#{NAMESPACE}#{g.BOARD}/cooldown"
input = $('.postarea input[name=email]')
if /sage/i.test input.value
$('.postarea form').action = "http://sys.4chan.org/#{g.BOARD}/post?sage"
$.bind input, 'keyup', cooldown.sage
sage: ->
if /sage/i.test @value
$('.postarea form').action = "http://sys.4chan.org/#{g.BOARD}/post?sage"
else
$('.postarea form').action = "http://sys.4chan.org/#{g.BOARD}/post"
start: ->
cooldown.duration = Math.ceil ($.getValue(g.BOARD+'/cooldown', 0) - Date.now()) / 1000
for submit in $$ '#com_submit'
@ -1112,16 +1126,26 @@ qr =
c = $('b').lastChild
if c.nodeType is 8 #comment node
[_, thread, id] = c.textContent.match(/thread:(\d+),no:(\d+)/)
otoNokoPattern = new RegExp "#{NAMESPACE}auto_noko=true"
otoWatchPattern = new RegExp "#{NAMESPACE}auto_watch=true"
otoNoko = otoNokoPattern.test d.cookie
otoNoko = new RegExp "#{NAMESPACE}auto_noko=true"
otoWatch = new RegExp "#{NAMESPACE}auto_watch=true"
cooldown = new RegExp "#{NAMESPACE}cooldown=true"
noko = otoNoko.test d.cookie
if thread is '0'
if otoWatchPattern.test d.cookie
if otoWatch.test d.cookie
window.location = "http://boards.4chan.org/#{g.BOARD}/res/#{id}#watch"
else if otoNoko
else if noko
window.location = "http://boards.4chan.org/#{g.BOARD}/res/#{id}"
else if otoNoko
else if cooldown.test d.cookie
duration = Date.now() + 30000
duration += 30000 if /sage/.test location.search
if noko
window.location = "http://boards.4chan.org/#{g.BOARD}/res/#{thread}?cooldown=#{duration}##{id}"
else
window.location = "http://boards.4chan.org/#{g.BOARD}?cooldown=#{duration}"
else if noko
window.location = "http://boards.4chan.org/#{g.BOARD}/res/#{thread}##{id}"
else
window.location = "http://boards.4chan.org/#{g.BOARD}"
threading =
init: ->
@ -2094,6 +2118,9 @@ main =
if $.config 'Cooldown'
cooldown.init()
d.cookie = "#{NAMESPACE}cooldown=true;path=/;domain=.4chan.org"
else
d.cookie = "#{NAMESPACE}cooldown=false;path=/;domain=.4chan.org"
if $.config 'Image Expansion'
imgExpand.init()