skyscrapercity unread threads opener

open unread threads in separates tab

当前为 2014-10-12 提交的版本,查看 最新版本

  1. // SkyscraperCity new threads opener
  2. // version 0.2 BETA!
  3. // 2014-09-17
  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 http://www.skyscrapercity.com/tags.php*
  23. // @include http://www.skyscrapercity.com/subscription.php*
  24. // @version 1.0.1
  25. // @namespace http://broman.pl/gmscripts/skyscraper-opener
  26. // @grant GM_log
  27. // @grant GM_openInTab
  28. // ==/UserScript==
  29.  
  30. console.log('Start of GM script');
  31.  
  32. (function() {
  33.  
  34. GM_log ('script start');
  35. var threadTable = getTable();
  36. if (getAllUnread() > 0) {
  37. var openAllLinks = document.createElement('a');
  38. openAllLinks.href = '#';
  39. openAllLinks.id = 'link-opener';
  40. openAllLinks.addEventListener('click', openAllUnread, false);
  41. openAllLinks.appendChild(document.createTextNode(' Open All unread threads'));
  42. threadTable.rows[0].cells[0].appendChild(openAllLinks);
  43. }
  44. })();
  45.  
  46. function getAllUnread() {
  47. return openAllUnread(1)
  48. }
  49. function openAllUnread(callType) {
  50. var toOpen = 0;
  51. var threadTable = getTable();
  52. var url = window.location.href;
  53. var expectedColumnNumber = -1
  54. if (url.contains('subscription.php')) {
  55. expectedColumnNumber = 6;
  56. } else if(url.contains('tags.php')) {
  57. expectedColumnNumber = 7;
  58. }
  59. if (threadTable != null) {
  60. GM_log ('threadTable exist');
  61. var rowsCount = threadTable.rows.length;
  62. for(var i=0; i<threadTable.rows.length;i++){
  63. var row = threadTable.rows[i];
  64. cellCount = row.cells.length;
  65. if(cellCount == expectedColumnNumber) {
  66. var fCell = row.cells[0];
  67. var img = fCell.querySelector('IMG');
  68. if(img.src.substr(-8) == '_new.gif') {
  69. links = row.cells[2].querySelectorAll('A');
  70. if(callType != 1) {
  71. GM_openInTab(links[links.length-1].href);
  72. links[links.length-1].style.color="";
  73. img.src = img.src.replace("_new","");
  74. var titles = row.cells[2].querySelectorAll('A[style="font-weight:bold"]');
  75. for(var j=0; j<titles.length;j++){
  76. titles[j].removeAttribute("style");
  77. }
  78. } else {
  79. links[links.length-1].style.color="magenta";
  80. }
  81. toOpen++;
  82. }
  83.  
  84. }
  85. }
  86. }
  87.  
  88. if (callType == 1) {
  89. return toOpen;
  90. } else {
  91. document.getElementById('link-opener').outerHTML = "";
  92. return false;
  93. }
  94. }
  95.  
  96. function getTable() {
  97. var threadTable = document.getElementById('threadslist');
  98. if (threadTable == null) {
  99. threadTable = document.querySelector('form[action*="dostuff"] table');
  100. }
  101. return threadTable;
  102. }
  103.  
  104. console.log('End of GM script');