AllegroTools (Comments)

By Pawelsky Last update Aug 30, 2011 — Installed 574 times.

There are 2 previous versions of this script.

Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)

// ==UserScript==
// @name           AllegroTools (komentarze) dla IE i FF
// @namespace      http://www.allegrotoolsie.hopto.org/
// @description    Dodatkowe narzedzia pomocne przy przegladaniu komentarzy uzytkownikow Allegro // v0.20110829.0
// @include        http*://*allegro.pl/show_user.php?*
// ==/UserScript==

(function(){

var SELLER_COLORS = new Array("#FFD9C6", "#FFE8DD");
var BUYER_COLORS = new Array("#C6D9FF", "#DDE8FF");

var SELLER_STRING = "Sprzedaj";
var BUYER_STRING = "Kupuj";

var CHECK_LINKS_BTN = "_check_links_btn_";
var COLORING_CHBX = "_coloring_chkbx_";
var THUMBNAILS_CHBX = "_thumbnails_chkbx_";
var AUTOCHECK_CHBX = "_autocheck_chkbx_";
var ARCH_CHBX = "_arch_chkbx_";
var SHOW_EMPTY_ARCH_CHBX = "_show_empty_arch_chkbx_";

var AT_COLORING = "AT_C_coloring";
var AT_THUMBNAILS = "AT_C_thumbnails";
var AT_AUTOCHECK = "AT_C_autocheck";
var AT_ARCH_PREFIX = "AT_C_arch_";
var AT_SHOW_EMPTY_ARCH = "AT_C_show_empty_arch";

var COMMENTS = new Array();

var BG_BYSTR = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAFRlDm/AAAAB3RJTUUH1gwHDRgVt4pvywAAAAlwSFlzAAAPYQAAD2EBqD+naQAAAARnQU1BAACxjwv8YQUAAAAYSURBVHjaY/j/nwEGoEwQBWEyoovDFQMAkc0N9HFYUnUAAAAASUVORK5CYII=";

var showEmptyArch = true;

//////////////////////////////////////////////
// Generic definitions for archivers
//////////////////////////////////////////////

var ARCH_MULTI_NO = 0;
var ARCH_MULTI_TITLES = 1;
var ARCH_MULTI_AVAILABILITY = 2;

var ARCH_AUCTION_SERVICE_LOGIN = "Aby sprobowac odnalezc i wyswietlic tytul aukcji %service_login%, a nastepnie odswiez te strone";
var ARCH_AUCTION_FOUND = "Aukcja dostepna w archiwum %archive%. Kliknij aby zobaczyc szczegoly";
var ARCH_AUCTION_NOT_FOUND = "Aukcja nie wystepuje w archiwum";
var ARCH_AUCTION_CHECK_IN_PROGRESS = "Pobierane tytulu aukcji, prosze czekac...";
var ARCH_AUCTION_CHECK_ERROR = "Nie udalo sie sprawdzic tytulu aukcji";



function markAuctionNotFound(titleTD)
{
  if(showEmptyArch == true)
  {
    titleTD.innerHTML = ARCH_AUCTION_NOT_FOUND;
  }
  else
  {
    var titleTR = titleTD.parentNode;
    titleTR.parentNode.removeChild(titleTR);
  }
}

function processGenericError(linkChecker, archiver)
{
  var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker.index);
  titleTD.innerHTML = ARCH_AUCTION_CHECK_ERROR;
  linkChecker.unmark(linkChecker.linkLI);
}

function processGenericMultiError(linkChecker, archiver)
{
  for(var i= 0; i < linkChecker.length; i++)
  {
    var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker[i].index);
    titleTD.innerHTML = ARCH_AUCTION_CHECK_ERROR;
    linkChecker[i].unmark(linkChecker[i].linkLI);
  }  
}

function processGenericMultiResponse(d, linkChecker, archiver)
{
  for(var i= 0; i < linkChecker.length; i++)
  {
    var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker[i].index);
    var re = new RegExp(linkChecker[i].auctionNumber + ":(.+)", "i");
    if(d.responseText.match(re))
    {
      var title = "";
      if(archiver.multi == ARCH_MULTI_TITLES)
      {
        title = RegExp.$1;
      }
      else
      {
        title = ARCH_AUCTION_FOUND.replace(/%archive%/, archiver.name);
      }  
      titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker[i].auctionNumber) + "'>" + title + "</a>";
    }
    else
    {
      markAuctionNotFound(titleTD);
    }
    linkChecker[i].unmark(linkChecker[i].linkLI);
  }  
}

