Wykop - scroll to unread comment

Scrolls window to first/next unread comment @ wykop.pl

当前为 2014-06-03 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Wykop - scroll to unread comment
// @description Scrolls window to first/next unread comment @ wykop.pl
// @namespace   Wykop scripts
// @include     http://www.wykop.pl/link/*
// @version     1.2
// @license     MIT License
// @grant       none
// ==/UserScript==

var offsetFix = 0; /* poeksperymentowac, jesli przewija za mało lub za duzo */

if(document.getElementsByClassName('nav fix-b-border')[0].getElementsByTagName('a')[0].href.indexOf('/unreadCommentsToggle/')>0)
{
    var nowe_komcie = document.getElementsByClassName('wblock lcontrast dC  newComment');
    var ile_nowych = nowe_komcie.length;
    var aktual_poz = -1;   
    
    function dodaj_button(komcie_node, ii)
    {
        if (!ile_nowych) return;
        var button_node = document.createElement('button');
        if (ii < ile_nowych - 1)
        {
                button_node.innerHTML = 'NEXT';
                button_node.val = ii + 1;
                button_node.onclick = function() {
                    nowe_komcie[this.val].scrollIntoView(true);
                    window.scrollBy(0, offsetFix);
                    aktual_poz = ii + 1;
                }; /*    button_node.onclick = function(){nowe_komcie[ii+1].scrollIntoView(true);};*/
        }
        else
        {
            button_node.onclick = function() {
                nowe_komcie[0].scrollIntoView(true);
                window.scrollBy(0, offsetFix);
                aktual_poz = 0;
            };
            button_node.innerHTML = 'FIRST';
        }
        komcie_node.appendChild(button_node);
    }
    for (var i = 0; i < ile_nowych; ++i)
    {
        dodaj_button(nowe_komcie[i], i);
    }
    var button_node = document.createElement('button');
    button_node.innerHTML = 'FIRST';
    button_node.onclick = function () {
        nowe_komcie[0].scrollIntoView(true);
        window.scrollBy(0, offsetFix);
        aktual_poz = 0;
    }; /*  document.getElementById('comments-list-entry').appendChild(button_node);*/
    document.getElementById('itemsStream').insertBefore(button_node, document.getElementById('itemsStream').firstChild);
    function nastepny(e)
    {
      e = e || window.event;
      if (e.keyCode == '220')
      {
            aktual_poz = (aktual_poz+1)%ile_nowych;
	    nowe_komcie[aktual_poz].scrollIntoView(true);
            window.scrollBy(0, offsetFix);
      }
    }

    document.onkeydown = nastepny;
}
void 0;