From 2808b1b8b2afe30126c26cd3dc35a5a81e765668 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Tue, 17 Feb 2015 14:40:04 +0800 Subject: [PATCH] post-filter Adds a dropdown menu to each post that allows for filtering by: - post - post and all replies to it - poster ID - poster ID and all replies to it - name - tripcode In the options panel, adds a new tab for adding/removing name and tripcode filters. --- js/post-filter.js | 755 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 755 insertions(+) create mode 100644 js/post-filter.js diff --git a/js/post-filter.js b/js/post-filter.js new file mode 100644 index 00000000..151a6f5d --- /dev/null +++ b/js/post-filter.js @@ -0,0 +1,755 @@ +if (active_page === 'thread' || active_page === 'index') { + $(document).ready(function () { + 'use strict'; + // returns blacklist object from storage + function getList() { + return JSON.parse(localStorage.postFilter); + } + + // stores blacklist into storage and reruns the filter + function setList(blacklist) { + localStorage.postFilter = JSON.stringify(blacklist); + $(document).trigger('filter_page'); + } + + // unit: seconds + function timestamp() { + return Math.floor((new Date()).getTime() / 1000); + } + + function initList(list, boardId, threadId) { + if (typeof list.postFilter[boardId] == 'undefined') + list.postFilter[boardId] = {}; + list.nextPurge[boardId] = {}; + if (typeof list.postFilter[boardId][threadId] == 'undefined') { + list.postFilter[boardId][threadId] = []; + list.nextPurge[boardId][threadId] = {timestamp: timestamp(), interval: 86400}; // 86400 seconds == 1 day + } + } + + var blacklist = { + add: { + name: function (posterName) { + var list = getList(); + var filter = list.nameFilter; + + for (var i in filter) { + if (filter[i].name == posterName) return; + } + filter.push({ + name: posterName + }); + setList(list); + drawFilterList(); + }, + trip: function (posterTrip) { + var list = getList(); + var filter = list.nameFilter; + + for (var i in filter) { + if (filter[i].trip == posterTrip) return; + } + filter.push({ + trip: posterTrip + }); + setList(list); + drawFilterList(); + }, + post: function (boardId, threadId, postId, hideReplies) { + var list = getList(); + var filter = list.postFilter; + + initList(list, boardId, threadId); + + for (var i in filter[boardId][threadId]) { + if (filter[boardId][threadId][i].post == postId) return; + } + filter[boardId][threadId].push({ + post: postId, + hideReplies: hideReplies + }); + setList(list); + }, + uid: function (boardId, threadId, uniqueId, hideReplies) { + var list = getList(); + var filter = list.postFilter; + + initList(list, boardId, threadId); + + for (var i in filter[boardId][threadId]) { + if (filter[boardId][threadId][i].uid == uniqueId) return; + } + filter[boardId][threadId].push({ + uid: uniqueId, + hideReplies: hideReplies + }); + setList(list); + } + }, + remove: { + name: function (posterName) { + var list = getList(); + var filter = list.nameFilter; + + for (var i=0; i').append( + $('