post-filter.js catalog support
Removes hidden threads from catalog page Shift click on catalog to hide thread Improved word matching for simple comment and subject filter.
This commit is contained in:
parent
dc725641c3
commit
513c8f7b68
@ -6,26 +6,6 @@ if (active_page == 'catalog') $(function(){
|
|||||||
localStorage.catalog = JSON.stringify(catalog);
|
localStorage.catalog = JSON.stringify(catalog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localStorage.hiddenthreads) {
|
|
||||||
var hidden_data = JSON.parse(localStorage.hiddenthreads);
|
|
||||||
|
|
||||||
if (hidden_data[board_name] && !$.isEmptyObject(hidden_data[board_name])) {
|
|
||||||
$.each(hidden_data[board_name], function(k, v) {
|
|
||||||
$('a[href$="/'+k+'.html"]').parents('.mix').remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hidden_data = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).on('click', '.mix', function(e) {
|
|
||||||
if (e.shiftKey) {
|
|
||||||
hidden_data[board_name][$(this).data('id')] = Math.round(Date.now() / 1000);
|
|
||||||
$(this).remove();
|
|
||||||
localStorage.hiddenthreads = JSON.stringify(hidden_data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#sort_by").change(function(){
|
$("#sort_by").change(function(){
|
||||||
var value = this.value;
|
var value = this.value;
|
||||||
$('#Grid').mixItUp('sort', (value == "random" ? value : "sticky:desc " + value));
|
$('#Grid').mixItUp('sort', (value == "random" ? value : "sticky:desc " + value));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
if (active_page === 'thread' || active_page === 'index') {
|
if (active_page === 'thread' || active_page === 'index' || active_page === 'catalog') {
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
// returns blacklist object from storage
|
// returns blacklist object from storage
|
||||||
@ -408,13 +408,13 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
if (!forcedAnon && hasTrip)
|
if (!forcedAnon && hasTrip)
|
||||||
trip = $post.find('.trip').text();
|
trip = $post.find('.trip').text();
|
||||||
if (hasSub)
|
if (hasSub)
|
||||||
subject = ' '+ $post.find('.subject').text() +' ';
|
subject = $post.find('.subject').text();
|
||||||
|
|
||||||
array = $post.find('.body').contents().filter(function () {if ($(this).text() !== '') return true;}).toArray();
|
array = $post.find('.body').contents().filter(function () {if ($(this).text() !== '') return true;}).toArray();
|
||||||
array = $.map(array, function (ele) {
|
array = $.map(array, function (ele) {
|
||||||
return $(ele).text();
|
return $(ele).text();
|
||||||
});
|
});
|
||||||
comment = ' '+ array.join(' ') +' ';
|
comment = array.join(' ');
|
||||||
|
|
||||||
|
|
||||||
for (i = 0, length = list.generalFilter.length; i < length; i++) {
|
for (i = 0, length = list.generalFilter.length; i < length; i++) {
|
||||||
@ -430,7 +430,7 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'trip':
|
case 'trip':
|
||||||
if (!forcedAnon && pattern.test(trip)) {
|
if (!forcedAnon && hasTrip && pattern.test(trip)) {
|
||||||
$post.data('hiddenByTrip', true);
|
$post.data('hiddenByTrip', true);
|
||||||
hide(post);
|
hide(post);
|
||||||
}
|
}
|
||||||
@ -463,13 +463,15 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'sub':
|
case 'sub':
|
||||||
if (hasSub && subject.indexOf(' '+ rule.value +' ') != -1) {
|
pattern = new RegExp('\\b'+ rule.value+ '\\b');
|
||||||
|
if (hasSub && pattern.test(subject)) {
|
||||||
$post.data('hiddenBySubject', true);
|
$post.data('hiddenBySubject', true);
|
||||||
hide(post);
|
hide(post);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'com':
|
case 'com':
|
||||||
if (comment.indexOf(' '+ rule.value +' ') != -1) {
|
pattern = new RegExp('\\b'+ rule.value+ '\\b');
|
||||||
|
if (pattern.test(comment)) {
|
||||||
$post.data('hiddenByComment', true);
|
$post.data('hiddenByComment', true);
|
||||||
hide(post);
|
hide(post);
|
||||||
}
|
}
|
||||||
@ -502,43 +504,63 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
function filterPage(pageData) {
|
function filterPage(pageData) {
|
||||||
var list = getList();
|
var list = getList();
|
||||||
|
|
||||||
// empty the local and no-reply list
|
if (active_page != 'catalog') {
|
||||||
pageData.localList = [];
|
|
||||||
pageData.noReplyList = [];
|
|
||||||
|
|
||||||
$('.thread').each(function () {
|
// empty the local and no-reply list
|
||||||
var $thread = $(this);
|
pageData.localList = [];
|
||||||
// disregard the hidden threads constructed by post-hover.js
|
pageData.noReplyList = [];
|
||||||
if ($thread.css('display') == 'none')
|
|
||||||
|
$('.thread').each(function () {
|
||||||
|
var $thread = $(this);
|
||||||
|
// disregard the hidden threads constructed by post-hover.js
|
||||||
|
if ($thread.css('display') == 'none')
|
||||||
|
return;
|
||||||
|
|
||||||
|
var threadId = $thread.attr('id').replace('thread_', '');
|
||||||
|
var op = $thread.children('.op')[0];
|
||||||
|
var i, array; // temp variables
|
||||||
|
|
||||||
|
// add posts to localList and noReplyList
|
||||||
|
if (typeof list.postFilter[pageData.boardId] != 'undefined' && typeof list.postFilter[pageData.boardId][threadId] != 'undefined') {
|
||||||
|
array = list.postFilter[pageData.boardId][threadId];
|
||||||
|
for (i=0; i<array.length; i++) {
|
||||||
|
if ( typeof array[i].post == 'undefined')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pageData.localList.push(array[i].post);
|
||||||
|
if (array[i].hideReplies) pageData.noReplyList.push(array[i].post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// run filter on OP
|
||||||
|
filter(op, threadId, pageData);
|
||||||
|
quickToggle(op, threadId, pageData);
|
||||||
|
|
||||||
|
// iterate filter over each post
|
||||||
|
if (!$(op).data('hidden') || active_page == 'thread') {
|
||||||
|
$thread.find('.reply').not('.hidden').each(function () {
|
||||||
|
filter(this, threadId, pageData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var postFilter = list.postFilter[pageData.boardId];
|
||||||
|
var $collection = $('.mix');
|
||||||
|
|
||||||
|
if ($.isEmptyObject(postFilter))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var threadId = $thread.attr('id').replace('thread_', '');
|
// for each thread that has filtering rules
|
||||||
var op = $thread.children('.op')[0];
|
// check if filter contains thread OP and remove the thread from catalog
|
||||||
var i, array; // temp variables
|
$.each(postFilter, function (key, thread) {
|
||||||
|
var threadId = key;
|
||||||
// add posts to localList and noReplyList
|
$.each(thread, function () {
|
||||||
if (typeof list.postFilter[pageData.boardId] != 'undefined' && typeof list.postFilter[pageData.boardId][threadId] != 'undefined') {
|
if (this.post == threadId) {
|
||||||
array = list.postFilter[pageData.boardId][threadId];
|
$collection.filter('[data-id='+ threadId +']').remove();
|
||||||
for (i=0; i<array.length; i++) {
|
}
|
||||||
if ( typeof array[i].post == 'undefined')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
pageData.localList.push(array[i].post);
|
|
||||||
if (array[i].hideReplies) pageData.noReplyList.push(array[i].post);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// run filter on OP
|
|
||||||
filter(op, threadId, pageData);
|
|
||||||
quickToggle(op, threadId, pageData);
|
|
||||||
|
|
||||||
// iterate filter over each post
|
|
||||||
if (!$(op).data('hidden') || active_page == 'thread') {
|
|
||||||
$thread.find('.reply').not('.hidden').each(function () {
|
|
||||||
filter(this, threadId, pageData);
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initStyle() {
|
function initStyle() {
|
||||||
@ -592,17 +614,17 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
|
|
||||||
$row = $('<tr>');
|
$row = $('<tr>');
|
||||||
$row.append(
|
$row.append(
|
||||||
'<td>'+ typeName[obj.type] +'</td>',
|
'<td>'+ typeName[obj.type] +'</td>',
|
||||||
'<td>'+ val +'</td>',
|
'<td>'+ val +'</td>',
|
||||||
$('<td>').append(
|
$('<td>').append(
|
||||||
$('<a>').html('X')
|
$('<a>').html('X')
|
||||||
.addClass('del-btn')
|
.addClass('del-btn')
|
||||||
.attr('href', '#')
|
.attr('href', '#')
|
||||||
.data('type', obj.type)
|
.data('type', obj.type)
|
||||||
.data('val', obj.value)
|
.data('val', obj.value)
|
||||||
.data('useRegex', obj.regex)
|
.data('useRegex', obj.regex)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$ele.append($row);
|
$ele.append($row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -754,33 +776,6 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
* Migrate from previous version of post filter
|
|
||||||
* Remember to remove next time anyone touches this file
|
|
||||||
*/
|
|
||||||
(function () {
|
|
||||||
var list = getList();
|
|
||||||
if (typeof list.nameFilter != 'undefined') {
|
|
||||||
var filter = list.nameFilter;
|
|
||||||
list.generalFilter = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < filter.length; i++) {
|
|
||||||
var obj = filter[i];
|
|
||||||
for (var key in obj) {
|
|
||||||
list.generalFilter.push({
|
|
||||||
type: key,
|
|
||||||
value: obj[key],
|
|
||||||
regex: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete list.nameFilter;
|
|
||||||
localStorage.postFilter = JSON.stringify(list);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
var pageData = {
|
var pageData = {
|
||||||
boardId: board_name, // get the id from the global variable
|
boardId: board_name, // get the id from the global variable
|
||||||
localList: [], // all the blacklisted post IDs or UIDs that apply to the current page
|
localList: [], // all the blacklisted post IDs or UIDs that apply to the current page
|
||||||
@ -812,6 +807,17 @@ if (active_page === 'thread' || active_page === 'index') {
|
|||||||
filterPage(pageData);
|
filterPage(pageData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// shift+click on catalog to hide thread
|
||||||
|
if (active_page == 'catalog') {
|
||||||
|
$(document).on('click', '.mix', function(e) {
|
||||||
|
if (e.shiftKey) {
|
||||||
|
var threadId = $(this).data('id');
|
||||||
|
var postId = threadId;
|
||||||
|
blacklist.add.post(pageData.boardId, threadId, postId, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// clear out the old threads
|
// clear out the old threads
|
||||||
purge();
|
purge();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user