skyscrapercity unread threads opener

open unread threads in separates tab

目前为 2020-03-26 提交的版本。查看 最新版本

// SkyscraperCity new threads opener
// version 1.0.4
// 2018-08-30
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "SkyscraperCity new threads opener", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          skyscrapercity unread threads opener
// @description   open unread threads in separates tab
// @include       https://www.skyscrapercity.com/tags.php*
// @include       https://www.skyscrapercity.com/subscription.php*
// @include       https://www.skyscrapercity.com/watched/*
// @version       1.0.6
// @namespace     http://broman.pl/gmscripts/skyscraper-opener
// @grant         GM.openInTab
// ==/UserScript==

console.log('Start of GM script');

(function() {

	console.log ('script start');
	var threadTable = getTable();

    if (getAllUnread() > 0) {
      var openAllLinks = document.createElement('a');
      openAllLinks.href = '#';
      openAllLinks.id = 'link-opener';
      openAllLinks.addEventListener('click', openAllUnread, false);
      openAllLinks.appendChild(document.createTextNode('Open All unread threads   '));
      var divLink = document.createElement('div');
      divLink.classList.add("block-outer-opposite");
      divLink.setAttribute("style", "margin-right:10px;"); 
      divLink.appendChild(openAllLinks);

      
      var menuDiv = threadTable.previousElementSibling;
      if (menuDiv == null) {
        console.log ('no place for button');
        
      }
      var otherButton = menuDiv.querySelector('div.california-outer-upper-nav');
      
      menuDiv.insertBefore(divLink,otherButton);
      //menuDiv.appendChild(divLink);
      
    }

})();

function getAllUnread() {
    return openAllUnread(1)
}
function openAllUnread(callType) {
    var toOpen = 0;
    var threadTable = getTable();

    if (threadTable !== null) {
      console.log ('threadTable exist');
      var rows = threadTable.querySelectorAll("div.is-unread[qid='thread-item']");
      var rowsCount = rows.length;
      
      for(var i=0; i<rowsCount;i++){
          var row = rows[i];
          var titleLink = row.querySelector("a[qid='thread-item-title']");
          if(callType != 1) {
              //console.log ('[open start');
              //console.log ("link " + links[links.length-1]);
              try {
                GM.openInTab(titleLink.href, true);
              } catch(err) {
                console.log(err.message);
              }
              //console.log ('open end]');
              titleLink.style.color="";
            	row.classList.remove("is-unread");
          } else {
            titleLink.style.color="magenta";
          }

       }

      if (callType == 1) {
          console.log ('links to open');
          return rowsCount;
        }      
    }
}

function getTable() {
	var threadTable = document.querySelector("div[qid='followed-discussions-section']");
  if (threadTable == null) {
		var threadTable = document.querySelector("div[qid='thread-item-parent']");
		threadTable = threadTable.parentNode;
		threadTable = threadTable.parentNode;
		threadTable = threadTable.parentNode;
  }
  return threadTable;
}

console.log('End of GM script');