//////////////////////////////////////////////
// Definition of ALLEGRO archiver
//////////////////////////////////////////////

function processAllegroResponse(d, linkChecker, archiver)
{
  var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker.index);
  if (d.responseText.match(/\((.{3} \d{2} .{3} \d{4} \d{2}:\d{2}:\d{2} .+?)\)/))
  {
    linkChecker.dateLI.style.fontSize = '8pt';
    linkChecker.dateLI.style.lineHeight = '12px';
    linkChecker.dateLI.innerHTML = "Komentarz: " + linkChecker.dateLI.innerHTML + "<br>Koniec aukcji: " + RegExp.$1;
    var title = getAllegroTitle(d.responseText);
    var price = getAllegroPrice(d.responseText);
    titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker.auctionNumber) + "'>" + title + "</a>" + " - " + price;

    var thumbnailTD = document.getElementById("_thumbnail_" + linkChecker.index);
    if(thumbnailTD)
    {
      var thumbnailURL = getThumbnailURL(d.responseText);
      if(thumbnailURL)
      {
        thumbnailTD.innerHTML = "<img src='" + thumbnailURL + "' border='0' width='64' height='48'></img>";
      }
    }  
  }
  else
  {
    markAuctionNotFound(titleTD);
  }
  linkChecker.unmark(linkChecker.linkLI);
}

function processAllegroError(linkChecker, archiver)
{
  linkChecker.linkLI.innerHTML = getInnerText(linkChecker.linkLI);
  processGenericError(linkChecker, archiver);
}

var ARCH_ALLEGRO = new Archiver("Allegro", ARCH_MULTI_NO,
                                 "http://allegro.pl/show_item.php?item=%number%",
                                 "http://allegro.pl/show_item.php?item=%number%",
                                 processAllegroResponse, processAllegroError);

//////////////////////////////////////////////
// Definition of OLD ALLEGRO archiver
//////////////////////////////////////////////
/*
function processAllegroOldResponse(d, linkChecker, archiver)
{
  var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker.index);
  if(d.responseText.match(/<td class="formtitle" colspan="2">Dane kontaktowe Kontrahenta<\/td>/))
  {
    if (d.responseText.match(/<td class="form2"><a href=\"\/item\d+?.*?.html\">(.*?)<\/a>/))
    {
      titleTD.innerHTML = RegExp.$1;
    }
    else
    {
      markAuctionNotFound(titleTD);
    }
  }
  else
  {
    titleTD.innerHTML = ARCH_AUCTION_SERVICE_LOGIN.replace(/%service_login%/, "<a href='http://allegro.pl/my_allegro.php?mm=1' target='_blank'>zaloguj sie na Allegro</a>");
  }
  linkChecker.unmark(linkChecker.linkLI);
}

var ARCH_OLD_ALLEGRO = new Archiver("Allegro", ARCH_MULTI_NO,
                                     "http://allegro.pl/my_allegro.php?page=feedbacks&type=us_data&item_id=%number%",
                                     null,
                                     processAllegroOldResponse, processGenericError);
*/
//////////////////////////////////////////////
// Definition of PAA archiver
//////////////////////////////////////////////

var ARCH_PAA = new Archiver("PAA", ARCH_MULTI_AVAILABILITY,
                             "http://archiwumallegro.pl/_idsearch.php?id=%number%",
                             "http://archiwumallegro.pl/szukaj/?itemid=%number%",
                             processGenericMultiResponse, processGenericMultiError);

//////////////////////////////////////////////
// Definition of ARCHIWIZATOR archiver
//////////////////////////////////////////////

var ARCH_ARCHIWIZATOR = new Archiver("Archi-wizator", ARCH_MULTI_TITLES,
                                      "http://archi.inosak.org/db/titles.html?id=%number%",
                                      "http://archi.inosak.org/db/item%number%_1.html",
                                      processGenericMultiResponse, processGenericMultiError);

