commit
c243a15c4d
72
4chan_x.js
72
4chan_x.js
@ -1464,56 +1464,56 @@
|
|||||||
};
|
};
|
||||||
watcher = {
|
watcher = {
|
||||||
init: function() {
|
init: function() {
|
||||||
var dialog, favicon, html, id, input, inputs, src, watched, watchedBoard, _i, _len, _results;
|
var dialog, favicon, html, input, inputs, _i, _len;
|
||||||
html = '<div class=move>Thread Watcher</div>';
|
html = '<div class=move>Thread Watcher</div>';
|
||||||
dialog = ui.dialog('watcher', {
|
dialog = ui.dialog('watcher', {
|
||||||
top: '50px',
|
top: '50px',
|
||||||
left: '0px'
|
left: '0px'
|
||||||
}, html);
|
}, html);
|
||||||
$.append(d.body, dialog);
|
$.append(d.body, dialog);
|
||||||
watched = $.getValue('watched', {});
|
|
||||||
watcher.refresh(watched);
|
|
||||||
watchedBoard = watched[g.BOARD] || {};
|
|
||||||
inputs = $$('form > input[value=delete], div.thread > input[value=delete]');
|
inputs = $$('form > input[value=delete], div.thread > input[value=delete]');
|
||||||
_results = [];
|
|
||||||
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
|
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
|
||||||
input = inputs[_i];
|
input = inputs[_i];
|
||||||
id = input.name;
|
|
||||||
if (id in watchedBoard) {
|
|
||||||
src = Favicon["default"];
|
|
||||||
} else {
|
|
||||||
src = Favicon.empty;
|
|
||||||
}
|
|
||||||
favicon = $.el('img', {
|
favicon = $.el('img', {
|
||||||
src: src,
|
|
||||||
className: 'favicon'
|
className: 'favicon'
|
||||||
});
|
});
|
||||||
$.bind(favicon, 'click', watcher.cb.toggle);
|
$.bind(favicon, 'click', watcher.cb.toggle);
|
||||||
_results.push($.before(input, favicon));
|
$.before(input, favicon);
|
||||||
}
|
}
|
||||||
return _results;
|
watcher.refresh($.getValue('watched', {}));
|
||||||
|
return setInterval((function() {
|
||||||
|
if (watcher.lastUpdated < $.getValue('watcher.lastUpdated', 0)) {
|
||||||
|
return watcher.refresh($.getValue('watched', {}));
|
||||||
|
}
|
||||||
|
}), 1000);
|
||||||
},
|
},
|
||||||
refresh: function(watched) {
|
refresh: function(watched) {
|
||||||
var board, div, id, props, _i, _len, _ref, _results;
|
var board, div, favicon, id, props, watchedBoard, _i, _j, _len, _len2, _ref, _ref2, _ref3;
|
||||||
_ref = $$('#watcher > div:not(.move)');
|
_ref = $$('#watcher > div:not(.move)');
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
div = _ref[_i];
|
div = _ref[_i];
|
||||||
$.remove(div);
|
$.remove(div);
|
||||||
}
|
}
|
||||||
_results = [];
|
|
||||||
for (board in watched) {
|
for (board in watched) {
|
||||||
_results.push((function() {
|
_ref2 = watched[board];
|
||||||
var _ref2, _results2;
|
for (id in _ref2) {
|
||||||
_ref2 = watched[board];
|
props = _ref2[id];
|
||||||
_results2 = [];
|
watcher.addLink(props, $('#watcher'));
|
||||||
for (id in _ref2) {
|
}
|
||||||
props = _ref2[id];
|
|
||||||
_results2.push(watcher.addLink(props, $('#watcher')));
|
|
||||||
}
|
|
||||||
return _results2;
|
|
||||||
})());
|
|
||||||
}
|
}
|
||||||
return _results;
|
watchedBoard = watched[g.BOARD] || {};
|
||||||
|
_ref3 = $$('img.favicon');
|
||||||
|
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
|
||||||
|
favicon = _ref3[_j];
|
||||||
|
id = favicon.nextSibling.name;
|
||||||
|
if (id in watchedBoard) {
|
||||||
|
favicon.src = Favicon["default"];
|
||||||
|
} else {
|
||||||
|
favicon.src = Favicon.empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$.setValue('watcher.lastUpdated', Date.now());
|
||||||
|
return watcher.lastUpdated = Date.now();
|
||||||
},
|
},
|
||||||
addLink: function(props, dialog) {
|
addLink: function(props, dialog) {
|
||||||
var div, link, x;
|
var div, link, x;
|
||||||
@ -1541,30 +1541,20 @@
|
|||||||
favicon = $('img.favicon', thread);
|
favicon = $('img.favicon', thread);
|
||||||
id = favicon.nextSibling.name;
|
id = favicon.nextSibling.name;
|
||||||
if (favicon.src === Favicon.empty) {
|
if (favicon.src === Favicon.empty) {
|
||||||
return watcher.watch(thread);
|
return watcher.watch(thread, id);
|
||||||
} else {
|
} else {
|
||||||
return watcher.unwatch(g.BOARD, id);
|
return watcher.unwatch(g.BOARD, id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
unwatch: function(board, id) {
|
unwatch: function(board, id) {
|
||||||
var favicon, input, watched;
|
var watched;
|
||||||
if (input = $("input[name=\"" + id + "\"]")) {
|
|
||||||
favicon = input.previousSibling;
|
|
||||||
favicon.src = Favicon.empty;
|
|
||||||
}
|
|
||||||
watched = $.getValue('watched', {});
|
watched = $.getValue('watched', {});
|
||||||
delete watched[board][id];
|
delete watched[board][id];
|
||||||
$.setValue('watched', watched);
|
$.setValue('watched', watched);
|
||||||
return watcher.refresh(watched);
|
return watcher.refresh(watched);
|
||||||
},
|
},
|
||||||
watch: function(thread) {
|
watch: function(thread, id) {
|
||||||
var favicon, id, props, tc, watched, _name;
|
var props, tc, watched, _name;
|
||||||
favicon = $('img.favicon', thread);
|
|
||||||
if (favicon.src === Favicon["default"]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
favicon.src = Favicon["default"];
|
|
||||||
id = favicon.nextSibling.name;
|
|
||||||
tc = $('span.filetitle', thread).textContent || $('blockquote', thread).textContent;
|
tc = $('span.filetitle', thread).textContent || $('blockquote', thread).textContent;
|
||||||
props = {
|
props = {
|
||||||
textContent: "/" + g.BOARD + "/ - " + tc.slice(0, 25),
|
textContent: "/" + g.BOARD + "/ - " + tc.slice(0, 25),
|
||||||
|
|||||||
@ -1167,31 +1167,37 @@ watcher =
|
|||||||
dialog = ui.dialog 'watcher', top: '50px', left: '0px', html
|
dialog = ui.dialog 'watcher', top: '50px', left: '0px', html
|
||||||
$.append d.body, dialog
|
$.append d.body, dialog
|
||||||
|
|
||||||
#populate watcher
|
|
||||||
watched = $.getValue 'watched', {}
|
|
||||||
watcher.refresh watched
|
|
||||||
|
|
||||||
#add watch buttons
|
#add watch buttons
|
||||||
watchedBoard = watched[g.BOARD] or {}
|
|
||||||
inputs = $$ 'form > input[value=delete], div.thread > input[value=delete]'
|
inputs = $$ 'form > input[value=delete], div.thread > input[value=delete]'
|
||||||
for input in inputs
|
for input in inputs
|
||||||
id = input.name
|
|
||||||
if id of watchedBoard
|
|
||||||
src = Favicon.default
|
|
||||||
else
|
|
||||||
src = Favicon.empty
|
|
||||||
favicon = $.el 'img',
|
favicon = $.el 'img',
|
||||||
src: src
|
|
||||||
className: 'favicon'
|
className: 'favicon'
|
||||||
$.bind favicon, 'click', watcher.cb.toggle
|
$.bind favicon, 'click', watcher.cb.toggle
|
||||||
$.before input, favicon
|
$.before input, favicon
|
||||||
|
|
||||||
|
#populate watcher, display watch buttons
|
||||||
|
watcher.refresh $.getValue 'watched', {}
|
||||||
|
|
||||||
|
setInterval (->
|
||||||
|
if watcher.lastUpdated < $.getValue 'watcher.lastUpdated', 0
|
||||||
|
watcher.refresh($.getValue 'watched', {})
|
||||||
|
), 1000
|
||||||
|
|
||||||
refresh: (watched) ->
|
refresh: (watched) ->
|
||||||
for div in $$ '#watcher > div:not(.move)'
|
for div in $$ '#watcher > div:not(.move)'
|
||||||
$.remove div
|
$.remove div
|
||||||
for board of watched
|
for board of watched
|
||||||
for id, props of watched[board]
|
for id, props of watched[board]
|
||||||
watcher.addLink props, $ '#watcher'
|
watcher.addLink props, $ '#watcher'
|
||||||
|
watchedBoard = watched[g.BOARD] or {}
|
||||||
|
for favicon in $$ 'img.favicon'
|
||||||
|
id = favicon.nextSibling.name
|
||||||
|
if id of watchedBoard
|
||||||
|
favicon.src = Favicon.default
|
||||||
|
else
|
||||||
|
favicon.src = Favicon.empty
|
||||||
|
$.setValue 'watcher.lastUpdated', Date.now()
|
||||||
|
watcher.lastUpdated = Date.now()
|
||||||
|
|
||||||
addLink: (props, dialog) ->
|
addLink: (props, dialog) ->
|
||||||
div = $.el 'div'
|
div = $.el 'div'
|
||||||
@ -1215,29 +1221,18 @@ watcher =
|
|||||||
favicon = $ 'img.favicon', thread
|
favicon = $ 'img.favicon', thread
|
||||||
id = favicon.nextSibling.name
|
id = favicon.nextSibling.name
|
||||||
if favicon.src == Favicon.empty
|
if favicon.src == Favicon.empty
|
||||||
watcher.watch thread
|
watcher.watch thread, id
|
||||||
else # favicon.src == Favicon.default
|
else # favicon.src == Favicon.default
|
||||||
watcher.unwatch g.BOARD, id
|
watcher.unwatch g.BOARD, id
|
||||||
|
|
||||||
unwatch: (board, id) ->
|
unwatch: (board, id) ->
|
||||||
if input = $ "input[name=\"#{id}\"]"
|
|
||||||
favicon = input.previousSibling
|
|
||||||
favicon.src = Favicon.empty
|
|
||||||
|
|
||||||
watched = $.getValue 'watched', {}
|
watched = $.getValue 'watched', {}
|
||||||
delete watched[board][id]
|
delete watched[board][id]
|
||||||
$.setValue 'watched', watched
|
$.setValue 'watched', watched
|
||||||
|
|
||||||
watcher.refresh watched
|
watcher.refresh watched
|
||||||
|
|
||||||
watch: (thread) ->
|
watch: (thread, id) ->
|
||||||
favicon = $ 'img.favicon', thread
|
|
||||||
|
|
||||||
#this happens if we try to auto-watch an already watched thread.
|
|
||||||
return if favicon.src is Favicon.default
|
|
||||||
|
|
||||||
favicon.src = Favicon.default
|
|
||||||
id = favicon.nextSibling.name
|
|
||||||
tc = $('span.filetitle', thread).textContent or $('blockquote', thread).textContent
|
tc = $('span.filetitle', thread).textContent or $('blockquote', thread).textContent
|
||||||
props =
|
props =
|
||||||
textContent: "/#{g.BOARD}/ - #{tc[...25]}"
|
textContent: "/#{g.BOARD}/ - #{tc[...25]}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user