DZ.com post blocker

Automatically hides posts on DZ.com

  1. // ==UserScript==
  2. // @name DZ.com post blocker
  3. // @namespace greasyfork.org
  4. // @description Automatically hides posts on DZ.com
  5. // @match http://www.dropzone.com/cgi-bin/forum/gforum.cgi?*post=*
  6. // @require http://code.jquery.com/jquery-latest.min.js
  7. // @require http://code.jquery.com/ui/1.11.2/jquery-ui.min.js
  8. // @grant none
  9. // @version 0.8
  10. // ==/UserScript==
  11. var sThreadTitle;
  12. currentVisibleThreads = [];
  13. Posts = [];
  14. nShownCount = 0;
  15.  
  16. $(document).ready(function() {
  17. // CheckCloudSync();
  18.  
  19. CreateStyles();
  20. CreateFilter();
  21. // CreateControlPanel();
  22. CreateEventHandlers();
  23.  
  24. // SetOptions();
  25.  
  26. UpdateHideLinks();
  27. UpdatePosts();
  28. });
  29.  
  30. function CreateStyles()
  31. {
  32. $("body").append("<link rel='stylesheet' href='//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css'>");
  33.  
  34. if (localStorage.getItem("HideLinkStyle") != "HideShow")
  35. $("body").append(GetRemoveStyle());
  36. }
  37.  
  38. function CreateFilter()
  39. {
  40. $('.dropdown-nav-top:first').parent().append("<select id='ThreadFilter'><option value='Unignored' selected='true'>Block Posts</option><option value='All'>Show All Posts</option></select>&nbsp;");
  41. }
  42.  
  43. function GetRemoveStyle()
  44. {
  45. var HideThreadStyle = 'margin-left: -11px; margin-top: -38px;';
  46. var HideThreadStyle2 = 'padding-left:10px; margin-left:-45px; margin-top:-2px;';
  47.  
  48. RemoveStyle = '<style id="RemoveStyle">';
  49. RemoveStyle += '.threadbit > td > a[id^="RemoveThread"]:before { content: "x"; font-size: 15pt;}';
  50. RemoveStyle += '.threadbit > td > a[id^="RemoveThread"] { position: absolute !important; ' + (navigator.userAgent.search("Chrome") >= 0 ? HideThreadStyle : HideThreadStyle2) + ' font-size: 0pt; visibility: hidden !important;}';
  51. RemoveStyle += '.threadbit > td:hover > a[id^="RemoveThread"] { visibility: visible !important; } ';
  52.  
  53. RemoveStyle += '.threadbit > td > a[id^="RemoveUser"]:before { content: "x"; font-size: 15pt;} ';
  54. RemoveStyle += '.threadbit > td > a[id^="RemoveUser"] { position: absolute !important; padding-left:10px; margin-left:-25px; margin-top:-2px; font-size: 0pt; visibility: hidden !important;} ';
  55. RemoveStyle += '.threadbit > td:hover > a[id^="RemoveUser"] { visibility: visible !important; } ';
  56. RemoveStyle += '</style>';
  57.  
  58. return RemoveStyle;
  59. }
  60.  
  61. function UpdateHideLinks()
  62. {
  63. $("a[name][name!='last']").each(function( index,value ) { AddHideLink($(this).parent()[0])});
  64. }
  65.  
  66. function CreateEventHandlers()
  67. {
  68. $('#ThreadFilter').change(function()
  69. {
  70. var sThreadFilterVal = $('#ThreadFilter').val();
  71. if (sThreadFilterVal == 'All')
  72. {
  73. Posts.forEach( function(s) {
  74. s.Hide = false;
  75. } )
  76. }
  77. UpdateHideLinks();
  78. UpdatePosts();
  79. });
  80. // $('#OpenFilterCP').click(OpenFilterCP);
  81. // $('#AddIgnoredUserButton').click(AddToIgnoredUserList);
  82. // $('input[name="HideLinkStyle"]').change(function () { localStorage.setItem('HideLinkStyle', this.value); RemoveHideLinks(); SaveLastUpdate();});
  83. }
  84.  
  85. function RemoveHideLinks()
  86. {
  87. $("a[id*='RemoveThread']").remove();
  88. $("a[id*='RemoveUser']").remove();
  89.  
  90. $("#RemoveStyle").remove();
  91.  
  92. if (localStorage.getItem("HideLinkStyle") != "HideShow")
  93. $("body").append(GetRemoveStyle());
  94. }
  95.  
  96.  
  97. function AddHideLink(currentPost)
  98. {
  99.  
  100. IgnoredUserList = GetListFromLocalStorage('IgnoredUserList');
  101.  
  102. nPost = $(currentPost).find('a[name][name!="last"]')[0];
  103. nPostID = $(nPost).attr('name');
  104. MemberLink = $(currentPost).find('a[href*="?username="]')[0];
  105. if (MemberLink)
  106. {
  107. nUserID = MemberLink.href.replace("http://www.dropzone.com/cgi-bin/forum/gforum.cgi?username=","").replace(";","");
  108.  
  109. var bUserIgnored = (containsObject(nUserID,IgnoredUserList) == -1) ? false : true;
  110.  
  111. var UserIgnoreText = bUserIgnored ? "Restore User" : "RU";
  112. var ThreadIgnoreText = bUserIgnored ? "Show" : "Hide";
  113.  
  114. if ($(currentPost).has("a[id*='HidePost" + nPostID + "']").length === 0)
  115. {
  116. var RemoveUserLinks = $('a[id*="RemoveUser' + nUserID + '"]').toArray();
  117.  
  118. sUserIDReference = (RemoveUserLinks.length > 0) ? nUserID + RemoveUserLinks.length : nUserID;
  119.  
  120. if (localStorage.getItem("HideLinkStyle") == "HideShow")
  121. $(MemberLink).after("<br /><a id='RemoveUser" + sUserIDReference + "'>" + UserIgnoreText + " User</a>");
  122. else
  123. $(MemberLink).before("<a id='RemoveUser" + sUserIDReference + "'>" + UserIgnoreText + " User</a>");
  124.  
  125. $('#RemoveUser' + sUserIDReference).click({param1: nUserID, param2: 'IgnoredUserList', param3: UpdatePosts, param4: currentPost}, IgnoreItem);
  126. $(nPost).before("<a id='HidePost" + nPostID + "'>" + ThreadIgnoreText + "</a>");
  127.  
  128. $('#HidePost' + nPostID).click({param1: nPostID, param2: 'IgnoreList', param3: UpdatePosts, param4: currentPost}, IgnoreItem);
  129.  
  130. addItem = {};
  131. addItem.ID = nPostID;
  132. addItem.UserID = nUserID;
  133. addItem.Hide = bUserIgnored;
  134. addItem.Post = currentPost;
  135. Posts.push(addItem);
  136.  
  137. }
  138. var postIndex = containsObject(nPostID,Posts);
  139. var bThreadIgnored = postIndex >= 0 ? Posts[postIndex].Hide : false;
  140.  
  141. ThreadIgnoreText = bThreadIgnored ? "Show post from " + nUserID : "Hide";
  142.  
  143. $('#HidePost' + nPostID).text(ThreadIgnoreText);
  144. $('a[id*="RemoveUser' + nUserID +'"').text(UserIgnoreText);
  145. }
  146. }
  147.  
  148. function UpdatePosts()
  149. {
  150. nShownCount = 0;
  151. $('#ThreadFilter').blur();
  152. localStorage.setItem('ThreadFilter',document.getElementById("ThreadFilter").value);
  153. IgnoredUserList = GetListFromLocalStorage('IgnoredUserList');
  154. currentVisibleThreads = [];
  155. var sThreadFilterVal = $('#ThreadFilter').val();
  156. $("a[name][name!='last']").each(function(index)
  157. {
  158. nPostID = $(this).attr('name');
  159.  
  160. sParent = $(this).parent()[0];
  161. sUser = $(sParent).find('a[href*="gforum.cgi?username="]')[0];
  162. sUserID = sUser.href.replace("http://www.dropzone.com/cgi-bin/forum/gforum.cgi?username=","").replace(";","");
  163. var postIndex = containsObject(nPostID,Posts);
  164. var bThreadIgnored = postIndex >= 0 ? Posts[postIndex].Hide : false;
  165. if (bThreadIgnored)
  166. $(this).siblings('table').hide();
  167. else
  168. {
  169. currentVisibleThreads.push(nPostID);
  170. nShownCount++;
  171. $(this).siblings('table').show();
  172. }
  173. });
  174. }
  175.  
  176. function IgnoreItem(event)
  177. {
  178. var nCurrentID = event.data.param1;
  179. var sList = event.data.param2;
  180.  
  181. if (sList == 'IgnoredUserList')
  182. {
  183. addItem = {}
  184. addItem.ID = nCurrentID;
  185. CurrentList = GetListFromLocalStorage(sList);
  186. nFoundIndex = containsObject(nCurrentID,CurrentList);
  187.  
  188. if (nFoundIndex == -1)
  189. CurrentList.push(addItem);
  190. else
  191. CurrentList.splice(nFoundIndex,1);
  192. localStorage.setItem(sList, JSON.stringify(CurrentList));
  193. Posts.forEach( function(s) {
  194. if (s.UserID == nCurrentID)
  195. {
  196. s.Hide = nFoundIndex == -1 ? true : false;
  197. AddHideLink(s.Post);
  198. }
  199. } )
  200.  
  201. }
  202. else
  203. {
  204. Posts.forEach( function(s) {
  205. if (s.ID == nCurrentID)
  206. {
  207. s.Hide = !s.Hide;
  208. AddHideLink(s.Post);
  209. }
  210. } )
  211. }
  212. if (event.data.param3)
  213. event.data.param3();
  214.  
  215.  
  216.  
  217. return 0;
  218. }
  219. function GetListFromLocalStorage(sListName)
  220. {
  221. return localStorage.getItem(sListName) ? JSON.parse(localStorage.getItem(sListName)) : [];
  222. }
  223.  
  224. function containsObject(id, list) {
  225. var i;
  226. for (i = 0; i < list.length; i++) {
  227. if (list[i].ID == id) {
  228. return i;
  229. }
  230. }
  231.  
  232. return -1;
  233. }