//////////////////////////////////////////////
// Definition of ALLEGROMAT archiver
//////////////////////////////////////////////

function processAllegromatResponse(d, linkChecker, archiver)
{
  for(var i= 0; i < linkChecker.length; i++)
  {
    var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker[i].index);
    var re = new RegExp(linkChecker[i].auctionNumber + ":(.*?)<br>", "i");
    d.responseText.match(re);
    var title = RegExp.$1;
    if(title)
    {
      titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker[i].auctionNumber) + "'>" + title + "</a>";
    }
    else
    {
      markAuctionNotFound(titleTD);
    }
    linkChecker[i].unmark(linkChecker[i].linkLI);
  }  
}

var ARCH_ALLEGROMAT = new Archiver("Allegromat", ARCH_MULTI_TITLES,
                                    "http://allegromat.pl/index.php?a=szukaj_at&str=%number%",
                                    "http://allegromat.pl/index.php?a=szukaj&str=%number%",
                                    processAllegromatResponse, processGenericMultiError);

//////////////////////////////////////////////
// Definition of ARCHIVER archiver
//////////////////////////////////////////////

function processArchiverResponse(d, linkChecker, archiver)
{
  var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker.index);
  d.responseText.replace(/\s/g, " ").match(/<ul class="aukcja"> *?<li> *?<h3>(.*?)<\/h3> *?<\/li> *?<\/ul>/);
  var title = RegExp.$1;
  if(title)
  {
    titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker.auctionNumber) + "'>" + title + "</a>";
  }
  else
  {
    markAuctionNotFound(titleTD);
  }
  linkChecker.unmark(linkChecker.linkLI);
}

var ARCH_ARCHIVER = new Archiver("Archiver", ARCH_MULTI_NO,
                                 "http://www.allegro.archiver.pl/auction/search?itid=%number%",
                                 "http://www.allegro.archiver.pl/auction/search?itid=%number%",
                                 processArchiverResponse, processGenericError);

//////////////////////////////////////////////
// Definition of Xarchiwum archiver
//////////////////////////////////////////////

function processXarchiwumResponse(d, linkChecker, archiver)
{
  var titleTD = document.getElementById(archiver.name + "_title_" + linkChecker.index);
  if (d.responseText.match(/(Aukcja:|Numer aukcji:|Ogl.dasz archiwum aukcji nr:|Archiwum Aukcji nr:)/))
  {
    var title = getXarchiwumTitle(d.responseText);
    if(title)
    {
      titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker.auctionNumber) + "'>" + title + "</a>";
      var price = getXarchiwumPrice(d.responseText);
      if(price)
      {
        titleTD.innerHTML = titleTD.innerHTML + " - " + price;
      }
    }
    else
    {
      titleTD.innerHTML = "<a target='_blank' href='" + archiver.archiveUrl.replace(/%number%/, linkChecker.auctionNumber) + "'>" + ARCH_AUCTION_FOUND.replace(/%archive%/, archiver.name) + "</a>";
    }
  }
  else
  {
    markAuctionNotFound(titleTD);
  }
  linkChecker.unmark(linkChecker.linkLI);
}

var ARCH_XARCHIWUM = new Archiver("xarchiwum", ARCH_MULTI_NO,
                                   "http://xarchiwum.pl/search?s=%number%",
                                   "http://xarchiwum.pl/search?s=%number%",
                                   processXarchiwumResponse, processGenericError);

/////////////////////////////////////////////////////////////////
var ARCHIVERS = new Array(ARCH_ALLEGRO, ARCH_PAA, ARCH_ARCHIWIZATOR, ARCH_ALLEGROMAT, ARCH_ARCHIVER, ARCH_XARCHIWUM);


/////////////////////////////////////////////////////////////////
// Data parsing functions
/////////////////////////////////////////////////////////////////

function getAllegroTitle(str)
{
  if(str.match(/<h1.*?>(.+?)<\/h1>/))
  {
    return RegExp.$1;
  }
  else
  {
    return null;
  }
}

function getAllegroPrice(str)
{
  if(str.match(/<tr>\s*?<th.*?>(Cena Kup Teraz|Aktualna cena).?<\/th>\s*?<td.*?>[\s\S]*?<strong>(.*?)<\/strong>/))
  {
    return RegExp.$2;
  }
  else
  {
    return null;
  }
}

