FA Content Filter

Filters user-defined content while browsing FA.

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

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