skyscrapercity unread threads opener

open unread threads in separates tab

  1. // SkyscraperCity new threads opener
  2. // version 1.0.8
  3. // 2020-04-29
  4. //
  5. // --------------------------------------------------------------------
  6. //
  7. // This is a Greasemonkey user script.
  8. //
  9. // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
  10. // Then restart Firefox and revisit this script.
  11. // Under Tools, there will be a new menu item to "Install User Script".
  12. // Accept the default configuration and install.
  13. //
  14. // To uninstall, go to Tools/Manage User Scripts,
  15. // select "SkyscraperCity new threads opener", and click Uninstall.
  16. //
  17. // --------------------------------------------------------------------
  18. //
  19. // ==UserScript==
  20. // @name skyscrapercity unread threads opener
  21. // @description open unread threads in separates tab
  22. // @include https://www.skyscrapercity.com/tags.php*
  23. // @include https://www.skyscrapercity.com/subscription.php*
  24. // @include https://www.skyscrapercity.com/watched/*
  25. // @include https://www.skyscrapercity.com/forums/*
  26. // @version 1.0.8
  27. // @namespace http://broman.pl/gmscripts/skyscraper-opener
  28. // @grant GM.openInTab
  29. // ==/UserScript==
  30.  
  31. console.log('Start of GM script');
  32.  
  33. (function() {
  34.  
  35. console.log ('script start');
  36. var threadTable = getTable();
  37.  
  38. if (getAllUnread() > 0) {
  39. var openAllLinks = document.createElement('a');
  40. openAllLinks.href = '#';
  41. openAllLinks.id = 'link-opener';
  42. openAllLinks.addEventListener('click', openAllUnread, false);
  43. openAllLinks.appendChild(document.createTextNode('Open All unread threads '));
  44. var divLink = document.createElement('div');
  45. divLink.classList.add("block-outer-opposite");
  46. divLink.setAttribute("style", "margin-right:10px;margin-top:7px;");
  47. divLink.appendChild(openAllLinks);
  48.  
  49.  
  50. var menuDiv = threadTable.previousElementSibling;
  51. if (menuDiv == null) {
  52. console.log ('no place for button');
  53.  
  54. }
  55. var otherButton = menuDiv.querySelector('div.california-outer-upper-nav');
  56.  
  57. menuDiv.insertBefore(divLink,otherButton);
  58. //menuDiv.appendChild(divLink);
  59.  
  60. } else {
  61. console.log("no links to open");
  62. }
  63.  
  64. })();
  65.  
  66. function getAllUnread() {
  67. return openAllUnread(1)
  68. }
  69. function openAllUnread(callType) {
  70. var toOpen = 0;
  71. var threadTable = getTable();
  72.  
  73. if (threadTable !== null) {
  74. console.log ('threadTable exist');
  75. var rows = threadTable.querySelectorAll("div.is-unread[qid='thread-item']");
  76. var rowsCount = rows.length;
  77. for(var i=0; i<rowsCount;i++){
  78. var row = rows[i];
  79. var titleLink = row.querySelector("a[qid='thread-item-title']");
  80. if(callType != 1) {
  81. //console.log ('[open start');
  82. //console.log ("link " + links[links.length-1]);
  83. try {
  84. GM.openInTab(titleLink.href, true);
  85. } catch(err) {
  86. console.log(err.message);
  87. }
  88. //console.log ('open end]');
  89. titleLink.style.color="";
  90. row.classList.remove("is-unread");
  91. } else {
  92. titleLink.style.color="#bb86fc";
  93. }
  94.  
  95. }
  96.  
  97. if (callType == 1) {
  98. console.log ('links to open');
  99. return rowsCount;
  100. }
  101. }
  102. }
  103.  
  104. function getTable() {
  105. var threadTable = document.querySelector("div[qid='followed-discussions-section']");
  106. if (threadTable === null) {
  107. var threadTable = document.querySelector("div[qid='forum-page-thread-items']");
  108. if (threadTable != null) {
  109. threadTable = threadTable.parentNode;
  110. threadTable = threadTable.parentNode;
  111. threadTable = threadTable.parentNode;
  112. }
  113. }
  114. if (threadTable === null) {
  115. var threadTable = document.querySelector("div[qid='thread-item-parent']");
  116. if (threadTable != null) {
  117. threadTable = threadTable.parentNode;
  118. threadTable = threadTable.parentNode;
  119. threadTable = threadTable.parentNode;
  120. }
  121. }
  122. if (threadTable == null) {
  123. console.log("no thread table");
  124. }
  125. return threadTable;
  126. }
  127.  
  128. console.log('End of GM script');