function getXarchiwumTitle(str)
{
  if(str.match(/<h1>(<a.*?>)?(.+?)(<\/a>)?<\/h1>/))
  {
    return RegExp.$2;
  }
  else
  {
    return null;
  }
}

function getXarchiwumPrice(str)
{
  if(str.match(/<div>(<span>)?(cena aukcji|Kup teraz):(<\/span>)? <(b|strong)> ?(.*?) ?<\/(b|strong)><\/div>/))
  {
    return RegExp.$5;
  }
  else
  {
    return null;
  }
}


/*
 * Retrieves URL to thumbnail from the auction (if any)
 */
function getThumbnailURL(str)
{
  if(str.match(/<a href="#gallery"><img.*?src="(.*?)".*?><\/a>/))
  {
    return RegExp.$1;
  }
  else
  {
    return null;
  }
}

/////////////////////////////////////////////////////////////////
//// IE/FF compatibility
/////////////////////////////////////////////////////////////////

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;
}

// FF uses addEventListener method while IE uses attachEvent method
// to register event handler
// Call this mehod with the element that generates the event,
// the event name (without 'on' prefix) and the handler routine
// The handler routine should accept an event source
// See getEvent method to see how to get the event source in FF and IE
function registerEventHandler(element, eventName, handler)
{
  if (element.addEventListener)
  {
    element.addEventListener(eventName, handler, false);
  }
  else if (document.attachEvent)
  {
    element.attachEvent("on" + eventName, handler);
  }
} 

// FF passes event to the handler function, while IE does not
// Call this function fit the ergument of the handler function:
// If e is not null (FF) then it will be returned. Otherwise (IE)
// the event will be retrieved from the window object and this value
// will be returned instead.
function getEvent(source)
{
  if (source)
  {
    return source;
  }
  else
  {
    return window.event;
  }
}

// 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 of 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;
}

// FF uses textContent property while IE uses innerText property
// to return the inner text of an element
function getInnerText(element)
{
  var result = null;
  
  if (element)
  {
    // For IE
    result = element.innerText;
  
    if(result == null)
    {
      // For FireFox
      result = element.textContent;
    }
  }
  
  return result;
}

// In FF firstChild returns also #text nodes that represents
// the whitespaces in the HTML source. IE skips these nodes
// For IE and FF use this method instead of firstChild property
// to return the first non-#text element.
// NOTE: this method skips ALL #text nodes (not only whitespaces)
function getFirstChild(element)
{
  var child = element.firstChild;
  while(child && (child.nodeType != 1))
  {
    child = child.nextSibling;
  }
  
  return child;
}

// In FF lastChild returns also #text nodes that represents
// the whitespaces in the HTML source. IE skips these nodes
// For IE and FF use this method instead of lastChild property
// to return the first non-#text element.
// NOTE: this method skips ALL #text nodes (not only whitespaces)
function getLastChild(element)
{
  var child = element.lastChild;
  while(child && (child.nodeType != 1))
  {
    child = child.previousSibling;




  }
  
  return child;
}

// 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;
}

/////////////////////////////////////////////////////////////////
// Event handlers section
/////////////////////////////////////////////////////////////////
function handleCheckLinksButton()
{
  enableButton(CHECK_LINKS_BTN, false);
  checkLinks();
}

function handleColoringCheckbox()
{
  GM_setValue(AT_COLORING, getCheckbox(COLORING_CHBX));
  filterComments();
}

function handleThumbnailsCheckbox()
{
  var thumbnails = getCheckbox(THUMBNAILS_CHBX);
  GM_setValue(AT_THUMBNAILS, thumbnails);
  displayThumbnails(thumbnails);
}

function handleAutocheckCheckbox()
{
  var autocheck = getCheckbox(AUTOCHECK_CHBX);
  GM_setValue(AT_AUTOCHECK, autocheck);
  showButton(CHECK_LINKS_BTN, !autocheck);
  autocheckLinks();
}

function handleShowEmptyArchCheckbox()
{
  GM_setValue(AT_SHOW_EMPTY_ARCH, getCheckbox(SHOW_EMPTY_ARCH_CHBX));
}

