skyscrapercity unread threads opener

open unread threads in separates tab

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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');