skyscrapercity unread threads opener

open unread threads in separates tab

目前為 2016-08-04 提交的版本,檢視 最新版本

// SkyscraperCity new threads opener
// version 0.2 BETA!
// 2014-09-17
//
// --------------------------------------------------------------------
//
// 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       http://www.skyscrapercity.com/tags.php*
// @include       http://www.skyscrapercity.com/subscription.php*
// @version       1.0.2
// @namespace     http://broman.pl/gmscripts/skyscraper-opener
// @grant		  GM_log
// @grant		  GM_openInTab
// ==/UserScript==

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

(function() { 

	GM_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'));
       threadTable.rows[0].cells[0].appendChild(openAllLinks);
    }
 
})();

function getAllUnread() {
    return openAllUnread(1)
}
function openAllUnread(callType) {
    var toOpen = 0;
    var threadTable = getTable();
    var url = window.location.href;
    var expectedColumnNumber = -1
    if (url.indexOf('subscription.php') > 0) {
       expectedColumnNumber = 6;
    } else if(url.indexOf('tags.php') > 0) {
       expectedColumnNumber = 7; 
    }
    if (threadTable != null) {
       GM_log ('threadTable exist'); 
       var rowsCount = threadTable.rows.length;
       for(var i=0; i<threadTable.rows.length;i++){
          var row = threadTable.rows[i];
          cellCount = row.cells.length;
           if(cellCount == expectedColumnNumber) {
              var fCell = row.cells[0];
              var img = fCell.querySelector('IMG');
               if(img.src.substr(-8) == '_new.gif') {                   
                   links = row.cells[2].querySelectorAll('A');                   
                   if(callType != 1) {
                      GM_openInTab(links[links.length-1].href);
                      links[links.length-1].style.color="";
                      img.src = img.src.replace("_new","");
                      var titles = row.cells[2].querySelectorAll('A[style="font-weight:bold"]');
                      for(var j=0; j<titles.length;j++){ 
                      	titles[j].removeAttribute("style");
                      }
                   } else {
	                   links[links.length-1].style.color="magenta";
                   }
                   toOpen++;
               }

           }
    
       }
    }

    if (callType == 1) {
		return toOpen;
    } else {
		document.getElementById('link-opener').outerHTML = "";
		return false;
	}
}

function getTable() {
	var threadTable = document.getElementById('threadslist');
    if (threadTable == null) {
        threadTable = document.querySelector('form[action*="dostuff"] table');        
    } 
    return threadTable;
}

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