Feedly Hide Read Items When Done

Hide the read items list when you have finished reading unread items.

  1. // ==UserScript==
  2. // @name Feedly Hide Read Items When Done
  3. // @version 1.2
  4. // @namespace geekrunner
  5. // @include *cloud.feedly.com/*
  6. // @include *feedly.com/*
  7. // @description Hide the read items list when you have finished reading unread items.
  8. // ==/UserScript==
  9.  
  10. // VERSION HISTORY
  11. // 1.2 - A nicer way to handle hiding the list of articles, doesn't completely remove them from the DOM.
  12. // 1.1.5.1 - Bugfix for last update.
  13. // 1.1.5 - Updated element to check for due to Feedly's August 2017 update removing the magic string.
  14. // 1.1.4 - Updated magic string from "No unread articles" to "No unread stories".
  15. // 1.1.3 - Reference one fewer element from DOM in hopes of having less DOM-based bugs.
  16. // 1.1.2 - Fix for Feedly's update to DOM.
  17. // 1.1.1 - Fix issue where the page refreshes while you're still reading the last article.
  18. // 1.1 - Fix for updated version of feedly.
  19. // 1.0 - Initial Release.
  20. (function() {
  21. console.debug("[FHRIWD] - running");
  22. var tweakXHR = function () {
  23. console.debug("[FHRIWD] Customizing XMLHttpRequest.");
  24. try {
  25. XMLHttpRequest.prototype.open_old = XMLHttpRequest.prototype.open;
  26. XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
  27. this.addEventListener("readystatechange", function() {
  28. try {
  29. var unreadCountSpan = document.querySelector("div.mark-as-read-button-group.button.secondary button span");
  30. if (unreadCountSpan === null || Number(unreadCountSpan.textContent.trim()) === 0) {
  31. if (document.querySelector("div.inlineFrame.read.selected") !== null) { //Don't hide when still reading the last article.
  32. console.info("[FHRIWD] Still reading last item, doing nothing.");
  33. } else {
  34. console.info("[FHRIWD] All items read - hiding timeline.");
  35. var divsToHide = document.querySelectorAll("div.list-entries");
  36.  
  37. for (var i=0; i<divsToHide.length; i++) {
  38. if (divsToHide[i].parentNode.style.display != "none") {
  39. divsToHide[i].parentNode.style.display = "none";
  40. }
  41.  
  42. if (i===0 && document.getElementById("noUnreadItems") === null) {
  43. var noUnreadPara = document.createElement("p");
  44. noUnreadPara.id = "noUnreadItems";
  45. noUnreadPara.appendChild(document.createTextNode("No Unread Items"));
  46. divsToHide[i].parentNode.parentNode.appendChild(noUnreadPara);
  47. }
  48. }
  49. }
  50. } else {
  51. var noUnreadPara2 = document.getElementById("noUnreadItems");
  52. if (noUnreadPara2 !== null) {
  53. noUnreadPara2.parentNode.removeChild(noUnreadPara2);
  54. }
  55. }
  56. } catch (e) {
  57. console.error("[FHRIWD] " + e.message);
  58. }
  59. }, false);
  60. this.open_old.call(this, method, url, async, user, pass);
  61. };
  62. } catch (e) {
  63. console.error("[FHRIWD] " + e.message);
  64. }
  65. console.debug("[FHRIWD] Finished customizing XMLHttpRequest.");
  66. };
  67. //Inject the script into the page.
  68. var script = document.createElement('script');
  69. script.setAttribute('type','application/javascript');
  70. script.textContent = '(' + tweakXHR + ')();';
  71. document.body.appendChild(script); //run the script
  72. document.body.removeChild(script); //cleanup
  73. console.debug("[FHRIWD] - complete");
  74. }());