function  handleArchCheckbox(e)
{
  var event = getEvent(e);
  var source = event.target || event.srcElement;
  var name = source.id.replace(ARCH_CHBX, "");
  GM_setValue(AT_ARCH_PREFIX + name, getCheckbox(name + ARCH_CHBX));
}


/////////////////////////////////////////////////////////////////
// Links checking related functions
/////////////////////////////////////////////////////////////////

function autocheckLinks()
{
  if(isEnabledButton(CHECK_LINKS_BTN) && getCheckbox(AUTOCHECK_CHBX))
  {
    handleCheckLinksButton();
  }
}

function checkLinks()
{
  if (COMMENTS)
  {
    var linkCheckers = new Array();
    linkCheckers.auctionNumber = "";
    for(var i = 0; i < COMMENTS.length; i++)
    {
      linkCheckers.push(new LinkChecker(i));
      linkCheckers.auctionNumber = linkCheckers.auctionNumber + ((i == 0) ? "" : ",") + linkCheckers[i].auctionNumber;
    }
    for(var i = 0; i < ARCHIVERS.length; i++)
    {
      if((ARCHIVERS[i].multi > ARCH_MULTI_NO) && (ARCHIVERS[i].enabled == true))
      {
        ARCHIVERS[i].check(linkCheckers);
      }
    }  
  }
}

////////////////////////////////////////////////////////////////////////
// Archiver class
////////////////////////////////////////////////////////////////////////

function Archiver(name, multi, checkUrl, archiveUrl, processMethod, errorMethod)
{
  // Name of the archiver to be displayed
  this.name = name;
  // Can this archiver handle queris with multiple auctions?
  this.multi = multi;
  // Url of the archiver used to check auction existence
  this.checkUrl = checkUrl;
  // Url of the archiver pointing to the archived auction
  this.archiveUrl = archiveUrl;
  // Method used to analyse archiver response
  this.processMethod = processMethod;
  // Method used to analyse archiver error
  this.errorMethod = errorMethod;
  // Property used to mark whether this archiver is enabled or not
  // Initialized during creation, so changes won;t affect processing
  this.enabled = GM_getValue(AT_ARCH_PREFIX + this.name, true);
}

Archiver.prototype.check = function(linkChecker)
{
  var archiverUrl = this.checkUrl.replace(/%number%/, linkChecker.auctionNumber);
  archiverUrl = archiverUrl.replace(/%params%/, location.search.substring(1));
  var me = this;
  GM_xmlhttpRequest({method:"GET", url:archiverUrl,
                     onload:function(d){me.processMethod(d, linkChecker, me);},
                     onerror:function(d){me.errorMethod(linkChecker, me);}});                  
}

////////////////////////////////////////////////////////////////////////
// LinkChecker class
////////////////////////////////////////////////////////////////////////

function LinkChecker(index)
{
  this.index = index;
  this.row = COMMENTS[this.index];
  if(this.row)
  {
    var link = null;
    link = select(this.row, 0, 3, 0);
    if(link)
    {
      this.link = link;
      this.linkLI = link.parentNode;
      this.titleDIV = document.createElement("DIV");
      //// workaround for strange positioning of titles table in Firefox ////
      this.titleDIV.style.fontSize = "0px";
      this.titleDIV.innerHTML = "&nbsp;";
      //// workaround for strange positioning of titles table in Firefox ////
      comment = select(this.row, 1);
      comment.parentNode.insertBefore(this.titleDIV, comment);
      this.dateLI = select(this.row, 0, 2);
      this.auctionNumber = getInnerText(this.link);
      this.checkLink();
    }
  }
}

LinkChecker.prototype.mark = function(element)
{
  if (element)
  {
    if(element.markCount)
    {
      element.markCount += 1;
    }
    else
    {
      element.markCount = 1;
      element.style.backgroundImage = "url('"+BG_BYSTR+"')";
    }
  }
}

LinkChecker.prototype.unmark = function(element)
{
  if (element)
  {
    if(element.markCount && element.markCount > 1)
    {
      element.markCount -= 1;
    }
    else
    {
      element.markCount = 0;
      element.style.backgroundImage = "";
    }
  }
}

