Furaffinity Filter

Filters user-defined content while browsing FA.

当前为 2015-01-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Furaffinity 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.0
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_deleteValue
  11. // @grant GM_openInTab
  12. // ==/UserScript==
  13.  
  14. this.$ = this.jQuery = jQuery.noConflict(true);
  15.  
  16. // === INITIALIZE USER ARRAY ===
  17. var userArray = JSON.parse(GM_getValue('userList', '{}'));
  18.  
  19. // === FILTER ===
  20. var parseSettings = function() {
  21. if (!(userArray instanceof Array)) {
  22. $.each(userArray, function(username, data) {
  23. if (data['subs'] === 1) { hideSubmissions(username); }
  24. if (data['shouts'] === 1) { hideShouts(username); }
  25. if (data['coms'] === 1) { hideComments(username); }
  26. if (data['notifications'] === 1) { hideNotifications(username); }
  27. });
  28. }
  29. }
  30.  
  31. // === SAVE ===
  32. function writeSettings() {
  33. GM_setValue('userList', JSON.stringify(userArray));
  34. }
  35.  
  36. // === FUNCTIONS ===
  37. // Hide user submissions
  38. function hideSubmissions(username) {
  39. // Browse
  40. var submission1 = $('.t-image a[href="/user/' + username + '/"]').closest('.t-image');
  41. submission1.addClass('hidden-sub');
  42. submission1.hide();
  43. // Favorites/Front Page
  44. var submission2 = $('b[id^="sid_"] img[src$="#' + username + '"]').closest('b');
  45. submission2.addClass('hidden-sub');
  46. submission2.hide();
  47. }
  48.  
  49. // Hide user shouts
  50. function hideShouts(username) {
  51. var shout = $('table[id^="shout-"] td.alt1 img[alt="' + username + '"]').closest('table[id^="shout-"]');
  52. shout.addClass('hidden-shout');
  53. shout.hide();
  54. }
  55.  
  56. // Hide user comments and threads
  57. function hideComments(username) {
  58. var comments = $('.container-comment td.icon img[alt="' + username + '"]').closest('.container-comment');
  59. $(comments).each(function() {
  60. // Hide comment and get width
  61. if (!($(this).hasClass('hidden-comment'))) {
  62. var width = Number($(this).addClass('hidden-comment').hide().attr('width').slice(0,-1));
  63. var current = $(this).next('.container-comment');
  64.  
  65. // Iterate through comments until there's a width that is greater than or equal
  66. while (true) {
  67. if (current.length) {
  68. if (Number(current.attr('width').slice(0,-1)) < width) {
  69. current.addClass('hidden-comment').hide();
  70. current = current.next('.container-comment');
  71. } else {
  72. break;
  73. }
  74. } else {
  75. break;
  76. }
  77. }
  78. }
  79. });
  80. }
  81. // Hide user notifications
  82. function hideNotifications(username) {
  83. var notification = $('.message-stream a[href="/user/' + username + '/"]').closest('li');
  84. notification.addClass('hidden-notification').hide();
  85. }
  86.  
  87. // === UI ===
  88. function displaySettings() {
  89. // Navbar link
  90. $('<li class="noblock"><a target="_blank" href="/controls/site-settings#fa-filter">FA Filter</a></li>').insertAfter($('li.sfw-toggle'));
  91. if (window.location.pathname.lastIndexOf('/controls/site-settings', 0) === 0) {
  92. // HTML Code (hacky, need to find better way)
  93. var settingsDisplay = '<table id="fa-filter" cellpadding="0" cellspacing="1" border="0" class="section maintable"><tbody>' +
  94. '<tr><td height="22" class="cat links">&nbsp;<strong>FA Filter</strong></td></tr>' +
  95. '<tr><td class="alt1 addpad ucp-site-settings" align="center">' +
  96. '<table cellspacing="1" cellpadding="0" border="0"><tbody>' +
  97. '<tr>' +
  98. '<th><strong>Add a User</strong></th>' +
  99. '<td><input type="text" id="faf-add-username" maxlength="50"></input>&nbsp;<input id="faf-add" class="button" type="button" value="Add User"></td>' +
  100. '<td class="option-description">' +
  101. '<h3>Hide a user\'s contributions to the site.</h3>' +
  102. '<p>Tired of seeing somebody\'s artwork 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>' +
  103. '</td>' +
  104. '</tr>' +
  105. '<tr>' +
  106. '<th class="noborder" style="vertical-align: text-top;"><strong style="position: relative; top: 25px;">Modify Filters</strong></th>' +
  107. '<td class="noborder">' +
  108. '<table cellspacing="0" cellpadding="0" border="0" class="faf-list">' +
  109. '<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>' +
  110. '</table>' +
  111. '<br><br><input class="button" id="faf-update" type="button" value="Update Filters"> <span class="faf-update-status" style="font-weight: bold; color: #006600; display: none;">Update successful!</span>' +
  112. '</td>' +
  113. '<td class="option-description noborder">' +
  114. '<h3>Choose what items you don\'t want to see.</h3>' +
  115. '<p>If you still want to see some of the things that a user contributes, you can control that here.</p>' +
  116. '</td>' +
  117. '</tr>' +
  118. '</tbody></table>' +
  119. '</td></tr>' +
  120. '</tbody></table>';
  121. $('form').append(settingsDisplay);
  122. // Populate list
  123. $.each(userArray, function(username, data) {
  124. addFilterUser(username, data);
  125. });
  126. }
  127. }
  128.  
  129. // Display user in the filter table
  130. function addFilterUser(username, data) {
  131. var row = '<tr id="filter-' + username + '"><td class="noborder"><a class="fa-filter-remove" id="faf-rm-' + username + '" href="#!">[x]</a> ' + username + '</td>';
  132. 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>'; }
  133. 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>'; }
  134. 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>'; }
  135. 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>'; }
  136. row += '</tr>';
  137.  
  138. $('table.faf-list tr:last').after(row);
  139. }
  140.  
  141. // === ADD ===
  142. $(document.body).on('click', '#faf-add', function() {
  143. var username = $.trim($('#faf-add-username').val());
  144. $('#faf-add-username').val('');
  145. if (username !== '') {
  146. username = username.toLowerCase();
  147. if (!(username in userArray)) {
  148. userArray[username] = {'subs':1, 'shouts':1, 'coms':1, 'notifications':1};
  149. addFilterUser(username, userArray[username]);
  150. }
  151. }
  152. });
  153.  
  154. // === REMOVE ===
  155. $(document.body).on('click', 'a.fa-filter-remove', function(event) {
  156. var username = event.target.id.substr(7);
  157. delete userArray[username];
  158. // Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
  159. userEsc = username.replace(/\./, '\\.');
  160. userEsc = userEsc.replace(/:/, '\:');
  161. console.log(userEsc)
  162. $('table.faf-list tr#filter-' + userEsc).remove();
  163. });
  164.  
  165. // === UPDATE ===
  166. $(document.body).on('click', '#faf-update', function() {
  167. $('.faf-list tr[id^="filter-"]').each(function() {
  168. var username = this.id.substr(7);
  169. var vals = {'subs':0, 'shouts':0, 'coms':0, 'notifications':0};
  170. // Replace periods/colons with escaped versions. Who the fuck allows periods in usernames, seriously?
  171. userEsc = username.replace(/\./, '\\.');
  172. userEsc = userEsc.replace(/:/, '\:');
  173. // Check checkboxes
  174. if ($('#faf-check-subs-' + userEsc).is(':checked')) { vals['subs'] = 1; }
  175. if ($('#faf-check-shouts-' + userEsc).is(':checked')) { vals['shouts'] = 1; }
  176. if ($('#faf-check-coms-' + userEsc).is(':checked')) { vals['coms'] = 1; }
  177. if ($('#faf-check-notifications-' + userEsc).is(':checked')) { vals['notifications'] = 1; }
  178. userArray[username] = vals;
  179. });
  180. // Save
  181. writeSettings();
  182. // Display message
  183. $('.faf-update-status').fadeIn('slow');
  184. setTimeout(function() {
  185. $('.faf-update-status').fadeOut('slow')
  186. }, 5000);
  187. });
  188.  
  189. displaySettings();
  190.  
  191. setTimeout(parseSettings, 100);