// ==UserScript==
// @name FA Content Filter
// @namespace fa-filter
// @description Filters user-defined content while browsing Furaffinity.
// @include *://www.furaffinity.net/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @version 1.0
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @downloadURL none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
// === INITIALIZE USER ARRAY ===
var userArray = JSON.parse(GM_getValue('userList', '{}'));
// === FILTER ===
var parseSettings = function() {
if (!(userArray instanceof Array)) {
$.each(userArray, function(username, data) {
if (data['subs'] === 1) { hideSubmissions(username); }
if (data['shouts'] === 1) { hideShouts(username); }
if (data['coms'] === 1) { hideComments(username); }
if (data['notifications'] === 1) { hideNotifications(username); }
});
}
}
// === SAVE ===
function writeSettings() {
GM_setValue('userList', JSON.stringify(userArray));
}
// === FUNCTIONS ===
// Hide user submissions
function hideSubmissions(username) {
// Browse
var submission1 = $('.t-image a[href="/user/' + username + '/"]').closest('.t-image');
submission1.addClass('hidden-sub');
submission1.hide();
// Favorites/Front Page
var submission2 = $('b[id^="sid_"] img[src$="#' + username + '"]').closest('b');
submission2.addClass('hidden-sub');
submission2.hide();
}
// Hide user shouts
function hideShouts(username) {
var shout = $('table[id^="shout-"] td.alt1 img[alt="' + username + '"]').closest('table[id^="shout-"]');
shout.addClass('hidden-shout');
shout.hide();
}
// Hide user comments and threads
function hideComments(username) {
var comments = $('.container-comment td.icon img[alt="' + username + '"]').closest('.container-comment');
$(comments).each(function() {
// Hide comment and get width
if (!($(this).hasClass('hidden-comment'))) {
var width = Number($(this).addClass('hidden-comment').hide().attr('width').slice(0,-1));
var current = $(this).next('.container-comment');
// Iterate through comments until there's a width that is greater than or equal
while (true) {
if (current.length) {
if (Number(current.attr('width').slice(0,-1)) < width) {
current.addClass('hidden-comment').hide();
current = current.next('.container-comment');
} else {
break;
}
} else {
break;
}
}
}
});
}
// Hide user notifications
function hideNotifications(username) {
var notification = $('.message-stream a[href="/user/' + username + '/"]').closest('li');
notification.addClass('hidden-notification').hide();
}
// === UI ===
function displaySettings() {
// Navbar link
$('
FA Filter ').insertAfter($('li.sfw-toggle'));
if (window.location.pathname.lastIndexOf('/controls/site-settings', 0) === 0) {
// HTML Code (hacky, need to find better way)
var settingsDisplay = '' +
' FA Filter ' +
'' +
'' +
' ' +
'
';
$('form').append(settingsDisplay);
// Populate list
$.each(userArray, function(username, data) {
addFilterUser(username, data);
});
}
}
// Display user in the filter table
function addFilterUser(username, data) {
var row = '[x] ' + username + ' ';
if (data['subs'] === 1) { row += ' '; } else { row += ' '; }
if (data['shouts'] === 1) { row += ' '; } else { row += ' '; }
if (data['coms'] === 1) { row += ' '; } else { row += ' '; }
if (data['notifications'] === 1) { row += ' '; } else { row += ' '; }
row += ' ';
$('table.faf-list tr:last').after(row);
}
// === ADD ===
$(document.body).on('click', '#faf-add', function() {
var username = $.trim($('#faf-add-username').val());
$('#faf-add-username').val('');
if (username !== '') {
username = username.toLowerCase();
if (!(username in userArray)) {
userArray[username] = {'subs':1, 'shouts':1, 'coms':1, 'notifications':1};
addFilterUser(username, userArray[username]);
}
}
});
// === REMOVE ===
$(document.body).on('click', 'a.fa-filter-remove', function(event) {
var username = event.target.id.substr(7);
delete userArray[username];
// Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
userEsc = username.replace(/\./, '\\.');
userEsc = userEsc.replace(/:/, '\:');
console.log(userEsc)
$('table.faf-list tr#filter-' + userEsc).remove();
});
// === UPDATE ===
$(document.body).on('click', '#faf-update', function() {
$('.faf-list tr[id^="filter-"]').each(function() {
var username = this.id.substr(7);
var vals = {'subs':0, 'shouts':0, 'coms':0, 'notifications':0};
// Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
userEsc = username.replace(/\./, '\\.');
userEsc = userEsc.replace(/:/, '\:');
// Check checkboxes
if ($('#faf-check-subs-' + userEsc).is(':checked')) { vals['subs'] = 1; }
if ($('#faf-check-shouts-' + userEsc).is(':checked')) { vals['shouts'] = 1; }
if ($('#faf-check-coms-' + userEsc).is(':checked')) { vals['coms'] = 1; }
if ($('#faf-check-notifications-' + userEsc).is(':checked')) { vals['notifications'] = 1; }
userArray[username] = vals;
});
// Save
writeSettings();
// Display message
$('.faf-update-status').fadeIn('slow');
setTimeout(function() {
$('.faf-update-status').fadeOut('slow')
}, 5000);
});
displaySettings();
setTimeout(parseSettings, 100);