LinkChecker.prototype.checkLink = function()
{
  var titleTable = document.createElement('table');
  titleTable.style.color="#606060";
  titleTable.cellPadding = "0";
  titleTable.cellSpacing = "0";
  titleTable.border = "0";
  var titleTableBody = document.createElement('tbody');
  titleTable.appendChild(titleTableBody);
  this.titleDIV.appendChild(titleTable);
  this.titleDIV.style.textAlign='left';
  for(var i = 0; i < ARCHIVERS.length; i++)
  {
    if(ARCHIVERS[i].enabled == true)
    {
      var titleTableRow = document.createElement('tr');
      var titleTableCell1 = document.createElement('td');
      titleTableCell1.style.fontSize = '8pt';
      titleTableCell1.innerHTML = "<b>" + ARCHIVERS[i].name + "</b>";
      titleTableRow.appendChild(titleTableCell1);
      var titleTableCell2 = document.createElement('td');
      titleTableCell2.style.fontSize = '8pt';
      titleTableCell2.innerHTML = "&nbsp;:&nbsp;";
      titleTableRow.appendChild(titleTableCell2);
      var titleTableCell3 = document.createElement('td');
      titleTableCell3.style.fontSize = '8pt';
      titleTableCell3.id = ARCHIVERS[i].name + "_title_" + this.index;
      titleTableCell3.innerHTML = ARCH_AUCTION_CHECK_IN_PROGRESS;
      titleTableRow.appendChild(titleTableCell3);
      titleTableBody.appendChild(titleTableRow);

      this.mark(this.linkLI); 
      if(ARCHIVERS[i].multi == ARCH_MULTI_NO) 
      {
        ARCHIVERS[i].check(this);
      }  
    }  
  }
}

/////////////////////////////////////////////////////////////////
// Coment filtering/coloring related functions
/////////////////////////////////////////////////////////////////
function changeCommentRowBackgroundColor(element, color, doColoring)
{
  var newColor = doColoring ? color : "";
  element.style.backgroundColor = newColor;
}

function filterComments()
{
  if(COMMENTS)
  {
    var doColoring = GM_getValue(AT_COLORING, false);
    var id = false;
    var color = false;
    for(var i = 0; i < COMMENTS.length; i++)
    {
      id = COMMENTS[i].getAttribute("id");

      // Check seller/buyer
      if (id.match(SELLER_STRING))
      {
        color = SELLER_COLORS[i % 2];
      }  
      else if (id.match(BUYER_STRING))
      {
        color = BUYER_COLORS[i % 2];
      }

      changeCommentRowBackgroundColor(COMMENTS[i], color, doColoring)
    }
  }
}

function displayThumbnails(display)
{
  var displayValue = display ? "" : "none";
  var element = null;
  var commentCount = 0;
  while ((element = document.getElementById("_thumbnail_" + commentCount)) != null)
  {
    element.style.display = displayValue;
    commentCount++;
  }
  var headerCount = 0;
  while ((element = document.getElementById("_thumbnail_header_" + headerCount)) != null)
  {
    element.style.display = displayValue;
    headerCount++;
  }
}

/////////////////////////////////////////////////////////////////
// Menu related functions
/////////////////////////////////////////////////////////////////
function showButton(id, show)
{
  var displayValue = show ? "block" : "none";
  var element = document.getElementById(id);
  if(element && element.style.display != displayValue)
  {
    element.style.display = displayValue;
  }
}

function enableButton(id, enable)
{
  var element = document.getElementById(id);
  if(element && element.disabled != !enable)
  {
    element.disabled = !enable;
  }
}

function isEnabledButton(id)
{
  var element = document.getElementById(id);
  if(element)
  {
    return !element.disabled;
  }
  else
  {
    return false;
  }
}

function setCheckbox(id, checked)
{
  var element = document.getElementById(id);
  if(element && element.checked != checked)
  {
    element.checked = checked;
  }
}

function getCheckbox(id)
{
  var element = document.getElementById(id);
  if(element)
  {
    return element.checked;
  }
  else
  {
    return false;
  }
}

function getButtonHtml(title, help, id, visible)
{
  return "<td><input style=\"font-size:8pt\" title=\"" + help + "\" type=\"button\" id=\"" + id + "\" value=\"" + title +"\"/></td>";
}

