1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-02 12:57:35 +01:00

thread-watcher.js: format

This commit is contained in:
Zankaria 2024-09-30 22:00:33 +02:00 committed by Zankaria
parent 2ab6f371f7
commit a3d1fe4884

View File

@ -20,13 +20,17 @@ var watchlist = {};
*/
watchlist.render = function(reset) {
/* jshint eqnull:true */
if (reset == null) reset = false;
if (reset == null) {
reset = false;
}
/* jshint eqnull:false */
if (reset && $('#watchlist').length) $('#watchlist').remove();
var threads = [];
if (reset && $('#watchlist').length) {
$('#watchlist').remove();
}
let threads = [];
// Read the watchlist and create a new container for each thread.
JSON.parse(localStorage.watchlist).forEach(function(e, i) {
//look at line 69, that's what (e) is here.
// Look at line 69, that's what (e) is here.
threads.push('<div class="watchlist-inner" id="watchlist-'+i+'">' +
'<span>/'+e[0]+'/ - ' +
'<a href="'+e[3]+'">'+e[1].replace("thread_", _("Thread #"))+'</a>' +
@ -40,7 +44,7 @@ watchlist.render = function(reset) {
$('#watchlist').append(threads.join(''));
} else {
// If the watchlist has not yet been rendered, create it.
var menuStyle = getComputedStyle($('.boardlist')[0]);
let menuStyle = getComputedStyle($('.boardlist')[0]);
$((active_page == 'ukko') ? 'hr:first' : (active_page == 'catalog') ? 'body>span:first' : 'form[name="post"]').before(
$('<div id="watchlist">'+
'<div class="watchlist-controls">'+
@ -48,7 +52,8 @@ watchlist.render = function(reset) {
'<span><a id="clearGhosts">['+_('Clear Ghosts')+']</a></span>'+
'</div>'+
threads.join('')+
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor));
'</div>').css("background-color", menuStyle.backgroundColor).css("border", menuStyle.borderBottomWidth+" "+menuStyle.borderBottomStyle+" "+menuStyle.borderBottomColor)
);
}
return this;
};
@ -58,9 +63,10 @@ watchlist.render = function(reset) {
* @param {[Obj/Str]} sel [An unwrapped jquery selector.]
*/
watchlist.add = function(sel) {
var threadName, threadInfo;
let threadName;
let threadInfo;
var board_name = $(sel).parents('.thread').data('board');
let board_name = $(sel).parents('.thread').data('board');
if (active_page === 'thread') {
if ($('.subject').length) {
@ -69,12 +75,10 @@ watchlist.add = function(sel) {
} else { //Otherwise use the thread id.
threadName = $('.op').parent().attr('id');
}
//board name, thread name as defined above, current amount of posts, thread url
// Board name, thread name as defined above, current amount of posts, thread url
threadInfo = [board_name, threadName, $('.post').length, location.href];
} else if (active_page === 'index' || active_page === 'ukko') {
var postCount;
let postCount;
// Figure out the post count.
if ($(sel).parents('.op').children('.omitted').length) {
postCount = $(sel).parents('.op').children('.omitted').text().split(' ')[0];
@ -82,7 +86,7 @@ watchlist.add = function(sel) {
postCount = $(sel).parents('.op').siblings('.post').length+1;
}
// Grab the reply link.;
var threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
let threadLink = $(sel).siblings('a:not(.watchThread)').last().attr('href');
// Figure out the thread name. If anon, use the thread id.
if ($(sel).parent().find('.subject').length) {
threadName = $(sel).parent().find('.subject').text().substring(0,20);
@ -91,7 +95,6 @@ watchlist.add = function(sel) {
}
threadInfo = [board_name, threadName, postCount, threadLink];
} else {
alert('Functionality not yet implemented for this type of page.');
return this;
@ -102,7 +105,7 @@ watchlist.add = function(sel) {
return this;
}
var _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
let _watchlist = JSON.parse(localStorage.watchlist); //Read the watchlist
_watchlist.push(threadInfo); //Add the new watch item.
localStorage.watchlist = JSON.stringify(_watchlist); //Save the watchlist.
return this;
@ -113,7 +116,7 @@ watchlist.add = function(sel) {
* @param {[Int]} n [The index at which to remove.]
*/
watchlist.remove = function(n) {
var _watchlist = JSON.parse(localStorage.watchlist);
let _watchlist = JSON.parse(localStorage.watchlist);
_watchlist.splice(n, 1);
localStorage.watchlist = JSON.stringify(_watchlist);
return this;
@ -181,7 +184,7 @@ $(document).ready(function(){
// $('.watchlist-remove').on('click') won't work in case of re-renders and
// the page will need refreshing. This works around that.
$(document).on('click', '.watchlist-remove', function() {
var item = parseInt($(this).parent().attr('id').split('-')[1]);
let item = parseInt($(this).parent().attr('id').split('-')[1]);
watchlist.remove(item).render();
});
@ -196,6 +199,4 @@ $(document).ready(function(){
watchlist.exists(this);
});
});
});