2013-07-21 21:12:30 -04:00
|
|
|
|
/*
|
|
|
|
|
* hide-threads.js
|
|
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/hide-threads.js
|
|
|
|
|
*
|
|
|
|
|
* Released under the MIT license
|
|
|
|
|
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-20 03:04:19 -05:00
|
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2013-07-21 21:12:30 -04:00
|
|
|
|
*
|
|
|
|
|
* Usage:
|
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
|
* $config['additional_javascript'][] = 'js/hide-threads.js';
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
2013-07-22 23:29:24 -04:00
|
|
|
|
if (active_page != "index" && active_page != "ukko")
|
2013-07-21 21:12:30 -04:00
|
|
|
|
return; // not index
|
2013-07-22 23:29:24 -04:00
|
|
|
|
|
2013-07-21 21:12:30 -04:00
|
|
|
|
if (!localStorage.hiddenthreads)
|
|
|
|
|
localStorage.hiddenthreads = '{}';
|
|
|
|
|
|
|
|
|
|
// Load data from HTML5 localStorage
|
|
|
|
|
var hidden_data = JSON.parse(localStorage.hiddenthreads);
|
|
|
|
|
|
|
|
|
|
var store_data = function() {
|
|
|
|
|
localStorage.hiddenthreads = JSON.stringify(hidden_data);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Delete old hidden threads (7+ days old)
|
|
|
|
|
for (var key in hidden_data) {
|
|
|
|
|
for (var id in hidden_data[key]) {
|
|
|
|
|
if (hidden_data[key][id] < Math.round(Date.now() / 1000) - 60 * 60 * 24 * 7) {
|
|
|
|
|
delete hidden_data[key][id];
|
|
|
|
|
store_data();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-16 07:51:18 -04:00
|
|
|
|
|
2016-05-06 09:03:53 -04:00
|
|
|
|
var fields_to_hide = 'div.file,div.post,div.video-container,video,iframe,img:not(.unanimated),canvas,p.fileinfo,a.hide-thread-link,div.new-posts,br';
|
2013-07-21 21:12:30 -04:00
|
|
|
|
|
2013-07-27 00:57:12 -04:00
|
|
|
|
var do_hide_threads = function() {
|
2013-07-21 21:12:30 -04:00
|
|
|
|
var id = $(this).children('p.intro').children('a.post_no:eq(1)').text();
|
|
|
|
|
var thread_container = $(this).parent();
|
2013-07-22 23:33:02 -04:00
|
|
|
|
|
2013-07-22 23:29:24 -04:00
|
|
|
|
var board = thread_container.data("board");
|
|
|
|
|
|
|
|
|
|
if (!hidden_data[board]) {
|
|
|
|
|
hidden_data[board] = {}; // id : timestamp
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-22 10:26:14 -04:00
|
|
|
|
$('<a class="hide-thread-link" style="float:left;margin-right:5px" href="javascript:void(0)">[–]</a><span> </span>')
|
2013-07-27 00:57:12 -04:00
|
|
|
|
.insertBefore(thread_container.find(':not(h2,h2 *):first'))
|
2013-07-21 21:12:30 -04:00
|
|
|
|
.click(function() {
|
|
|
|
|
hidden_data[board][id] = Math.round(Date.now() / 1000);
|
|
|
|
|
store_data();
|
|
|
|
|
|
2014-04-16 07:51:18 -04:00
|
|
|
|
thread_container.find(fields_to_hide).hide();
|
2013-07-21 21:12:30 -04:00
|
|
|
|
|
|
|
|
|
var hidden_div = thread_container.find('div.post.op > p.intro').clone();
|
|
|
|
|
hidden_div.addClass('thread-hidden');
|
2013-07-26 15:31:20 -04:00
|
|
|
|
hidden_div.find('a[href]:not([href$=".html"]),input').remove();
|
|
|
|
|
hidden_div.html(hidden_div.html().replace(' [] ', ' '));
|
2013-07-23 09:20:37 -04:00
|
|
|
|
hidden_div.html(hidden_div.html().replace(' [] ', ' '));
|
2013-07-21 21:12:30 -04:00
|
|
|
|
|
2013-07-26 15:31:20 -04:00
|
|
|
|
$('<a class="unhide-thread-link" style="float:left;margin-right:5px;margin-left:0px;" href="javascript:void(0)">[+]</a><span> </span>')
|
|
|
|
|
.insertBefore(hidden_div.find(':first'))
|
2013-07-21 21:12:30 -04:00
|
|
|
|
.click(function() {
|
|
|
|
|
delete hidden_data[board][id];
|
|
|
|
|
store_data();
|
2014-04-16 07:51:18 -04:00
|
|
|
|
thread_container.find(fields_to_hide).show();
|
2014-04-18 15:04:47 -04:00
|
|
|
|
thread_container.find(".hidden").hide();
|
2013-07-21 21:12:30 -04:00
|
|
|
|
$(this).remove();
|
|
|
|
|
hidden_div.remove();
|
|
|
|
|
});
|
|
|
|
|
|
2013-07-27 00:57:12 -04:00
|
|
|
|
hidden_div.insertAfter(thread_container.find(':not(h2,h2 *):first'));
|
2013-07-21 21:12:30 -04:00
|
|
|
|
});
|
|
|
|
|
if (hidden_data[board][id])
|
|
|
|
|
thread_container.find('.hide-thread-link').click();
|
2013-07-27 00:57:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('div.post.op').each(do_hide_threads);
|
|
|
|
|
|
2014-01-21 13:25:11 -05:00
|
|
|
|
$(document).on('new_post', function(e, post) {
|
2013-07-27 00:57:12 -04:00
|
|
|
|
do_hide_threads.call($(post).find('div.post.op')[0]);
|
2013-07-21 21:12:30 -04:00
|
|
|
|
});
|
|
|
|
|
});
|