You Might Like These
Other Free Resources
Back to PCDesigns.net Some of my Favorite Places

So, if you're visiting my site, I can't help but think that we probably have some common interests so I thought I'd share some of my links. This is a quick aggregator that I threw together to keep track of some of my favorite RSS feeds. Take a look.
Computer Humor
General Technology News and Topics
Programming
General Computer Topics

Actually, you can just click here and get the whole directory here: http://uptodate.pcdesigns.net

Please Fill Out a Survey

I've developed a short survey to evaluate a new measure of job satisfaction. I need data. Please take a few seconds to fill it out.

Thanks,
Patrick

Free Scripts!

These are some scripts that I have created (or modified) in the process of developing websites for clients. I've posted them here to help other developers create the results they desire. Take what you want, just remember that all commented lines must remain in the scripts (give credit where credit is due). To install bookmarklets, right click on the bookmark title and indicate that you would like to save the link to your bookmarks list.

WEP Key Converter

Some wireless hardware manufacturers do not accept ascii wep keys. This makes it fairly difficult to get all of your wireless hardware working. This utility converts an ascii string to a hexidecimal string. Remember, WEP keys are 5 or 13 ascii charachters (10 or 26 hex pairs).



Ascii to Hexidecimal
Hexidecimal to Ascii

My Regular Expressions

These are some regular expressions that I have designed for form validation and/or searching.

Expressions

      
Social Security Number: /\d{3}[\.\-]?\d{2}[\.\-]?\d{4}/
US Phone Number: /1?[\.\-\+\( ]?[2-9]\d{2}[\.\)\- ]*[2-9]\d{2}[\.\-]?\d{4}/
Email Address: /\w[\w\.\-]*\w@\w[\w\-]*\w((:\d+)|\.\w[\w\-]*\w)+(\/\w[\w\-]*\w)*/i
Date: /(0?[1-9]|1[0-2])[\/\\\-\.](0?[1-9]|[12][\d]|3[01])[\/\\\-\.](19|20)?[\d]{2}/
Money: /\$[\d]*(,[\d]{3})*(\.[\d]{2})?/
URL: /([a-zA-Z]+:\/\/)?\w[\w\-]*\w(\.\w[\w\-]*\w)+(:\d+)?([~\/\.]+\w[\w\-]*\w)*\/?(\?[^ ]*)?/
      
     
Zoom In Images Bookmarklet Zoom Out Images Bookmarklet

This bookmarklet doubles/halves the size of each image on a page.

Script:

      
    (
        function(){

// this is the image zoom function.
// it is the same for both zoom and unzoom.
            function zoomImage(image, amt){

// set initialHight and initialWidth properties.
// i suppose this could possibly be useful
// but it's not really used here.
                if(image.initialHeight == null){
                    image.initialHeight = image.height;
                    image.initialWidth = image.width;
                    image.scalingFactor = 1;
                }

// set the image scaling factor and scale the images
// based on the amt attribute.
                image.scalingFactor *= amt;
                var newWidth = image.scalingFactor * image.initialWidth,
                    newHeight = image.scalingFactor * image.initialHeight;
                image.width = newWidth;
                image.height = newHeight;

// set styles too because styles override height
// and width attributes.
                image.style.width = newWidth;
                image.style.height = newHeight;
            }

            var i, L = document.images.length;

// the zoom out script uses .5 instead of 2 as
// the scaling factor
            for(i = 0; i < L; ++i) zoomImage(document.images[i], 2);
        }
    )();
      
     
Zoom In Hover Images Bookmarklet Zoom Out Hover Images Bookmarklet

This bookmarklet is the same as above except that the images only change sizes when you mouse over them. It works pretty well but can be a little annoying sometimes.

