FA Content Filter

Filters user-defined content while browsing FA.

当前为 2016-10-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FA Content Filter
  3. // @namespace fa-filter
  4. // @description Filters user-defined content while browsing FA.
  5. // @include *://www.furaffinity.net/*
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  7. // @version 1.5.1
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_deleteValue
  11. // @grant GM_openInTab
  12. // ==/UserScript==
  13.  
  14. // === WARNING ===
  15. // THE TAG FUNCTIONS ARE COMMENTED OUT IN ORDER TO PREVENT ACCIDENTAL DDoS DETECTION ON FURAFFINITY.
  16. this.$ = this.jQuery = jQuery.noConflict(true);
  17.  
  18. // === INITIALIZE USER ARRAY ===
  19. var userArray = JSON.parse(GM_getValue('userList', '{}'));
  20. //var tagArray = JSON.parse(GM_getvalue('tagList', '{}'));
  21.  
  22. // === GENERAL TEMPORARY VARIABLES ===
  23. var filterEnabled = {['subs']:true, ['shouts']:true, ['coms']:true, ['notifications']:true};
  24.  
  25. // === FILTER ===
  26. var parseSettings = function() {
  27. if (!(userArray instanceof Array)) {
  28. $.each(userArray, function(username, data) {
  29. if (data['subs'] === 1) { hideSubmissions(username); }
  30. if (data['shouts'] === 1) { hideShouts(username); }
  31. if (data['coms'] === 1) { hideComments(username); }
  32. if (data['notifications'] === 1) { hideNotifications(username); }
  33. });
  34. }
  35. };
  36.  
  37. //var parseTagSettings = function() {
  38. // $('.t-image a[href^="/view"]').each(function() {
  39. // var url = $(this).attr('href');
  40. // console.log(url);
  41. // $.post(url, function(data) {
  42. // console.log($('#keywords', data).text());
  43. // });
  44. // });
  45. //}
  46.  
  47.  
  48. // === SAVE ===
  49. function writeSettings() {
  50. GM_setValue('userList', JSON.stringify(userArray));
  51. }
  52.  
  53. // === FUNCTIONS ===
  54. // Hide user submissions
  55. function hideSubmissions(username) {
  56. // Browse/Submissions
  57. var submission1 = $('b[id^="sid_"] a[href="/user/' + username + '/"]').closest('b');
  58. stylizeHidden(submission1);
  59. // Mark Submissions as Checked
  60. submission1.children('small').children('input').prop('checked', true);
  61. submission1.addClass('hidden-sub').hide();
  62.  
  63. // Favorites/Front Page
  64. var submission2 = $('b[id^="sid_"] img[src$="#' + username + '"]').closest('b');
  65. stylizeHidden(submission2);
  66. submission2.addClass('hidden-sub').hide();
  67.  
  68. // Correspond to UI
  69. if (!filterEnabled['subs']) {
  70. submission1.show();
  71. submission2.show();
  72. }
  73. }
  74.  
  75. function showSubmissions(username) {
  76. // Browse/Submissions
  77. var submission1 = $('b[id^="sid_"] a[href="/user/' + username + '/"]').closest('b');
  78. undoStylize(submission1);
  79. // Mark Submissions as Checked
  80. submission1.children('small').children('input').prop('checked', false);
  81. submission1.removeClass('hidden-sub').show();
  82.  
  83. // Favorites/Front Page
  84. var submission2 = $('b[id^="sid_"] img[src$="#' + username + '"]').closest('b');
  85. undoStylize(submission2);
  86. submission2.removeClass('hidden-sub').show();
  87. }
  88.  
  89. // Hide user shouts
  90. function hideShouts(username) {
  91. // Classic
  92. var shout = $('table[id^="shout-"] td.alt1 img[alt="' + username + '"]').closest('table[id^="shout-"]');
  93. shout.addClass('hidden-shout').hide();
  94. stylizeHidden(shout.find('table'));
  95. shout.next('br').addClass('hidden-shout-br').hide();
  96.  
  97. // Beta
  98. var shoutBeta = $('table[id^="shout-"] .comments-flex-item-icon img[alt="' + username +'"]').closest('table[id^="shout-"]');
  99. shoutBeta.addClass('hidden-shout').hide();
  100. stylizeHidden(shoutBeta.find('.comments-flex-item-main'));
  101. }
  102.  
  103. // Hide user comments and threads
  104. function hideComments(username) {
  105. // Classic
  106. var comments = $('.container-comment td.icon img[alt="' + username + '"]').closest('.container-comment');
  107.  
  108. $(comments).each(function() {
  109. // Hide comment and get width
  110. if (!($(this).hasClass('hidden-comment'))) {
  111. var width = Number($(this).addClass('hidden-comment').hide().attr('width').slice(0,-1));
  112. var current = $(this).next('.container-comment');
  113.  
  114. // Iterate through comments until there's a width that is greater than or equal
  115. while (true) {
  116. if (current.length) {
  117. if (Number(current.attr('width').slice(0,-1)) < width) {
  118. current.addClass('hidden-comment').hide();
  119. current = current.next('.container-comment');
  120. } else {
  121. break;
  122. }
  123. } else {
  124. break;
  125. }
  126. }
  127. }
  128. });
  129.  
  130. // Beta
  131. var commentsBeta = $('.container-comment .comments-flex-item-icon img[alt="' + username + '"]').closest('.container-comment');
  132. stylizeHidden(commentsBeta.find('.comments-flex-item-main'));
  133.  
  134. $(commentsBeta).each(function() {
  135. // Hide comment and get width
  136. if (!($(this).hasClass('hidden-comment'))) {
  137. var width = Number($(this).addClass('hidden-comment').hide().attr('width').slice(0,-1));
  138. var current = $(this).next('.container-comment');
  139.  
  140. // Iterate through the comments until there's a width that is greater than or equal
  141. while (true) {
  142. if (current.length) {
  143. if (Number(current.attr('width').slice(0,-1)) < width) {
  144. current.addClass('hidden-comment').hide();
  145. current = current.next('.container-comment');
  146. } else {
  147. break;
  148. }
  149. } else {
  150. break;
  151. }
  152. }
  153. }
  154. });
  155. }
  156.  
  157. // Hide user notifications
  158. function hideNotifications(username) {
  159. var notification = $('.message-stream a[href="/user/' + username + '/"]').closest('li');
  160. notification.addClass('hidden-notification').hide();
  161. stylizeHidden(notification);
  162. notification.children('input').prop('checked', true);
  163.  
  164. // Classic only
  165. notification.children('table').children('tbody').children('tr').children('td').children('.checkbox').children('input').prop('checked', true);
  166. }
  167.  
  168. function stylizeHidden(item) {
  169. $(item).css('background-color', '#FFBBBB');
  170. $(item).css('color', '#FF0000');
  171. $('a:link', item).css('color', '#FF0000');
  172. $('a:visited', item).css('color', '#FF0000');
  173. }
  174.  
  175. function undoStylize(item) {
  176. $(item).css('background-color', '');
  177. $(item).css('color', '');
  178. $('a:link', item).css('color', '');
  179. $('a:visited', item).css('color', '');
  180. }
  181.  
  182. // === UI ===
  183. // == Filter Toggle ==
  184. // Submissions
  185. function filtersSubs() {
  186. // Remove all pre-existing UI
  187. $('[id="faf-toggle-subs"]').remove();
  188. $('.faf-remove-user-external').parent().remove();
  189. $('.faf-add-user-external').parent().remove();
  190.  
  191. if ($('.hidden-sub').length > 0) {
  192. // Classic
  193. if (!$('li.lileft').length) {
  194. $display = '<input style="float:right;" id="faf-toggle-subs" class="button" type="button" value="Toggle Filtered Submissions (' + $('.hidden-sub').length + ')"></input>';
  195. $('form').first().append($display);
  196. // Beta
  197. } else {
  198. $display = '<li class="lileft"><a class="top-heading" id="faf-toggle-subs" href="#!"><div class="sprite-nuke menu-space-saver hideonmobile"></div>Toggle Filtered Submissions (' + $('.hidden-sub').length + ')</a></li>';
  199. $('.lileft').last().after($display);
  200. }
  201. } else {
  202. filterEnabled['subs'] = true;
  203. }
  204.  
  205. $userFilterLink = '<a class="faf-add-user-external" id="filter-username" href="#!">Filter</a>';
  206. $('b[id^="sid_"]').each(function() {
  207. var username = $(this).find('small a').attr('href');
  208. username = username.match('/user/(.*)/');
  209. if (username) {
  210. if (username[1] in userArray && userArray[username[1]]['subs'] === 1) {
  211. $(this).find('small').append('<span>&nbsp;<a style="color: #FF5555;" class="faf-remove-user-external" id="faf-' + username[1] + '" href="#!" title="Remove ' + username[1] + ' from filter">[Unfilter]</a></span>');
  212. } else {
  213. $(this).find('small').append('<span>&nbsp;<a style="color: #FF5555;" class="faf-add-user-external" id="faf-' + username[1] + '" href="#!" title="Add ' + username[1] + ' to filter">[Filter]</a></span>');
  214. }
  215. }
  216. });
  217. }
  218.  
  219. // Followed Submissions
  220. function filtersSubsFollow() {
  221. if ($('.hidden-sub').length > 0) {
  222. $display = '<input id="faf-toggle-subs" class="button" type="button" value="Toggle Filtered Submissions (' + $('.hidden-sub').length + ')"></input>';
  223. $('.actions').append($display);
  224. }
  225. }
  226.  
  227. // Shouts
  228. function filtersShouts() {
  229. if ($('.hidden-shout').length > 0) {
  230. $display = '<center><input id="faf-toggle-shouts" class="button" type="button" value="Toggle Filtered Shouts (' + $('.hidden-shout').length + ')"></input></center>';
  231. // Classic
  232. $('table[id^="shout-"]').first().prevAll('table.maintable:first').append($display);
  233. // Beta
  234. $($display).insertAfter('#shoutboxentry');
  235. }
  236. }
  237.  
  238. // Shouts (Controls, Beta Only)
  239. function filtersShoutsControl() {
  240. if ($('.hidden-shout').length > 0) {
  241. $display = '<div class="button-nav-item"><button id="faf-toggle-shouts" class="button mobile-button" type="button" value="Toggle Filtered Shouts (' + $('.hidden-shout').length + ')">Toggle Filtered Shouts (' + $('.hidden-shout').length + ')</input></div>';
  242. $('.button-nav').append($display);
  243. $('.hidden-shout input').prop('checked', true);
  244. }
  245. }
  246.  
  247. // Comments
  248. function filtersComments() {
  249. if ($('.hidden-comment').length > 0) {
  250. $display = '<input style="float:right;" id="faf-toggle-comments" class="button" type="button" value="Toggle Filtered Comments (' + $('.hidden-comment').length + ')"></input>';
  251. if (!$('.flex-submission-container').length) {
  252. // Classic
  253. $('table.container-comment').first().parent().parent().prev().children().append($display);
  254. } else {
  255. // Beta
  256. $($display).insertAfter('.flex-submission-container');
  257. }
  258. }
  259. }
  260.  
  261. // Notifications
  262. function filtersNotifications() {
  263. if ($('.hidden-notification').length > 0) {
  264. $display = '<input id="faf-toggle-notifications" class="button" type="button" value="Toggle Filtered Notifications (' + $('.hidden-notification').length + ')"></input>';
  265. $('.global-controls').append($display);
  266.  
  267. // = Notification Count =
  268. // Classic
  269. if ($('fieldset[id^="messages-watches"] .hidden-notification').length > 0)
  270. $('fieldset[id^="messages-watches"] h3').append(' (' + $('fieldset[id^="messages-watches"] .hidden-notification').length + ' filtered)');
  271. if ($('fieldset[id^="messages-comments-submission"] .hidden-notification').length > 0)
  272. $('fieldset[id^="messages-comments-submission"] h3').append(' (' + $('fieldset[id^="messages-comments-submission"] .hidden-notification').length + ' filtered)');
  273. if ($('fieldset[id^="messages-shouts"] .hidden-notification').length > 0)
  274. $('fieldset[id^="messages-shouts"] h3').append(' (' + $('fieldset[id^="messages-shouts"] .hidden-notification').length + ' filtered)');
  275. if ($('fieldset[id^="messages-favorites"] .hidden-notification').length > 0)
  276. $('fieldset[id^="messages-favorites"] h3').append(' (' + $('fieldset[id^="messages-favorites"] .hidden-notification').length + ' filtered)');
  277.  
  278. // Beta
  279. if ($('div[id^="messages-watches"] .hidden-notification').length > 0)
  280. $('div[id^="messages-watches"]').prev().find('h3').append(' (' + $('div[id^="messages-watches"] .hidden-notification').length + ' filtered)');
  281. if ($('div[id^="messages-comments-submission"] .hidden-notification').length > 0)
  282. $('div[id^="messages-comments-submission"]').prev().find('h3').append(' (' + $('div[id^="messages-comments-submission"] .hidden-notification').length + ' filtered)');
  283. if ($('div[id^="messages-shouts"] .hidden-notification').length > 0)
  284. $('div[id^="messages-shouts"]').prev().find('h3').append(' (' + $('div[id^="messages-shouts"] .hidden-notification').length + ' filtered)');
  285. if ($('div[id^="messages-favorites"] .hidden-notification').length > 0)
  286. $('div[id^="messages-favorites"]').prev().find('h3').append(' (' + $('div[id^="messages-favorites"] .hidden-notification').length + ' filtered)');
  287. if ($('div[id^="messages-journals"] .hidden-notification').length > 0)
  288. $('div[id^="messages-journals"]').prev().find('h3').append(' (' + $('div[id^="messages-journals"] .hidden-notification').length + ' filtered)');
  289. }
  290. }
  291.  
  292. // == Buttons ==
  293. // Show/Hide Submissions
  294. $(document.body).on('click', '#faf-toggle-subs', function() {
  295. $('.hidden-sub').toggle();
  296. filterEnabled['subs'] = !filterEnabled['subs'];
  297. });
  298.  
  299. // Show/Hide Shouts
  300. $(document.body).on('click', '#faf-toggle-shouts', function() {
  301. $('.hidden-shout').toggle();
  302. $('.hidden-shout-br').toggle();
  303. filterEnabled['shouts'] = !filterEnabled['shouts'];
  304. });
  305.  
  306. // Show/Hide Comments
  307. $(document.body).on('click', '#faf-toggle-comments', function() {
  308. $('.hidden-comment').toggle();
  309. filterEnabled['coms'] = !filterEnabled['coms'];
  310. });
  311.  
  312. // Show/Hide Notifications
  313. $(document.body).on('click', '#faf-toggle-notifications', function() {
  314. $('.hidden-notification').toggle();
  315. filterEnabled['notifications'] = !filterEnabled['notifications'];
  316. });
  317.  
  318. // == External Filters ==
  319. // Add submission filter outside of settings
  320. $(document.body).on('click', '.faf-add-user-external', function() {
  321. var addUser = $(this).attr('id').match('faf-(.*)')[1];
  322.  
  323. // Add to array
  324. if (!(addUser in userArray)) {
  325. userArray[addUser] = {'subs':1, 'shouts':0, 'coms':0, 'notifications':0};
  326. } else {
  327. userArray[addUser]['subs'] = 1;
  328. }
  329.  
  330. // Hide, replace link, and save
  331. hideSubmissions(addUser);
  332. filtersSubs();
  333. writeSettings();
  334. });
  335.  
  336. // Remove submission filter outside of settings
  337. $(document.body).on('click', '.faf-remove-user-external', function() {
  338. var removeUser = $(this).attr('id').match('faf-(.*)')[1];
  339.  
  340. // Remove from array
  341. if (removeUser in userArray) {
  342. userArray[removeUser]['subs'] = 0;
  343. }
  344.  
  345. // Show, replace link, and save
  346. showSubmissions(removeUser);
  347. filtersSubs();
  348. writeSettings();
  349. });
  350.  
  351. // == User Settings ==
  352. function displaySettings() {
  353. // Navbar link
  354. $('<li class="noblock"><a target="_blank" href="/controls/site-settings#fa-filter">FA Filter</a></li>').insertAfter($('li.sfw-toggle'));
  355.  
  356. if (window.location.pathname.lastIndexOf('/controls/site-settings', 0) === 0) {
  357. // Brute forced, but there are no tables in the beta layout site-settings page. This is one of the major differences.
  358. if (!$('table').length) {
  359. // Beta HTML Code
  360. var settingsDisplay = '<div class="section-divider">' +
  361. '<h2 id="fa-filter">FA Filter</h2>' +
  362. '<strong>Add a User</strong>' +
  363. '<div class="control-panel-option">' +
  364. '<div class="control-panel-item-1">' +
  365. '<p>Tired of seeing somebody\'s contributions on the site? Add them to your filter list!<br/><strong>Note:</strong> Enter in the username of the person you want to filter, which is the username that would appear after "furaffinity.net/user/".' +
  366. '</div>' +
  367. '<div class="control-panel-item-2">' +
  368. '<input class="textbox" type="text" id="faf-add-username" maxlength="50"></input><input id="faf-add" class="button" type="button" value="Add" />' +
  369. '</div>' +
  370. '</div>' +
  371. '<strong>Validate Filters</strong>' +
  372. '<div class="control-panel-option">' +
  373. '<div class="control-panel-item-1">' +
  374. '<p>This double-checks to make sure that your filtered usernames are correct and, optionally, removes users that don\'t have any enabled filters.<br/><strong>Note:</strong> This automatically saves the list.</p>' +
  375. '</div>' +
  376. '<div class="control-panel-item-2">' +
  377. '<select name="faf-validate-options" id="select-faf-validate-options" class="styled">' +
  378. '<option value="v" selected="selected">Vaildate Filters Only</option>' +
  379. '<option value="vr">Validate Filters and Remove Unused Filters</option>' +
  380. '</select><input id="faf-validate" class="button" type="button" value="Apply" /><br/>' +
  381. '<span class="faf-validate-status" style="font-weight: bold; color: #009900; display: none;">Validated! 0 user(s) have been modified or removed.</span>' +
  382. '</div>' +
  383. '</div>' +
  384. '</div>' +
  385. '<div class="maintable rounded">' +
  386. '<table class="sessions-list faf-list faf-list-beta" width="100%" cellspacing="0" cellpadding="0" border="0" style="padding:0 15px 10px 15px">' +
  387. '<tbody>' +
  388. '<tr>' +
  389. '<td class="p10t p5r p5b"><h3>Username</h3></td>' +
  390. '<td class="p10t p5r p5b" width="200px"><h3>Submissions</h3></td>' +
  391. '<td class="p10t p5r p5b" width="200px"><h3>Shouts</h3></td>' +
  392. '<td class="p10t p5r p5b" width="200px"><h3>Comments</h3></td>' +
  393. '<td class="p10t p5r p5b" width="200px"><h3>Notifications</h3></td>' +
  394. '</tr>' +
  395. '</tbody>' +
  396. '</table>' +
  397. '</div>' +
  398. '<div class="section-divider">' +
  399. '<input class="button mobile-button" id="faf-update" type="button" value="Apply Filters (FA Filter)"> <center><span class="faf-update-status" style="font-weight: bold; color: #006600; display: none;">Update successful!</span></center>' +
  400. '</div>';
  401. $(settingsDisplay).insertBefore($('.section-divider').last());
  402. } else {
  403. // Classic HTML Code
  404. var settingsDisplay = '<table id="fa-filter" cellpadding="0" cellspacing="1" border="0" class="section maintable"><tbody>' +
  405. '<tr><td height="22" class="cat links">&nbsp;<strong>FA Filter</strong></td></tr>' +
  406. '<tr><td class="alt1 addpad ucp-site-settings" align="center">' +
  407. '<table cellspacing="1" cellpadding="0" border="0"><tbody>' +
  408. '<tr>' +
  409. '<th><strong>Add a User</strong></th>' +
  410. '<td><input type="text" id="faf-add-username" maxlength="50"></input>&nbsp;<input id="faf-add" class="button" type="button" value="Add User"></td>' +
  411. '<td class="option-description">' +
  412. '<h3>Hide a user\'s contributions to the site.</h3>' +
  413. '<p>Tired of seeing somebody\'s contributions on the site? Add them to your filter list!<br>Note: Enter in the username of the person you want to filter, which is the username that would appear after "furaffinity.net/user/".</p>' +
  414. '</td>' +
  415. '</tr>' +
  416. '<tr>' +
  417. '<th><strong>Validate Filters</strong></th>' +
  418. '<td>' +
  419. '<select name="faf-validate-options" id="select-faf-validate-options" class="styled">' +
  420. '<option value="v" selected="selected">Vaildate Filters Only</option>' +
  421. '<option value="vr">Validate Filters and Remove Unused Filters</option>' +
  422. '</select>&nbsp;<input id="faf-validate" class="button" type="button" value="Apply" /><br/>' +
  423. '<span class="faf-validate-status" style="font-weight: bold; color: #009900; display: none;">Validated! 0 user(s) have been modified or removed.</span>' +
  424. '</td>' +
  425. '<td class="option-description">' +
  426. '<h3>Clean up everything and revalidate filtered usernames.</h3>' +
  427. '<p>This double-checks to make sure that your filtered usernames are correct and, optionally, removes users that don\'t have any enabled filters.<br/><strong>Note:</strong> This automatically saves the list.</p>' +
  428. '</td>' +
  429. '</tr>' +
  430. '<tr>' +
  431. '<th class="noborder" style="vertical-align: text-top;"><strong style="position: relative; top: 25px;">Modify Filters</strong></th>' +
  432. '<td class="noborder">' +
  433. '<table cellspacing="0" cellpadding="0" border="0" class="faf-list faf-list-classic">' +
  434. '<tr><th><strong>Username</strong></th><th><strong>Submissions</strong></th><th><strong>Shouts</strong></th><th><strong>Comments</strong></th><th><strong>Notifications</strong></th></tr>' +
  435. '</table>' +
  436. '<br><br><input class="button" id="faf-update" type="button" value="Apply Filters (FA Filter)"> <span class="faf-update-status" style="font-weight: bold; color: #006600; display: none;">Update successful!</span>' +
  437. '</td>' +
  438. '<td class="option-description noborder">' +
  439. '<h3>Choose what items you don\'t want to see.</h3>' +
  440. '<p>If you still want to see some of the things that a user contributes, you can control that here.</p>' +
  441. '</td>' +
  442. '</tr>' +
  443. '</tbody></table>' +
  444. '</td></tr>' +
  445. '</tbody></table>';
  446. $('form').append(settingsDisplay);
  447. }
  448.  
  449. // Populate list
  450. $.each(userArray, function(username, data) {
  451. addFilterUser(username, data);
  452. });
  453. }
  454. }
  455.  
  456. // Display user in the filter table
  457. function addFilterUser(username, data) {
  458. // Classic
  459. if ($('table.faf-list-classic').length) {
  460.  
  461. var row = '<tr class="checked" id="filter-' + username + '"><td class="noborder"><a class="fa-filter-remove fonthighlight" id="faf-rm-' + username + '" href="#!">[x]</a> ' + username + '</td>';
  462. if (data['subs'] === 1) { row += '<td class="noborder"><input id="faf-check-subs-' + username + '" type="checkbox" checked="checked"></td>'; } else { row += '<td class="noborder"><input id="faf-check-subs-' + username + '" type="checkbox"></td>'; }
  463. if (data['shouts'] === 1) { row += '<td class="noborder"><input id="faf-check-shouts-' + username + '" type="checkbox" checked="checked"></td>'; } else { row += '<td class="noborder"><input id="faf-check-shouts-' + username + '" type="checkbox"></td>'; }
  464. if (data['coms'] === 1) { row += '<td class="noborder"><input id="faf-check-coms-' + username + '" type="checkbox" checked="checked"></td>'; } else { row += '<td class="noborder"><input id="faf-check-coms-' + username + '" type="checkbox"></td>'; }
  465. if (data['notifications'] === 1) { row += '<td class="noborder"><input id="faf-check-notifications-' + username + '" type="checkbox" checked="checked"></td>'; } else { row += '<td class="noborder"><input id="faf-check-notifications-' + username + '" type="checkbox"></td>'; }
  466.  
  467. row += '</tr>';
  468.  
  469. $('table.faf-list tr:last').after(row);
  470. // Beta
  471. } else {
  472. var rowBeta = '<tr id="filter-' + username + '"><td class="p5r" valign="middle" width="auto"><a class="fa-filter-remove" id="faf-rm-' + username + '" href="#!">[x]</a> ' + username + '</td>';
  473. if (data['subs'] === 1) { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-subs-' + username + '" type="checkbox" checked="checked"></td>'; } else { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-subs-' + username + '" type="checkbox"></td>'; }
  474. if (data['shouts'] === 1) { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-shouts-' + username + '" type="checkbox" checked="checked"></td>'; } else { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-shouts-' + username + '" type="checkbox"></td>'; }
  475. if (data['coms'] === 1) { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-coms-' + username + '" type="checkbox" checked="checked"></td>'; } else { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-coms-' + username + '" type="checkbox"></td>'; }
  476. if (data['notifications'] === 1) { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-notifications-' + username + '" type="checkbox" checked="checked"></td>'; } else { rowBeta += '<td class="p5r" valign="middle" width="auto"><input id="faf-check-notifications-' + username + '" type="checkbox"></td>'; }
  477.  
  478. rowBeta += '</tr>';
  479.  
  480. $('table.faf-list tr:last').after(rowBeta);
  481. }
  482. }
  483.  
  484. // Add
  485. $(document.body).on('click', '#faf-add', function() {
  486. var username = $.trim($('#faf-add-username').val());
  487. $('#faf-add-username').val('');
  488. if (username !== '') {
  489. username = username.toLowerCase();
  490. username = username.replace(/[_]/g, '');
  491. if (!(username in userArray)) {
  492. userArray[username] = {'subs':1, 'shouts':1, 'coms':1, 'notifications':1};
  493. addFilterUser(username, userArray[username]);
  494. }
  495. }
  496. });
  497.  
  498. // Remove
  499. $(document.body).on('click', 'a.fa-filter-remove', function(event) {
  500. var username = event.target.id.substr(7);
  501. delete userArray[username];
  502.  
  503. // Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
  504. userEsc = username.replace(/\./g, '\\.');
  505. userEsc = userEsc.replace(/:/g, '\:');
  506.  
  507. console.log(userEsc);
  508. $('table.faf-list tr#filter-' + userEsc).remove();
  509. });
  510.  
  511. // Update
  512. $(document.body).on('click', '#faf-update', function() {
  513. $('.faf-list tr[id^="filter-"]').each(function() {
  514. var username = this.id.substr(7);
  515. var vals = {'subs':0, 'shouts':0, 'coms':0, 'notifications':0};
  516.  
  517. // Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
  518. userEsc = username.replace(/\./g, '\\.');
  519. userEsc = userEsc.replace(/:/g, '\:');
  520.  
  521. // Check checkboxes
  522. if ($('#faf-check-subs-' + userEsc).is(':checked')) { vals['subs'] = 1; }
  523. if ($('#faf-check-shouts-' + userEsc).is(':checked')) { vals['shouts'] = 1; }
  524. if ($('#faf-check-coms-' + userEsc).is(':checked')) { vals['coms'] = 1; }
  525. if ($('#faf-check-notifications-' + userEsc).is(':checked')) { vals['notifications'] = 1; }
  526.  
  527. userArray[username] = vals;
  528. });
  529.  
  530. // Save
  531. writeSettings();
  532.  
  533. // Display message
  534. $('.faf-update-status').fadeIn('slow');
  535. setTimeout(function() {
  536. $('.faf-update-status').fadeOut('slow');
  537. }, 5000);
  538. });
  539.  
  540. // Validate
  541. $(document.body).on('click', '#faf-validate', function() {
  542. var modCount = 0;
  543. // Validate
  544. $.each(userArray, function(username, data) {
  545. var tempUsername = username;
  546. tempUsername = tempUsername.trim();
  547. if (tempUsername !== '') {
  548. tempUsername = tempUsername.toLowerCase();
  549. tempUsername = tempUsername.replace(/[_]/g, '');
  550. if (tempUsername !== username) {
  551. userArray[tempUsername] = data;
  552. delete userArray[username];
  553. $('tr[id="filter-' + username + '"]').remove();
  554. modCount++;
  555. }
  556. }
  557. });
  558.  
  559. // Remove empty
  560. if ($('#select-faf-validate-options').val() === 'vr') {
  561. $.each(userArray, function(username, data) {
  562. var isEmpty = true;
  563. $.each(data, function(entity, value) {
  564. if (value === 1) {
  565. isEmpty = false;
  566. }
  567. });
  568. if (isEmpty) {
  569. delete userArray[username];
  570. $('tr[id="filter-' + username + '"]').remove();
  571. modCount++;
  572. }
  573. });
  574. }
  575.  
  576. // Save
  577. writeSettings();
  578.  
  579. // Display message
  580. $('.faf-validate-status').text('Validated! ' + modCount + ' user(s) have been modified or removed.');
  581. $('.faf-validate-status').fadeIn('slow');
  582. setTimeout(function() {
  583. $('.faf-validate-status').fadeOut('slow');
  584. }, 5000);
  585. });
  586.  
  587. displaySettings();
  588.  
  589. setTimeout(parseSettings, 50);
  590. //setTimeout(parseTagSettings, 100);
  591.  
  592. // Submissions
  593. if (window.location.pathname.lastIndexOf('/browse', 0) === 0) setTimeout(filtersSubs, 100);
  594. else if (window.location.pathname.lastIndexOf('/favorites', 0) === 0) setTimeout(filtersSubs, 100);
  595. else if (window.location.pathname.lastIndexOf('/msg/submissions', 0) === 0) setTimeout(filtersSubsFollow, 100);
  596. // Shouts
  597. else if (window.location.pathname.lastIndexOf('/user', 0) === 0) setTimeout(filtersShouts, 100);
  598. else if (window.location.pathname.lastIndexOf('/controls/shouts', 0) === 0) setTimeout(filtersShoutsControl, 100);
  599. // Comments
  600. else if (window.location.pathname.lastIndexOf('/view', 0) === 0) setTimeout(filtersComments, 100);
  601. // Notifications
  602. else if (window.location.pathname.lastIndexOf('/msg/others', 0) === 0) setTimeout(filtersNotifications, 100);
  603. else setTimeout(filtersSubs, 100);