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:
marktaiwan 2015-03-06 16:15:49 +08:00 committed by czaks
parent dc725641c3
commit 513c8f7b68
2 changed files with 83 additions and 97 deletions

View File

@ -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));

View File

@ -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,6 +504,8 @@ if (active_page === 'thread' || active_page === 'index') {
function filterPage(pageData) { function filterPage(pageData) {
var list = getList(); var list = getList();
if (active_page != 'catalog') {
// empty the local and no-reply list // empty the local and no-reply list
pageData.localList = []; pageData.localList = [];
pageData.noReplyList = []; pageData.noReplyList = [];
@ -539,6 +543,24 @@ if (active_page === 'thread' || active_page === 'index') {
} }
}); });
} else {
var postFilter = list.postFilter[pageData.boardId];
var $collection = $('.mix');
if ($.isEmptyObject(postFilter))
return;
// for each thread that has filtering rules
// check if filter contains thread OP and remove the thread from catalog
$.each(postFilter, function (key, thread) {
var threadId = key;
$.each(thread, function () {
if (this.post == threadId) {
$collection.filter('[data-id='+ threadId +']').remove();
}
});
});
}
} }
function initStyle() { function initStyle() {
@ -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();
} }