Script:

      
  (
    function()
    {
    // the main function in the whole mess
      function zoomImage (image, amt)
      {

    // if the image hasn't been initialized yet,
    // do so
        if (image.initialHeight == null)
        {
          image.initialHeight = image.height;
          image.initialWidth = image.width;
          image.scalingFactor = 1;
        }

    // multiply the scaling factor by the
    // new multiplier
        image.scalingFactor *= amt;

    // assign the zoom function to the onmouseover
    // event
        image.onmouseover = new Function
        ('
          this.width = this.scalingFactor * this.initialWidth;
          this.height = this.scalingFactor * this.initialHeight;
          this.style.width = this.scalingFactor * this.initialWidth;
          this.style.height = this.scalingFactor * this.initialHeight;
        ');

    // unzoom onmouseout
        image.onmouseout = new Function
        ('
          this.width = this.initialWidth;
          this.height = this.initialHeight;
          this.style.width = this.initialWidth;
          this.style.height = this.initialHeight;
        ')
      }

    // apply settings to each image on the page
      var i, L = document.images.length;
      for (i = 0; i < L; ++i)
        zoomImage (document.images[i], 2);

    // it's amazingly easy, huh?
    }
  )();
      
     
Horde Message Row Highlighter

I use horde webmail. I love it and horde is awesome! However, I don't like havin' to click the checkboxes themselves so if you run this bookmarklet, you'll be able to click anywhere in the row and it'll check the checkbox for you. Just a handy little tool. I'm not sure why horde hasn't made this yet, but I'm sure they will eventually.

Script:

      
//  get the messages form from the main frame
var myMessages = top.frames[1].document.forms['messages'];

//  loop through all of the elements in that form (i.e., mostly checkboxes)
for (var i = 0; i < myMessages.elements.length; i++)
{
  var myBox = myMessages.elements[i];

//  if the checkbox is one of the message boxes then do stuff
  if (myBox.name == 'indices[]')
  {

//  build the event handler for the table row
    myBox.parentNode.parentNode.onclick = new Function(

//  get the checkbox from the checkbox number
      "var myCheckbox = 'check" + myBox.value + "';"
      + "myCheckbox = top.frames[1].document.getElementById(myCheckbox);"

//  check the checkbox
      + "myCheckbox.checked = !myCheckbox.checked;"

//  do what should have happened had you clicked the checkbox.
//  horde could have put this code in onchange instead so i
//  wouldn't have to call the onclick event, but whatever
      + "myCheckbox.onclick();"
    );
  }
}
      
     
Regex Search

Use this bookmarklet to run a regex search on the current page and highlight all of the matches that occur.

Script:

      
// check to see if the variable searches has been defined.
// if not, create it.  this variable is to cycle through 
// highlight colors.
if (typeof(searches) == 'undefined')
{
  var searches = 0;
};

(
  function()
  {

// just some variables
    var count = 0, text, regexp;

// prompt for the regex to search for
    text = prompt('Search regexp:', '');

// if no text entered, exit bookmarklet
    if (text == null || text.length == 0)
    {
      return;
    }

// try to create the regex object.  if it fails
// just exit the bookmarklet and explain why.
    try
    {
      regexp = new RegExp(text, 'i');
    }

    catch (er)
    {
      alert('Unable to create regular expression using text \'' 
        + text + '\'.\n\n' + er);
      return;
    }

// this is the function that does the searching.
    function searchWithinNode(node, re)
    {

// more variables
      var pos, skip, spannode, middlebit, endbit, middleclone;
      skip = 0;

// be sure the target node is a text node
      if (node.nodeType == 3)
      {

// find the position of the first match
        pos = node.data.search(re);

// if there's a match . . . 
        if (pos >= 0)
        {

// create the acronym node.  it's called spannode
// 'cause it wasn't always an acronym.  i thought of
// the acronym thing and decided to leave spannode as
// the variable name 'cause . . . well, 'cause it's
// my prerogative.
          spannode = document.createElement('ACRONYM');
          spannode.title = 'Search ' + (searches + 1) 
            + ': ' + re.toString();
          spannode.style.backgroundColor = backColor;
          spannode.style.borderTop = '1px solid ' + borderColor;
          spannode.style.borderBottom = '1px solid ' + borderColor;
          spannode.style.fontWeight = 'bold';
          spannode.style.color = borderColor;

// get the last half of the node and cut the match
// out.  then, clone the middle part and replace it with
// the acronym
          middlebit = node.splitText(pos);
          endbit = middlebit.splitText(RegExp.lastMatch.length);
          middleclone = middlebit.cloneNode(true);
          spannode.appendChild(middleclone);
          middlebit.parentNode.replaceChild(spannode, middlebit);
          ++count;
          skip=1;
        }
      } else if

// if the node is not a text node and is not
// a script or a style tag
      (
        node.nodeType == 1
        && node.childNodes
        && node.tagName.toUpperCase() != 'SCRIPT'
        && node.tagName.toUpperCase != 'STYLE'
      )
      {

// loop through the nodes children searhing
// for the regex
        for (var child = 0; child < node.childNodes.length; ++child)
        {
          child = child + searchWithinNode(node.childNodes[child], re);
        }
      }

      return skip;
    }

// this function converts decimal to binary.
    function toBinary(decimal, padding)
    {
      var myBinStr = '', myStringLength;

// determine how many characters you're gonna need
// for the binary representation of the decimal number
// (i.e., ln(dec)/ln(2) is the number of digits you'll need
// for the binary number.  I need at least 3 characters so
// i'll use the padding parameter to ensure that a minimum of
// 3 bits come out (i.e., 001 vs. 1)
      myStringLength = 
        Math.max
        (
          Math.floor
          (
            Math.log(decimal) / Math.LN2
          ) + 1
          
          , (padding) ? padding : 0
        );

      for (var i = myStringLength - 1; i >= 0; i--)
      {

// this is the binary conversion.  if you don't get it,
// i'd suggest you seek tutorials about base conversions
        if (decimal - Math.pow(2, i) >= 0)
        {
          myBinStr += '1';
          decimal -= Math.pow(2, i);
        } else {
          myBinStr += '0';
        }
      }
      return myBinStr;
    }

// tell yourself what you're up to
    window.status = 'Searching for ' + regexp + '...';

// use the search count to get the colors.  sure, i
// could nix the mod 8 and just get the last three digits
// of the binary string from search count, but i think this
// way is faster, cleaner, and shorter.
    var borderColor = '#' 
      + toBinary(searches %25 8, 3)
      .replace(/0/g, '3')
      .replace(/1/g, '6');
    
    var backColor = borderColor
      .replace(/3/g, 'c')
      .replace(/6/g, 'f');

// for the last half of every 16 searhes, invert the
// colors.  this just adds more variation between
// searches.
    if (searches %25 16 / 8 >= 1)
    {
      var tempColor = borderColor;
      borderColor = backColor;
      backColor = tempColor;
    }

    searchWithinNode(document.body, regexp);
    window.status = 'Found ' + count + ' match'
      + (count == 1 ? '' : 'es')
      + ' for ' + regexp + '.';

// if we made any matches, increment the search count
    if (count > 0)
    {
      searches++;
    }
  }
)();
      
     
Enlarge Fields on a Form Bookmarklet

This script works in Mozilla but I haven't tried to test it in any other browsers.

Script:

      
// define this link as a function
     function(){

// declare variables
        var j=0, x, y, z, areaNode,
          hiddenElements=new Array(),
          textInputs=new Array();

// loop through each form in the document
        while (x = document.forms[j++]){

// loop through each form input element
            x = x.getElementsByTagName('input');
            var k = 0;
            while (y = x[k++]){

// do something depending on the element type
                switch(y.type.toLowerCase()){

// if it's a text element,
// push it into the textInput array
// for later use
                    case 'text':
                        textInputs.push(y);
                        break;

// if it's a textarea,
// make it bigger
                    case 'textarea':
                        y.style.height='400px';
                        y.style.width='400px';
                        break;

// if it is hidden, push it
// into the hiddenElement array
// in case I ever want to add code
// to unhide elements
                    case 'hidden':
                        hiddenElements.push(y);
                        break;
                }
            }
        }

// loop through textInputs and turn
// them into text areas
        while (z = textInputs.pop()){

// but not if it's a search field.
// that'd be kind've annoying I think.
            if(z.name.toLowerCase().indexOf('query')
              && z.name.toLowerCase().indexOf('search')){
                areaNode = document.createElement('textarea');
                areaNode.innerHTML = z.value;
                areaNode.style.height = '200px';
                areaNode.style.width = '400px';
                areaNode.name = z.name;
                z.parentNode.replaceChild(areaNode,z);
            }
        }
    }
      
     
Resize To 800x600 Bookmarklet

This script works in Mozilla and Netscape and IE (I think).

Script:

      
// set size (800x600)
    void(window.outerWidth=800);
    void(window.outerHeight=600);

// center window
    void(
        window.moveTo(
            Math.round(
                (screen.availWidth-window.outerWidth)/2
            ),
            Math.round(
                (screen.availHeight-window.outerHeight)/2
            )
        )
    );
      
     
Toggle Pass/Text Bookmarklet

This script works in Mozilla and Netscape (not IE because IE doesn't allow you to change the type attribute at run-time). If you're filling out a form and someone is looking over your shoulder, click this bookmark and turn every field into password fields. If you have a stored password you cannot remember, click it again and every field becomes a text field. Be careful though because after you cover every text field, if you click it again, you will uncover every password field.

Script:

      
    j = -1;

// loop through document forms
    while (document.forms[++j]){
        k = -1;
        aText = false;
        var cachedElements = new Array();

// loop through form elements
        while (document.forms[j].elements[++k]){
            if (document.forms[j].elements[k].type.toLowerCase() == "text"){
                aText = true; // check for text fields
            }
// when you change the element type,
// it rearranges the elements array so
// you have to put each element in your own
// array.
            cachedElements.push(document.forms[j].elements[k]);
        }

        k = -1;

// loop through form elements again
        while (cachedElements[++k]){

// change only text and password fields
            if(cachedElements[k].type.toLowerCase() == "text"
              || cachedElements[k].type.toLowerCase() == "password"){
                void(cachedElements[k].type = (aText) ? "password" : "text");
            }
        }
    }
      
     
Google Search Bookmarklet

This script works in Mozilla, Netscape, and IE. To use it, highlight some text in a web document, go to bookmarks, and click "Google Search." Your browser will browse to Google and display the search results for the selected words. If no text is selected, it will prompt you for a search term. Alternatively, if you define a keyword to the bookmark, you can enter the keyword in the address bar followed by the search term.

Script:

      
// get selected text with getSelection for NS/Moz or
// with selection with IE
    q = (window.getSelection) ?
        window.getSelection() :
        document.selection.createRange().text;

// if no selected text, check for %s keyword
    if(!q || q == ''){
        q = '%s';
    }

// if no %s keyword or q is still not set, prompt
    if(!q || q == '%25s'){
        q = prompt('Google Search:', '');
    }

// if q contains a value, look it up.
// If not, go to http://www.google.com
    if(q != null && q != ''){
        top.location.href =
          'http://www.google.com/search?q=' + escape(q).replace(/\+/g, '%' + '2B');
    } else {
        top.location.href = 'http://www.google.com';
    }
      
     
Dictionary.com Lookup Bookmarklet

This script works in Mozilla, Netscape, and IE. To use it, highlight a word in a web document, go to bookmarks, and click "Dictionary.com Lookup." Your browser will browse to Dictionary.com and display the definition of the selected word. If no word is selected, it will prompt you for a word to look up. Alternatively, if you define a keyword to the bookmark, you can enter the keyword in the address bar followed by the lookup term.

Script:

      
// get selected text
    q = (window.getSelection) ?
        window.getSelection() :
        document.selection.createRange().text;

// if no selected text, check for %s keyword
    if(!q || q == ''){
        q = '%s';
    }

// if no %s keyword or q is still not set, prompt
    if(!q || q == '%25s'){
        q = prompt('Dictionary Lookup:', '');
    }

// if q contains a value, look it up.
// If not, go to http://www.dictionary.com
    if(q != null && q != ''){
        top.location.href =
          'http://www.dictionary.com/search?q=' + q;
    } else {
        top.location.href = 'http://www.dictionary.com';
    }
      
     
W3C Validator Bookmarklet

This script works in Mozilla, Netscape, and IE. To use it, go to bookmarks, and click "W3C Validator." Your browser will browse to validator.w3.org and display the validation results of the current page. Alternatively, if you define a keyword to the bookmark, you can enter the keyword in the address bar followed by the lookup term.

Script:

      
// check for %s keyword
    uri='%s';

// if %s is not set or uri is empty,
// store current location in uri
    if(!uri || uri == '%25s'){
        uri = top.location.href;
    }

// confirm that uri contains protocol (i.e., 'http://')
    if(uri.toLowerCase().indexOf('http://') < 0){
        uri = 'http://' + uri;
    }

// if uri is not empty, browse to validation page.
// If it is empty, browse to validator homepage
    if(uri != 'http://'){
        top.location.href =
            'http://validator.w3.org/check?uri=' + uri;
    } else {
        top.location.href = 'http://validator.w3.org';
    }
      
     
Show Links Bookmarklet

This script works in Mozilla and Netscape. To use it, go to bookmarks, and click "Show Links." Your browser will open a new window that displays the links in the current page. Alternatively, if you define a keyword to the bookmark, you can enter the keyword in the address bar and it will display the link table.

Script:

      
// prepare HTML entity arrays
    seek = new Array ('&', '<' ,'>');
    entities = new Array ('&amp;', '&lt;', '&gt;');

// create window
    display = window.open (
      '',
      'linksWindow',
      'height = 300, width = 600, resizable = yes,
        scrollbars = yes, status = yes'
    );

// write beginning HTML and Styles to document
    display.document.write ('
        <html>
            <head>
                <base target="_blank;">
                <style type="text/css">
                    body {
                        font-family: georgia;
                        color: #4c5157;
                    }
                    a, a:link, a:visited {
                        text-decoration: none;
                        color: #4c5157;
                    }a:hover, a:active {
                        text-decoration: underline;
                    }
                </style>
            </head>
        <body>
    \n');

// function to convert strings to valid HTML
    function toHTML(target){
        for (
            entityIndex = 0;
            entityIndex < entities.length;
            entityIndex++
        ){
            target = target.replace(
                seek[entityIndex],
                entities[entityIndex]
            );
        }
        return target;
    }

// function to loop through links in the source
// document passed through the source parameter
// and print the links in the opened window
//
// links that have a " in them are not displayed
    function loopLinks(source){
        for (
            linkIndex = 0;
            linkIndex < source.links.length;
            linkIndex++
        ){
            if(
                source.links[linkIndex].href.indexOf('"') < 0
            ){
                display.document.write('
                    <li>
                        <a href="
                '
                + source.links[linkIndex].href
                + '">'
                + toHTML(source.links[linkIndex].href)
                + '
                        </a>
                    </li>
                \n');
            }
        }
    }

// if there are frames, loop through them
// displaying the links in each frame
// otherwise, just show the links in document
    if(window.frames.length){
        for (
            frameIndex = 0;
            frameIndex < window.frames.length;
            frameIndex++
        ){
            display.document.write(
                '<h3>'
                + window.frames[frameIndex].name
                + ' ('
                + window.frames[frameIndex].document.links.length
                + ')</h3><ul>'
            );
            loopLinks(window.frames[frameIndex].document);
            display.document.write('</ul>');
        }
    } else {
        display.document.write('
            <h3>
                Document (
        '
        + document.links.length
        + ' </h3>
            <ul>
        ');
        loopLinks(document);
        display.document.write('</ul>');
    }

// close the body and html elements
    display.document.write('
             </body>
        </html>
    ');

// close the output stream to the document
    display.document.close();
      
     
Auto Scroll Bookmarklet

This script works in Mozilla and Netscape. To use it, go to bookmarks, and click "Auto Scroll." While scrolling, press down to speed up and up to slow down. If you slow it to a stop, it stops the script. You can also stop the script by hitting any key that is not either the up nor the down key.

Script:

      
// let the script handle document.onkeydown
// and document.onkeypress
    document.captureEvents(Event.KEYDOWN|Event.KEYPRESS);

// cancel a keypress event
    document.onkeypress=new Function('return false;');

// declare and set important variables
    var scrollInt;
    scrollSpeed = 1;

// create scrollChange function
//
// this function checks for an event
// if an event was triggered, it determines the key
// and increments or decrements scrollSpeed
// if the key is neither the up key nor the down key
// then cancell scroll and give event handling
// control back to the document
    scrollChange = new Function(
        'e',
        'if(e) {
            if(e.which == 38 && scrollSpeed > 1){
                scrollSpeed--;
            } else if(e.which == 40 && scrollSpeed < 20){
                scrollSpeed++;
            } else if(e.which != 40){
                clearTimeout(scrollInt);
                document.onkeypress =
                    document.onkeydown = null;
                window.status=null;
            }
        } else {
            clearTimeout(scrollInt);
        }'
    );

// handle document.onkeydown event with
// the new handler
    document.onkeydown=scrollChange;

// clear any already running intervals
// and start scroll
//
// the interval function stops scrolling at the
// bottom of the document
    void(scrollChange());
    void(scrollInt = setInterval('
        window.status = \'Scroll Speed: \'
             + scrollSpeed;
        if(window.pageYOffset <
            (document.height - window.innerHeight)
        || document.all){
            window.scrollBy(0, scrollSpeed)
        } else {
            scrollChange()
        }', 200)
    );
      
     
Auto Scroll Bookmark (for IE)

This script works in Mozilla, Netscape, and IE but IE doesn't automatically stop scrolling at the bottom of the page. To use it, go to bookmarks, and click "Auto Scroll." Your browser will prompt you for a number between 1(slow) and 10(fast). Press any key to stop scrolling.

Script:

      
// declare interval ID variable
    var scrollInt;

// declare stop function
    scrollStop = new Function(
        'clearTimeout(scrollInt);'
    );

// assign stop function to onkeydown event
    document.onkeydown = scrollStop;

// prompt for scroll speed
    scrollSpeed = prompt(
        'Enter Scroll Rate Between 1(slow) and 10(fast)'
        , 1
    );

// check to see that scroll speed is reasonable
// and set interval
    if(scrollSpeed >= 1 && scrollSpeed <= 10){
        scrollStop();
        void(
            scrollInt = setInterval('
                // not at bottom of the page or is IE
                if(
                    window.pageYOffset <
                    (document.height - window.innerHeight)
                    || document.all
                ){
                    window.scrollBy(0, scrollSpeed)
                } else {
                    scrollStop()
                }', 100
            )
        );
    } else {
        void(null);
    }
      
     
MySpace Ad Remover Bookmarklet

This is a little script that removes the ads from MySpace pages. It's the second in my useless what the hell else am I gonna do series. I've added another feature. I use AJAX to check for new messages every minute.

Script:

      
// get the advertisement div element
var myAd = document.getElementById('advert');

// if there is an ad div, it's the
// home page.  remove the ad div
if (myAd)
{
    var myAdDad = myAd.parentNode;
    myAdDad.removeChild(myAd);
    myAdDad.style.height='20px';
}

// if the ad div isn't there, it's not
// the homepage so find an ad script
// and delete it
else if (!document.getElementById('squareAd'))
{
    myAd = document.getElementsByTagName('table')[2];
    if (myAd.innerHTML.match(/ad.yieldmanager.com/i))
    {
        myAd.parentNode.removeChild(myAd);
    }
}

// this is a list of divs that annoy me
// so i remove them
var toKill = new Array
    (
      'squareAd',
      'splash_coolNewPeople',
      'splash_profile',
      'home_infoBar',
      'home_additionalLinks',
      'home_additionalLinks',
      'home_additionalLinks',
      'home_additionalLinks',
      'home_userURLInfo',
      'home_setHomePage',
      'home_searchAddressBook'
    );

// here's where I remove them
for(i in toKill)
{
    myAd = document.getElementById(toKill[i]);
    if (myAd)
    {
        myAd.parentNode.removeChild(myAd);
    }
}

// here's where i declare the important
// div nodes
var myNav = document.getElementById('nav');
var myCon = document.getElementById('content');

// this is a list of divs that i prefer
// to have on the right rather than the left
var toMove = new Array('home_messages', 'home_bulletins');

// move them
for(i in toMove)
{
    var myNode = document.getElementById(toMove[i]);
    if (myNode)
    {
        myCon.insertBefore(myNode.cloneNode(true)
            , myCon.firstChild);

        myNode.parentNode.removeChild(myNode);
    }
}

// these vars are for AJAX support
var myXML, mString, mStart, tStart, mEnd, mNode, to = 60000;

// start the timer process
window.setTimeout(xmlSend, to);

// reinit the XMLHttpRequest object, assign
// the event handler, and send the request
// if the object is ready
function xmlSend()
{
  myXML = new XMLHttpRequest();
  myXML.open('GET', top.location, true);
  myXML.onreadystatechange = myHandler;
  if (myXML.readyState == 1) myXML.send(null);
}

// handler for state changes
function myHandler()
{

  // run only if transfer is complete
  if (myXML.status == 200 && myXML.readyState == 4)
  {
    rt = myXML.responseText;

    // find the start and finish of the message section
    mString = '<div id="home_messages" class="section">';
    mStart = rt.indexOf(mString) + mString.length;
    tStart = rt.indexOf('<table class="cols">', mStart);
    mEnd = rt.indexOf('</div>', tStart);

    // swap html in message node
    mNode = document.getElementById('home_messages');
    if (mNode) mNode.innerHTML = rt.substring(mStart, mEnd);

    // find the start and finish of the friends section
    mString = '<div id="home_friends" class="section">';
    mStart = rt.indexOf(mString) + mString.length;
    tStart = rt.indexOf('View All of My Friends', mStart);
    mEnd = rt.indexOf('</div>', tStart);
    mEnd = rt.indexOf('</div>', mEnd + 6);

    // swap html in friends node
    mNode = document.getElementById('home_friends');
    if (mNode) mNode.innerHTML = rt.substring(mStart, mEnd);

    // find the start and finish of the bulletin section
    mString = '<div id="home_bulletins" class="section">';
    mStart = rt.indexOf(mString) + mString.length;
    mEnd = rt.indexOf('</div>', mStart);

    // swap html in bulletin node
    mNode = document.getElementById('home_bulletins');
    if (mNode) mNode.innerHTML = rt.substring(mStart, mEnd);

    // reset timeout
    window.setTimeout(xmlSend, to);
  }
}
      
     
HotOrNot Vote Counter Bookmarklet

This is a mozilla script that adds a number of votes to the chart for HotOrNot.com. If you are looking at your HotOrNot.com report and would like to know how many people gave you which votes, click this bookmarklet. Yeah, I know it's almost entirely useless, but what the hell else do I have to do?

Script:

      
    function(){

// declare variables
        var myCells = document.getElementsByTagName('td');
        var aCell, totalHeight=0, graphCells = new Array();
        var ratings = 0, ratingsMatch,

// build regex to find ratings
        ratingsExp = />([0-9]*) (people have|person has) rated you(<\/font>)?$/;

// loop through table cells looking for rankings
        for(var x = 0; x <= myCells.length - 1; x++){
            aCell = myCells[x];

// if it is a ranking, add it to
// the graph cell array and format
// it.
            if (aCell.bgColor){
                graphCells.push(aCell);
                totalHeight += 1 * aCell.height;
                aCell.vAlign = 'bottom';
                aCell.style.textAlign = 'center';
                aCell.style.fontSize = '8px';
                aCell.style.color = '#fff';
            } else if (ratingsMatch = aCell.innerHTML.match(ratingsExp)){

// if you find the ratings count
// save it
                ratings = ratingsMatch[1] * 1;
            }
        }

// loop through the graph cells and
// calculate the number of votes
// per cell
        while (aCell = graphCells.pop()){
            var percent = Math.round(aCell.height / totalHeight*100);
            aCell.innerHTML = Math.round(percent*ratings / 100);
        }
    }
      
     
Random Image Script

This is a script that selects a random image from the folder in which it resides and returns it. To use it, place the script (a .php file) into a folder with images in it and use the script in the source of an <img>. I call it rImage.php (remember that for the example of the corresponding HTML) below.

HTML:
<img src="rImage.php" alt="">

Script:

      

<?php
 
// setup image type array
 //
 // comment any image types you do not
 // want to include in the randomization
 // and uncomment any image types you do
 // want to include in the randomization.
 //
 // add more if you want
 //
 
$imageTypes = array();
 
//$imageTypes[] = "tif";
 
$imageTypes[] = "jpg";
 
$imageTypes[] = "png";
 
$imageTypes[] = "gif";
 
//$imageTypes[] = "bmp";

 // instantiate image array
 
$imageNames = array();

 
// determine file path and open it
 
$path dirname($_SERVER["PATH_TRANSLATED"]);
 
$pathResource opendir($path);

 
// if there are files in the path loop through
 // them, if it's an image file, put its name into
 // the array
 
if (!empty($path)){
  while ((
$fileName readdir($pathResource)) !== false){
   
$fileType strtolower(substr($fileName,
    
strlen($fileName) - 33));
   
$imageName ucwords(substr($fileName0,
    
strlen($fileName) - 4));
   if (
$fileName != "." && $fileName != ".."
    
&& (in_array($fileType$imageTypes))){
    
$imageNames[] = $fileName;
   }
  }
 }

 
// randomize and shuffle the array
 
srand((float)microtime() * 1000000);
 
shuffle($imageNames);

 
// randomize and select an array member
 // (yes, this is overkill)
 
srand((float)microtime() * 1000000);
 
$fileName $imageNames[array_rand($imageNames)];

 
// determine file type and set
 // mime type
 
$fileType strtolower(substr($fileName,
  
strlen($fileName) - 33));
 
header("Content-Type: image/$fileType");
 echo 
file_get_contents($fileName);
 
closedir($pathResource);
?>
Slideshow Script

This is a script that creates a slideshow from images in the folder it resides in. To use it, place the script (a .php file) into a folder with images in it. The caption changes to the name of the image without the extension. I call it slideshow.php. Format it any way you'd like.

Script:

      

<?php
 
//Settings
 
$title "iGallery";//Page Title
 
$imageDelay 15//seconds displayed before change

 // setup image type array
 //
 // comment any image types you do not
 // want to include in the randomization
 // and uncomment any image types you do
 // want to include in the randomization.
 //
 // add more if you want
 //
 
$imageTypes = array();
 
//$imageTypes[] = "tif";
 
$imageTypes[] = "jpg";
 
$imageTypes[] = "png";
 
$imageTypes[] = "gif";
 
//$imageTypes[] = "bmp";


  
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>
   <?php if(!empty($title)){echo $title;}else{echo dirname($_SERVER["PATH_TRANSLATED"]);};?>
  </title>
  <script type="text/javascript">
   // setup swap rate
   var imageSwapRate = <?php echo $imageDelay 1000?>;

   // declare variables
   var slideShowImages = new Array();
   var currentImage = 0;
   var displayCount = 0;

   // populate slideShowImages
<?php
 $fileNumber 
0;
 
$path dirname($_SERVER["PATH_TRANSLATED"]);
 
$pathResource opendir($path);
 if (!empty(
$path)){
  while ((
$fileName readdir($pathResource)) !== false){
   
$fileType=strtolower(substr($fileNamestrlen($fileName)-33));
   
$imageName ucwords(substr($fileName0strlen($fileName)-4));
   if (
$fileName != "." && $fileName != ".." && (in_array($fileType$imageTypes))){
?>
   slideShowImages[<?php echo $fileNumber?>] = new Array();
   slideShowImages[<?php echo $fileNumber?>][0] = new Image();
   slideShowImages[<?php echo $fileNumber?>][0].src = "<?php echo $fileName?>";
   slideShowImages[<?php echo $fileNumber?>][1] = 0;
   slideShowImages[<?php echo $fileNumber?>][2] = '<?php echo $imageName?>';

<?php
    $fileNumber
++;
   }
  }
 }
 
closedir($pathResource);
?>
   function changeImage(){
    var nextImage;

    // these two statements adjust a binary variable
    // such that each image in the folder is displayed
    // before any image repeats in a cycle
    slideShowImages[currentImage][1] = (slideShowImages[currentImage][1] + 1) % 2;
    displayCount = (++displayCount >= (2 * slideShowImages.length)) ? 0: displayCount;

    // randomly select an image and make the important swaps
    while (currentImage == (nextImage = Math.floor(Math.random() * slideShowImages.length))
     || slideShowImages[nextImage][1] != Math.floor(displayCount / slideShowImages.length)){
    }
    currentImage = nextImage;
    document.images.phpSlideShow.src = slideShowImages[currentImage][0].src;
    if(document.getElementById){
     if(document.getElementById("ssDescription")){
      document.getElementById("ssDescription").innerHTML=slideShowImages[currentImage][2];
     }
    }
    // start swap timer
    var t = setTimeout('changeImage()', imageSwapRate);
   }
  </script>
  <style type="text/css">
   div {
    font-style: italic;
    font-family: georgia, "lucida sans", sans-serif;
   }
   #main {
    height: 100%;
    width: 100%;
    padding: 0px;
    margin: 0px;
    position: fixed;
    top: 0px;
    left: 0px;
    display: table;
   }
   #main #center {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
   }
   #ssDescription {
    font-size: 48px;
   }
  </style>
 </head>
 <body onload="changeImage();">
  <div id="main">
   <div id="center">
    <img alt="" name="phpSlideShow" src="" />
    <div id="ssDescription"></div>
   </div>
  </div>
 </body>
</html>
VBA Look-up Selected

This script is written in Visual Basic for Applications. To use it, create a macro, paste the code, and bind it to a short cut key if you desire. Then, highlight up to 10 words and run the macro. The browser you set up will open a new window for each word you selected.

Script:

      
Sub Dictionary()
    For Each aWord In Selection.Range.Words
        openPages = openPages + 1
        dictionaryShell = Shell( _
         "c:\program files\netscape\netscape\netscp.exe" & _
         " http://dictionary.reference.com/search?q=" & aWord _
         , vbNormalFocus)
        If openPages >= 10 Then Exit Sub
    Next
End Sub
      
     
Visual Basic Sentence Case Conversion

This script is written in Visual Basic Script (VBScript). To use it, paste the code between header script tags in your webpage or as a function in your asp or in a module in your Visual Basic application. Pass a string to the function. It will look for a sentence end based on the standard (at least in the USA) ".  " (period - space - space) format (because one space following a period might be an abbreviation). Note that some groups of lines of code could be consolidated but VBScript in browsers doesn't interpret the & _ line wrap so it messed up my page formatting so I made it more verbose.

Script:

      
function toSentenceCase(target)

    'get first character
    curChar = left(target, 1)

    'if it is lower case, capitalize it
    If len(curChar) > 0 then
        if asc(curChar) >= 97 and asc(curChar) <= 122 then
            curChar = chr(asc(curChar) - 32)
        end if
    end if

    compString = curChar

    'go from there with the loop
    curPos = 2

    'if there is an end of a sentence
    'in the target string from the last spot
    'capitalize first character of next sentence
    do while instr(curPos, target, ".  ", 1)
        'find next sentence end
        nextPos = instr(curPos, target, ".  ", 1)

        'add end of last sentence to compilation string
        lastSentEnd = mid(target, curPos, nextPos - curPos + 3)
        compString = compString & lastSentEnd

        'first character of next sentence
        curChar = mid(target, nextPos + 3, 1)

        'if it is lower case, capitalize it
        If len(curChar) > 0 then
            if asc(curChar) >= 97 and asc(curChar) <= 122 then
                curChar = chr(asc(curChar) - 32)
            end if
        end if
        compString = compString & curChar

        'go from there with the loop
        curPos = nextPos + 4
    loop

    'add any remaining string
    compString = compString & mid(target, curPos)

    'return compilation string
    toSentenceCase = compString

end function
      
     
Javascript Sentence Case Conversion

This is the Javascript version of the above function. To use it, paste the code between header script tags in your webpage. Pass a string to the function. This script uses regular expressions to identify sentences and words that should be capitalized.

Script:

      
    var scRunning=false;
    function toSentenceCase(target){

// This script de-capitalizes proper nouns so only run it if it's obvious
// that you need to.  If you do want the script to run no matter what,
// changing tooManyCaps to a 1 should do it.
        var tooManyCaps = 20;

        var re = new RegExp("([^a-z]{" + tooManyCaps + ",})");
        var m;
        var compileString = "";

// if there are too many caps (i.e., a series of non-lowercase chars), then
// convert to sentence case
        if (target.match(re) != null || scRunning){

// continue to sentence case if used runtime
            scRunning = false;

// make the whole thing little then capitalize the first character.
            target = target.toLowerCase();
            target = target.substr(0,1).toUpperCase() + target.substring(1, target.length);

// this regex matches the end of a sentence or a new line, followed by 0 or more
// white space chars and one and only one lower case character.
            re = new RegExp("([\\.\\?!\\r\\n]+[\\s]*)([a-z]{1,1})");

// for each match, replace the last char with its ucase version
            while (m = re.exec(target)){
                target = target.substr(0, m.index) 
                  + m[1] + m[2].toUpperCase() 
                  + target.substr(m.index + m[0].length);
            }

// this regex matches I words (i.e., I, I'd, I'll, etc.) to recapitalize them.
// It just seemed like the right thing to do.
            re = new RegExp("([^\\w]i([^\\w]|'))");

// for each match, recap the i
            while (m = re.exec(target)){
                compileString += target.substr(0, m.index) + m[1].toUpperCase();
                target = target.substr(m.index + m[1].length);
            }
        }
        return compileString + target;
    }
      
     
Javascript Decimal to Binary Conversion

This javascript function converts decimal numbers to binary numbers. The padding parameter is optional. It defines the minimum length of the string (i.e., passing an 8 would return a string at least one bite long -- 00000010 vs. 10).

Script:

      
// this function converts decimal to binary.
    function toBinary(decimal, padding)
    {
      var myBinStr = '', myStringLength;

// determine how many characters you're gonna need
// for the binary representation of the decimal number
// (i.e., ln(dec)/ln(2) is the number of digits you'll need
// for the binary number.  I need at least 3 characters so
// i'll use the padding parameter to ensure that a minimum of
// 3 bits come out (i.e., 001 vs. 1)
      myStringLength = Math.max(Math.floor(Math.log(decimal) / Math.LN2) + 1 , (padding) ? padding : 0);

      for (var i = myStringLength - 1; i >= 0; i--)
      {

// this is the binary conversion.  if you don't get it,
// i'd suggest you seek tutorials about base conversions
        if (decimal - Math.pow(2, i) >= 0)
        {
          myBinStr += '1';
          decimal -= Math.pow(2, i);
        } else {
          myBinStr += '0';
        }
      }
      return myBinStr;
    }
      
     
Contact Me

If you have any questions about my scripts, feel free to contact me at admin@pcdesigns.net.