function getCheckboxHtml(title, help, id)
{
  return "<td><input style=\"font-size:8pt\" title=\"" + help + "\" type=\"checkbox\" id=\"" + id + "\"/><label style=\"font-size:8pt\" title=\"" + help + "\" for=\"" + id + "\">" + title + "</label></td>";
}

function addMenu()
{
  var menuPosition = document.getElementById("flpw");
  if(menuPosition == null)
  {
    menuPosition = getNextSibling(document.getElementById("myAllegroSubMenu"), 1); // workaround when flpw DIV is missing
  }
  if(menuPosition)
  {
    var menuDiv = document.createElement("div");
    menuDiv.style.backgroundColor="#E7DAD1";
    menuDiv.style.borderTopColor="#002449";
    menuDiv.style.borderTopWidth="4";
    menuDiv.style.borderTopStyle = "solid";
    menuPosition.parentNode.insertBefore(menuDiv, menuPosition);

    var filterBuyerSellerMenu = document.createElement("div");
    menuDiv.appendChild(filterBuyerSellerMenu);
    var filterBuyerSellerMenuInnerHTML = "<table cellspacing=2 cellpadding=0 border=0>" +
                                         getCheckboxHtml("Kolorowanie", "Wlacza/wylacza kolorowanie kupujacych/sprzedajacych", COLORING_CHBX) +
                                         "<td>&nbsp;</td>";
    var archivesListString = ARCHIVERS[0].name;
    for(var i = 1; i < ARCHIVERS.length; i++)
    {
      archivesListString = archivesListString.concat(", " + ARCHIVERS[i].name);
    }
    filterBuyerSellerMenuInnerHTML = filterBuyerSellerMenuInnerHTML +
                                     getCheckboxHtml("Miniaturki", "Wlacza/wylacza wyswietlanie minaturek zdjec przedmiotow", THUMBNAILS_CHBX) +
                                     "<td>&nbsp;</td>" +
                                     getCheckboxHtml("Autosprawdzanie", "Wlacza/wylacza automatyczne sprawdzanie aukcji. Sprawdzane sa archiwa: " + archivesListString + ". Gdy wlaczona jest ta opcja, przycisk 'Sprawdz aukcje' jest niewidoczny.", AUTOCHECK_CHBX) +
                                     "<td>&nbsp;</td>" +
                                     getButtonHtml("Sprawdz aukcje", "Sprawdza aukcje wyswietlane na tej stronie. Sprawdzane sa archiwa: " + archivesListString + ". Jesli przycisk ten jest wyszarzony, oznacza to ze aukcje na tej stronie zostaly juz sprawdzone lub sprawdzanie jest w toku. Przycisk ten jest niewidzoczny gdy wlaczona jest opcja 'Autosprawdzanie'.", CHECK_LINKS_BTN);

    var archiverMenu = document.createElement("div");
    menuDiv.appendChild(archiverMenu);
    var archiverMenuInnerHTML = "<table cellspacing='2' cellpadding='0' border='0'><tr>" +
                                "<td style=\"font-size:8pt\">Sprawdz archiwa:</td>" +
                                "<td>&nbsp;</td>";
    for(var i = 0; i < ARCHIVERS.length; i++)
    {
      archiverMenuInnerHTML = archiverMenuInnerHTML +
                              getCheckboxHtml(ARCHIVERS[i].name, "Wlacza/wylacza sprawdzanie archiwum " + ARCHIVERS[i].name + " (UWAGA! zmiany tej opcji beda widoczne dopiero po nastepnym odswiezeniu strony!)", ARCHIVERS[i].name + ARCH_CHBX) +
                              "<td>&nbsp;</td>";
    }                           
    archiverMenuInnerHTML = archiverMenuInnerHTML +
                            "<td>&nbsp;</td>" +
                            getCheckboxHtml("Pokazuj niezarchiwizowane", "Wlacza/wylacza wyswietlanie archiwow nie posiadajacych zarchiwizowanej aukcji (UWAGA! zmiany tej opcji beda widoczne dopiero po nastepnym odswiezeniu strony!)", SHOW_EMPTY_ARCH_CHBX) +
                            "</tr></table>";
    archiverMenu.innerHTML = archiverMenuInnerHTML;
    filterBuyerSellerMenuInnerHTML = filterBuyerSellerMenuInnerHTML +
                                     "</tr></table>";
    filterBuyerSellerMenu.innerHTML = filterBuyerSellerMenuInnerHTML;
    var coloring = GM_getValue(AT_COLORING, false);
    setCheckbox(COLORING_CHBX, coloring);
    registerEventHandler(document.getElementById(COLORING_CHBX), "click", handleColoringCheckbox);
    setCheckbox(THUMBNAILS_CHBX, GM_getValue(AT_THUMBNAILS, true));
    //// temporarily disable thumbnails checkbox ////
    setCheckbox(THUMBNAILS_CHBX, GM_getValue(AT_THUMBNAILS, false));
    enableButton(THUMBNAILS_CHBX, false);
    //// temporarily disable thumbnails checkbox ////
    var autocheck = GM_getValue(AT_AUTOCHECK, false);
    setCheckbox(AUTOCHECK_CHBX, autocheck);
    showButton(CHECK_LINKS_BTN, !autocheck);
    registerEventHandler(document.getElementById(THUMBNAILS_CHBX), "click", handleThumbnailsCheckbox);
    registerEventHandler(document.getElementById(AUTOCHECK_CHBX), "click", handleAutocheckCheckbox);
    registerEventHandler(document.getElementById(CHECK_LINKS_BTN), "click", handleCheckLinksButton);
    var showEmpty = GM_getValue(AT_SHOW_EMPTY_ARCH, true);
    setCheckbox(SHOW_EMPTY_ARCH_CHBX, showEmpty);
    registerEventHandler(document.getElementById(SHOW_EMPTY_ARCH_CHBX), "click", handleShowEmptyArchCheckbox);
    for(var i = 0; i < ARCHIVERS.length; i++)
    {
      setCheckbox(ARCHIVERS[i].name + ARCH_CHBX, ARCHIVERS[i].enabled);
      registerEventHandler(document.getElementById(ARCHIVERS[i].name + ARCH_CHBX), "click", function(e){handleArchCheckbox(e);});
    }
  }
}

