There are 1 previous version of this script.
// ==UserScript==
// @name AllegroTools (Cafe) dla IE i FF
// @namespace http://www.allegrotoolsie.hopto.org/
// @description Dodatkowe narzedzia pomocne przy przegladaniu Cafe Allegro // v0.20100129.0
// @include http*://*allegro.pl/spolecznosc/
// @include http*://*allegro.pl/phorum/read.php?*
// @include http*://*allegro.pl/phorum/list.php?*
// @include http*://*allegro.pl/phorum/show_user_profile.php?*
// ==/UserScript==
/////////////////////////////////////////////////////////////////
// Returns the number-th parent node of the element
function getParentNode(element, number)
{
var parent = element;
while((number > 0) && (parent))
{
parent = parent.parentNode;
number--;
}
return parent;
}
// In FF childNodes returns also #text nodes that represents
// the whitespaces in the HTML source. IE skips these nodes
// For IE and FF use this method instead od childNodes property
// to return all children of an element.
// NOTE: this method skips ALL #text nodes (not only whitespaces)
function getChildNodes(element)
{
var children = new Array();
if(element)
{
var child = element.firstChild;
while(child)
{
if (child.nodeType == 1)
{
children.push(child);
}
child = child.nextSibling;
}
}
return children;
}
// Returns the number-th next sibling of the element
// for IE/FF compatibility skips #text nodes
function getNextSibling(element, number)
{
var sibling = element;
while((number > 0) && (sibling))
{
sibling = sibling.nextSibling;
if (sibling && (sibling.nodeType == 1))
{
number--;
}
}
return sibling;
}
// IE specific functions
function select()
{
if (arguments.length>1) {
var node = arguments[0];
for (var i=1; i<arguments.length; i++) {
if (typeof(arguments[i])=='string') {
node = node.getElementById(arguments[i]);
} else {
var nodeIdx = arguments[i];
var children = getChildNodes(node);
if (nodeIdx<children.length) {
node = children[nodeIdx];
} else {
node = null;
break;
}
}
}
}
return node;
}
function modifyMenus()
{
var linksTable = document.links;
var menuTop = false;
var menuBottom = false;
if (linksTable)
{
for(var i = 0; i < linksTable.length; i++)
{
if (linksTable[i].href.match("phorum_search.php") && (linksTable[i].className == "spec-flex"))
{
if(menuTop)
{
menuBottom = getParentNode(linksTable[i], 2);
break;
}
else
{
menuTop = getParentNode(linksTable[i], 5);
}
}
}
if(menuTop && menuBottom)
{
// add spacing between bottom menu and message edit box
var span = document.createElement("SPAN");
span.innerHTML = "<BR>";
getParentNode(menuBottom, 1).insertBefore(span, getNextSibling(menuBottom, 1));
// clone the top menu at the bottom
menuBottom = getParentNode(menuBottom, 1).replaceChild(menuTop.cloneNode(true), menuBottom);
}
}
}
function modifyIndexMenus()
{
var linksTable = document.links;
var menuTop = false;
var menuBottom = false;
if (linksTable)
{
for(var i = 0; i < linksTable.length; i++)
{
if ((menuTop == false) && linksTable[i].href.match("post.php") && (linksTable[i].className == "spec-flex"))
{
menuTop = getParentNode(linksTable[i], 1);
}
if ((menuBottom == false) && linksTable[i].href.match(/list\.php\?f=\d+&r=1/) && (linksTable[i].className == "spec-flex"))
{
menuBottom = getParentNode(linksTable[i], 1);
}
if(menuTop && menuBottom)
{
// merge bottom menu with top menu
menuTop.innerHTML = menuTop.innerHTML + "<BR>" + menuBottom.innerHTML;
// clone merged top menu at the bottom
menuBottom = getParentNode(menuBottom, 1).replaceChild(menuTop.cloneNode(true), menuBottom);
break;
}
}
}
}
function addCoreThreadLink()
{
var coreThreadLink = document.location.href.replace(/&i=\d+|i=\d+&|#href\d+/g, "");
if(coreThreadLink.match(/t=(\d+)/))
{
var threadNo = RegExp.$1;
var div = document.getElementById("div" + threadNo);
if(div)
{
var coreThreadParent = getParentNode(div, 1);
if(coreThreadParent)
{
coreThreadLink = coreThreadLink + "&i=" + threadNo;
coreThreadParent.innerHTML = coreThreadParent.innerHTML.replace(/<STRONG>(.*?)<\/STRONG>/i, "<STRONG><a href='" + coreThreadLink + "'>$1</a></STRONG>");
}
}
}
}
function addGlobalSearch()
{
var div = document.getElementById("CmutyCafe");
if(div)
{
var searchLink = document.createElement("span");
searchLink.style.verticalAlign = '100%';
searchLink.innerHTML = "<strong> <a href='http://allegro.pl/phorum/phorum_search.php?f=298&globalsearch=1'>Szukaj w calym Cafe Allegro</a></strong>";
getParentNode(div, 1).insertBefore(searchLink, div);
}
}
function addUserPostsLink()
{
var spans = document.getElementsByTagName("SPAN");
if(spans)
{
for(var i = 0; i < spans.length; i++)
{
if(spans[i].className == "uname")
{
if(spans[i].innerHTML.match(/<a.*?>(.*?)<\/a>/i))
{
var uname = RegExp.$1;
var imgs = document.getElementsByTagName("IMG");
if(imgs)
{
for(var j = 0; j < imgs.length; j++)
{
if(imgs[j].className == "forumAvatar")
{
var link = document.createElement("DIV");
link.innerHTML = "<a href='http://allegro.pl/phorum/phorum_search.php?search=&globalsearch=1&match=1&date=360&fldauthor=" + uname + "&fldauthor_exactly=1&f=299&date_order=0&search_task=1' target='_blank'>Znajdz posty uzytkownika</a>";
getParentNode(imgs[j], 1).insertBefore(link, getNextSibling(imgs[j], 1));
break;
}
}
}
}
break;
}
}
}
}
function allegrotoolsCafe()
{
if(document.location.pathname.match("/phorum/read.php"))
{
modifyMenus();
addCoreThreadLink();
}
else if(document.location.pathname.match("/phorum/list.php"))
{
modifyIndexMenus();
}
else if(document.location.pathname.match("/spolecznosc"))
{
addGlobalSearch();
}
else if(document.location.pathname.match("/phorum/show_user_profile.php"))
{
addUserPostsLink();
}
}
/////////////////////////////////////////////////////////////////
// Start Allegro Tools Cafe script
/////////////////////////////////////////////////////////////////
allegrotoolsCafe()