What.cd Hide unwated subscription posts

Adds Ignore link on the What.cd "grouped unread post history" page

  1. // ==UserScript==
  2. // @name What.cd Hide unwated subscription posts
  3. // @namespace funeral_meat
  4. // @include https://what.cd/userhistory.php?*action=posts&userid=*
  5. // @version 1
  6. // @grant none
  7. // @description Adds Ignore link on the What.cd "grouped unread post history" page
  8. // ==/UserScript==
  9.  
  10. //initialize empty array for storing ids to ignore
  11. if(localStorage["wcd_ignorethreads"] == undefined) {
  12. //run the next 2 lines to reset ignored posts
  13. wcd_ignore_arr = [];
  14. localStorage["wcd_ignorethreads"] = JSON.stringify(wcd_ignore_arr);
  15. }
  16.  
  17. //load and clean array of duplicates
  18. wcd_ignore_arr = $.unique(JSON.parse(localStorage["wcd_ignorethreads"]));
  19.  
  20. window.hidelink = function(id, tname) { // e.g. id = "threadid=123456", tname = "Thread title"
  21. if(confirm("Ignore the thread '" + unescape(tname) + "'?")) {
  22. wcd_ignore_arr.push(id);
  23. localStorage["wcd_ignorethreads"] = JSON.stringify(wcd_ignore_arr);
  24. // hide instantly after confirmation - still to figure out
  25. }
  26. }
  27.  
  28. threads = document.getElementsByClassName("thin")[0].getElementsByClassName("forum_post");
  29.  
  30. //add ignore link or hide it if it's already in the list
  31. for(i = 0; i < threads.length; i++) {
  32. ti = threads[i];
  33. tname = ti.getElementsByClassName("tooltip")[1].innerHTML;
  34. tnameesc = escape(tname); //for handling single and double quotation marks, and maybe other special chars
  35. tid = ti.innerHTML.match(/threadid\=[0-9]+/)[0];
  36. //id number required to find link injection point
  37. postid = ti.id.split("post")[1];
  38. if(wcd_ignore_arr.indexOf(tid) == -1) {
  39. //make function string
  40. hl = "'" + 'hidelink("' + tid + '","' + tnameesc + '")' + "'";
  41. //make html string
  42. hidelink = '<a href="javascript:void(0)"' + "onClick = " + hl + '; class = "brackets">Ignore</a>';
  43. //add ignore link before subscribe link
  44. tispan = ti.getElementsByTagName("span");
  45. tispan["bar"+postid].innerHTML = hidelink + tispan["bar"+postid].innerHTML;
  46. } else {
  47. ti.hidden = "true";
  48. }
  49. }