function insertThumbnailLI(item, count, header)
{
  // Insert thumbnail cell
  if(header == false)
  {
  }
  else  
  {
  }
}

/////////////////////////////////////////////////////////////////
function findComments()
{
  var commentCount = 0;
  var headerCount = 0;
  var list;
  var lists = document.getElementsByTagName("ul");
  // First find lists with comments
  for (var i = 0; i < lists.length; ++i)
  {
    list = lists[i];
    if (list)
    {
      classAttr = list.className;
      if(classAttr && classAttr.match("feedbacks_main"))
      {
        // Now mark seller and buyer comments, modify headers and add comments to the list
        var listItems = getChildNodes(list);
        if(listItems)
        {
          var item;
          for(var j = 0; j < listItems.length; j++)
          {
            item = listItems[j];
            if(item)
            {
              if(item.className.match("list-white") || item.className.match("list-color"))
              {
                var id = "";
                var details = getFirstChild(item);
                if(details)
                {
                  var string = getInnerText(details);
                  // TODO correct matching strings
                  if(string.match(SELLER_STRING))
                  {
                    id = id.concat(SELLER_STRING);
                  }  
                  else if(string.match(BUYER_STRING))
                  {
                    id = id.concat(BUYER_STRING);
                  }
                }
                
                if (id != "")
                {
                  item.setAttribute("id", id);
                  COMMENTS.push(item);
                  insertThumbnailLI(item, commentCount, false);
                  commentCount++;
                }
              }
              else if(item.className.match("feedback_header_cont"))
              {
                insertThumbnailLI(item, headerCount, true);
                headerCount++;
              }
            }
          }
        }
      }
    }
  }
}

function allegrotoolsComments()
{
  // Initialize at the start, so changes won't affect the processing
  showEmptyArch = GM_getValue(AT_SHOW_EMPTY_ARCH, true);

  findComments();
  if (COMMENTS.length > 0)
  {
    filterComments();
    displayThumbnails(GM_getValue(AT_THUMBNAILS, true));
    addMenu();
    autocheckLinks();
  }
}

/////////////////////////////////////////////////////////////////
// Start Allegro Tools Comments script
/////////////////////////////////////////////////////////////////

allegrotoolsComments()

})();