pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by ShaggyShaggs on Thu 3rd Dec 17:40
download | new post

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is zombienames.
  15.  *
  16.  * The Initial Developer of the Original Code is Max Grivas.
  17.  *
  18.  * Portions created by the Initial Developer are Copyright (C) 2007
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. /*
  38.  *  Global Data for zombie names:
  39.  *           
  40.  *
  41.  */
  42.  
  43. var udw_Zombies_Known = null;
  44. var udw_ZN_WriteCount = 0;
  45. var FetchReqs = null;
  46.  
  47. /*
  48.  *  Function:   udw_WorkZombieProfiles(document)
  49.  *     
  50.  *      replace "A zombie" with "A zombie (name of zombie)"
  51.  *
  52.  */
  53.  function udw_WorkZombieProfiles(d)  {
  54.         var tfNdx = d.lastModified;
  55.         var local_ToFetch = null;
  56.         var known_Touch = null;
  57.  
  58.         var debug_out = '';
  59.  
  60. //if (isDebugEnabled) alert('zn tfNdx: '+tfNdx);
  61.  
  62.         var gp = getElementsByClass('gp',d,'td')[0];
  63.         var links = gp.getElementsByTagName('a');
  64.  
  65. //if (isDebugEnabled) alert('zn Found '+links.length+' links');
  66.  
  67.         for (var i = 0; i < links.length; i++) {
  68.                 var ptest = links[i].href.match(/profile.cgi\?id=(\d+)/);
  69.                 if (ptest) {
  70.                         var pid = parseInt(ptest[1]);
  71.  
  72. //                  if (links[i].innerHTML.match(/a zombie|one of the zombies/i)) {
  73.                         if (links[i].text.match(/a zombie|one of the zombies|one of the bodies/i)) {
  74.  
  75.                         debug_out+= 'Found zombie '+pid;
  76.  
  77.                         var known = false;
  78.  
  79.                         if (udw_Zombies_Known) {
  80.                                 for (var z = 0; z<udw_Zombies_Known.length; z++) {
  81.                                         if (udw_Zombies_Known[z]['profile']==pid) {
  82.  
  83.                                                 debug_out+= " : known\n";
  84.  
  85.                                                 known = true;
  86.                                                 // Do Append Name
  87.                                                 udw_AppendNameToLink(links[i],udw_Zombies_Known[z]['name']);
  88.                                                 i++;
  89.                                        
  90.                                                 // update cache delay
  91.                                                 var dStamp = new Date();
  92.                                                 udw_Zombies_Known[z]['seen'] = dStamp.getTime();
  93.                                                 known_Touch = true;
  94.                                                 }
  95.                                         }
  96.                                 } // if udw_Zombies_Known
  97.  
  98.                                 if (!known) {
  99.                                         if (!local_ToFetch) local_ToFetch = new Array();
  100.  
  101.                                         var tf = false;
  102.                                         for (var zz = 0; zz<local_ToFetch.length; zz++) {
  103.                                                 if (local_ToFetch[zz]==pid) {
  104.                                                         tf = true;
  105.                                                         debug_out+= " : queued\n";
  106.                                                         }
  107.                                                 }
  108.  
  109.                                         if (!tf) {
  110.  
  111. //if (isDebugEnabled) alert('They will be looked up.');
  112.  
  113.                                                 local_ToFetch[local_ToFetch.length]=pid;
  114.                                                 debug_out+= " : new\n";
  115.                                                 }
  116.  
  117.                                         }  // !known
  118.                                 }  // match(/A zombie/i)
  119.                         } // ptest
  120.                 }  // i<links.length
  121.  
  122.         // Launch Async Requests
  123.         if (local_ToFetch) {
  124.                 FetchReqs = new Array();
  125.                
  126. //if (isDebugEnabled) alert('zn '+local_ToFetch.length+' zombies to lookup.');
  127.  
  128.                 for (var r = 0; r<local_ToFetch.length; r++) {
  129.                         FetchReqs[r] = new XMLHttpRequest();
  130.                         // Can I add my own properties to the request object
  131.                         //           Seems odd ... wonder when and if it gets discarded ...
  132.  
  133.                                 // sport a reference to the document it should appear in
  134.                         FetchReqs[r].znDoc = d;
  135.  
  136.                         FetchReqs[r].open('GET', 'http://urbandead.com/profile.cgi?id='+local_ToFetch[r], true);
  137.                         FetchReqs[r].onload=udw_ZN_onLoad;
  138.  
  139.                         // Don't care about errors for now
  140.                         //tfReq.onerror=udw_ZN_onError;
  141.                         // Let it not show up ...
  142.  
  143.                         FetchReqs[r].send(null);
  144.                         }
  145.                 }  // local_ToFetch
  146. //      else {
  147. //            if (known_Touch) {
  148. //                  // Serialize the known cache >>> or onunload <<<
  149. //                  }
  150. //            }
  151.  
  152. //      if (isDebugEnabled && debug_out.length) alert(debug_out);
  153.         } // udw_WorkZombieProfiles
  154.  
  155. /*
  156.  *  Function:   udw_AppendNameToLink(doc,link,name)
  157.  *     
  158.  *      replace <a>A zombie</a> with <a>A zombie</a>&nbsp;(<a>name</a>)
  159.  *
  160.  */
  161.  function udw_AppendNameToLink(ele,name)  {
  162.         if ( !ele ) return 0;
  163.  
  164.         var NodeText = ' ( <a href="'+ele.href+'"';
  165.         if (ele.className.length) NodeText+= ' class="'+ele.className+'"';
  166.         else {
  167.                 var isspan = ele.getElementsByTagName('span');
  168.                 if (isspan && isspan.length) NodeText+= ' class="'+isspan[0].className+'"';
  169.                 }
  170.  
  171.         // if isColorNamesEnabled
  172.         //            udw_ColorData is loaded
  173.         //                  before udw_WorkZombieProfiles
  174.  
  175.         //      udw_ColorData = loadAndParseList();
  176.         if (isColorNamesEnabled ) {
  177.                 if (udw_ColorData) {
  178.                         var newname = name.replace(/&nbsp;/g, ' ');
  179.                         var gnum = udw_ColorData.userHT[newname];
  180.                         if (gnum!=undefined) {
  181.                                 NodeText += ' style="color:'+udw_ColorData.colorList[gnum]+'; font-weight:bold;"';
  182.                                 NodeText += ' title="'+udw_ColorData.nameCommentHT[newname]+'"';
  183.                                 }
  184.                         }  //  if udw_ColorData
  185.                 }  //  if isColorNamesEnabled
  186.  
  187.  
  188.         NodeText+= '>'+name+'</a> )';
  189.  
  190.         var tack = ele.ownerDocument.createElement('SPAN');
  191.  
  192.         tack.innerHTML = NodeText;
  193.         ele.parentNode.insertBefore(tack, ele.nextSibling);
  194.  
  195.         }  //  udw_AppendNameToLink
  196.  
  197. /*
  198.  *  Function:   udw_ZN_onLoad(link,name,profile)
  199.  *     
  200.  *      handle async document
  201.  *
  202.  */
  203.  function udw_ZN_onLoad(e)  {
  204.         var szPage = e.target.responseText;
  205.  
  206.         var scraps = null;
  207.         var name = null;
  208.         var pid = null;
  209.  
  210. //if (isDebugEnabled) alert('zn udw_ZN_onLoad fired');
  211.  
  212. //      get name from responseText
  213.         try { scraps = szPage.match(/<span class="ptt">([\w ]+)<\/span>/i); }
  214.         catch (e) { if (isDebugEnabled) alert("udWidget Error while reading name: "+e); }
  215.         if (scraps) name = udw_Trim(scraps[1]);
  216.         else return;
  217.  
  218. //if (isDebugEnabled) alert('zn name: '+name);
  219.  
  220. //      get profile from responseText
  221.         scraps = null;
  222.         try { scraps = szPage.match(/href="contacts\.cgi\?add=(\d+)"/i); }
  223.         catch (e) { if (isDebugEnabled) alert("udWidget Error while reading profile id: "+e); }
  224.         if (scraps) pid = parseInt(scraps[1]);
  225.         else return;
  226.  
  227. //if (isDebugEnabled) alert('zn pid: '+pid);
  228.  
  229. //      add name to zombies_known
  230.         if (!udw_Zombies_Known) udw_Zombies_Known = new Array();
  231.         var z = udw_Zombies_Known.length;
  232.         udw_Zombies_Known[z] = new Array();
  233.         udw_Zombies_Known[z]['name'] = name;
  234.         udw_Zombies_Known[z]['profile'] = pid;
  235.  
  236.         var dStamp = new Date();
  237.         udw_Zombies_Known[z]['seen'] = dStamp.getTime();
  238.  
  239.         // Serialize the known cache >>> or onunload <<<
  240.  
  241.         // Get the document reference from the Request object
  242.         //      which was overloaded with the new property .znDoc
  243.         var links = null;
  244.         try { links = e.target.znDoc.getElementsByTagName('a'); }
  245.         catch (e) { if (isDebugEnabled) alert("udWidget Zombie Names Error while looking for the zombie to update: "+e); }
  246.  
  247.         //      the doc reference e.target.znDoc
  248.         //            could be gone by now ?
  249.         if (!links) return;
  250.  
  251. //if (isDebugEnabled) alert('zn links to match: '+links.length);
  252.  
  253.         for (var i = 0; i < links.length; i++) {
  254.                 var lid = null;
  255.                 var ptest = links[i].href.match(/profile.cgi\?id=(\d+)/);
  256.                 if (ptest) lid = parseInt(ptest[1]);
  257.  
  258.                 if (lid)
  259.                         if (links[i].text.match(/a zombie|one of the zombies|one of the bodies/i))  //  if (links[i].innerHTML.match(/A zombie/i))
  260.                                 if (lid == pid) {
  261.                                         udw_AppendNameToLink(links[i],name);
  262.                                         i++;
  263.                                 }
  264.                 }
  265.  
  266.         }  //  udw_ZN_onLoad
  267.  
  268. /*
  269.  *  Function:   udw_ZN_onError(e)
  270.  *     
  271.  *      handle async error
  272.  *
  273.  */
  274.  function udw_ZN_onError(e)  {
  275.         }  //  udw_ZN_onError

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings