Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Location
    Orange County, CA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Text Manipulation Issues

    I code through Greasemonkey using Firebug on Firefox. I'm trying to write my first script using a simple function to change the appearance of my email address in Gmail.

    My current email address is formatted like this example:
    Code:
    firstlast@gmail.com
    I want the script to manipulate the text to resemble this:
    Code:
    first.last@gmail.com
    I've posted my script below. The Mozilla error console shows no syntax errors or warnings. JavaScript IS allowed to run and there are no restrictions of any kind that should hinder this script's ability to run. What am I doing wrong in the code? Any help would be greatly appreciated!

    Code:
    (function () {
    
    	var loadOldName = window.document.body.getElementById('loading').getElementsByClassName('msg').textContent('\nLoading+ firstlast@gmail.com…\n');
    	var topLeftName = window.document.getElementsByClassName('cP').getElementsByClassName('bB').getElementsByTag('u').innerHTML('<b>firstlast@gmail.com</b>');
    	var topLeftDrop = window.document.getElementsByClassName('cP').getElementsByClassName('J-N-Jz').innerHTML('<span class="Qu L4">firstlast@gmail.com (default)</span>');
    
    	function changeName() {
    		
    		if(loadOldName) {
    			window.document.body.getElementById('loading').getElementsByClassName('msg').removeChild(textContent('\nLoading+ firstlast@gmail.com…\n')).appendChild(textContent('\nLoading+ first.last@gmail.com…\n'));
    		};
    
    		if(topLeftName) {
    			window.document.getElementsByClassName('cP').getElementsByClassName('bB').getElementsByTag('u').removeChild(innerHTML('<b>firstlast@gmail.com</b>')).appendChild(innerHTML('<b>first.last@gmail.com</b>'));
    		};
    
    		if(topLeftDrop) {
    			window.document.getElementsByClassName('cP').getElementsByClassName('J-N-Jz').removeChild(innerHTML('<span class="Qu L4">firstlast@gmail.com (default)</span>')).appendChild(innerHTML('<span class="Qu L4">first.last@gmail.com (default)</span>'));
    		};
    
    	};
    
    	changeName();
    
    });
    Last edited by DaveyJake; 10-29-2010 at 04:13 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,111
    Thanks
    75
    Thanked 4,335 Times in 4,301 Posts
    First off, you can't use innerHTML as a *selector*. That is, there's no function by the name innerHTML. It's just an attribute. The same is true for textContent.
    So these code fragments
    Code:
        textContent('\nLoading+ firstlast@gmail.com…\n')
        innerHTML('<b>firstlast@gmail.com</b>')
        innerHTML('<span class="Qu L4">firstlast@gmail.com (default)</span>')
    are nonsense.

    Secondly, the methods with an "s" after "Element" return *COLLECTIONS* of elements. Essentially arrays. For example,
    Code:
    document.getElementById('loading').getElementsByClassName('msg')
    will return all the elements inside of the element with the id of "loading" that have the className "msg".

    Even if there is only one such element, you will still get an array with one element.

    So you would need to do
    Code:
    document.getElementById('loading').getElementsByClassName('msg')[0]
    to reference that one element.

    Needless to say, none of that code will come close to working.

    ***********

    I know it's none of my business, but what is the point of this? The changes won't be visible to anyone not using GreaseMonkey. Is it only for your own edification?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Location
    Orange County, CA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the great response! And yes, this is for my own edification. I just want to see if I can write a proper JS that will function properly. I know HTML and CSS, but JS has always haunted me in one facet or another. I need to master it!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •