skyscrapercity unread threads opener

open unread threads in separates tab

目前為 2014-10-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// 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.1
// @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.contains('subscription.php')) {
       expectedColumnNumber = 6;
    } else if(url.contains('tags.php')) {
       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');