// ==UserScript==
// @name GamersGlobal - Scroll to Newest Comments
// @description Jump to the next or previous "--neu" comment on GamersGlobal.de
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant GM.addStyle
// @grant GM_addStyle
// @include http*://*.gamersglobal.de/*
// @version 1.1.2
// ==/UserScript==
// https://gist.github.com/raw/2625891/waitForKeyElements.js
/*
original script: https://userscripts.org/scripts/review/3128
modifications by nova
*/
//HEADERSpath = "html/body//div[@id='site-header']|//div[@id='comments']//span[contains(@class, 'new')]";
//HEADERSpath = "html/body//div[@id='comments']//span[contains(@class, 'new')]";
HEADERSpath = "html/body//div[@id='comments']//div[contains(@class, 'comment-new')]";
HEADERS = new Array;
PANpos = -1;
var interval;
function XPOrderedSnap(node, xpath)
{
return document.evaluate(xpath, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
}
function addPanel()
{
window.clearInterval(interval);
var headersSnap = XPOrderedSnap(document, HEADERSpath);
for (var i = 0; i < headersSnap.snapshotLength; i++)
{
HEADERS[i] = headersSnap.snapshotItem(i); // could mung here if needed
}
if (HEADERS.length < 1)
{
return;
}
GM.addStyle('#hsPanel { position: fixed; padding: 3px; background-color: #C8C8C8; border: 1px solid #AAAAAA; z-index: 10; } #hsPanel button { line-height: 18px; width: 30px; }');
PAN = document.createElement('div');
PAN.id = 'hsPanel';
PAN.innerHTML
= ''
+ ''
+ '';
// + '';
document.body.appendChild(PAN);
rotatePanel(); // to give an initial position
function addClick(id, func)
{
document.getElementById(id).addEventListener("click", func, false);
}
addClick("hsTop", function(e){ document.getElementById('site-header').scrollIntoView();});
addClick("hsUp", function(e){ searchUp(e);});
addClick("hsDown", function(e){ searchDown(e);});
// addClick("hsRotate", function(e){rotatePanel(e);});
}
function findPosY(obj)
{ // from: www.quirksmode.org/js/findpos.html
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
}
else if (obj.y)
{
curtop += obj.y;
}
return curtop;
}
function searchDown(e)
{
if (e)
{
e.target.blur();
}
var viewY = window.scrollY + 1;
for (i = 0; i < HEADERS.length; i++)
{
if (findPosY(HEADERS[i]) > viewY)
{
return HEADERS[i].wrappedJSObject.scrollIntoView();
}
}
}
function searchUp(e)
{
if (e)
{
e.target.blur();
}
var viewY = window.scrollY;
for (i = HEADERS.length - 1; i > -1; i--)
{
if (findPosY(HEADERS[i]) < viewY)
{
return HEADERS[i].wrappedJSObject.scrollIntoView();
}
}
}
function rotatePanel(e)
{
if (e)
{
e.target.blur();
}
PANpos = (PANpos + 1) % 4;
var vs = [['0px','0px','',''],
['0px','','','0px'],
['','','0px','0px'],
['','0px','0px','']][PANpos];
var pS = PAN.style;
pS.left = vs[0];
pS.top = vs[1];
pS.right = vs[2];
pS.bottom = vs[3];
}
interval = window.setInterval(addPanel, 0.5 * 1000);