views:

1424

answers:

6

At work, I use Gmail's chat, since it's encrypted and logs chats without installing or saving anything to the hard drive. At home, I use Pidgin. When I log into GMail at home, I have to log out of chat, or messages will end up in the wrong place. When I log into GMail at work, I have to log back in to chat.

In other words, when I start Firefox at home, I want Gmail's chat disabled automatically. When I start Firefox at work, I want Gmail's chat enabled automatically.

Is there a way to use a Greasemonkey script or similar to force logging in and logging out on specific machines? It would seem simple enough; just follow a URL or simulate clicking a link. Unfortunately, Gmail doesn't use actual links.

While logged out:

<span tabindex="0" role="link" action="si" class="az9OKd">Sign into chat</span>

While logged in, in drop-down menu:

<div tabindex="-1" id=":1mj" role="menuitem" class="oA" value="si"><div class="uQ c6"/>Sign into chat</div>

<div tabindex="-1" id=":8f" role="menuitem" class="oA" value="sia"><div class="uQ c5"/>Sign into AIM®</div>

<div tabindex="-1" id=":8e" role="menuitem" class="oA" value="so"><div class="uQ df"/>Sign out of chat</div>

At bottom of page:

<span id=":im" class="l8 ou" tabindex="0" role="link">turn off chat</span>

<span id=":im" class="l8 ou" tabindex="0" role="link">turn on chat</span>

Anyone know how to "click" these non-links with JavaScript or access their functions? I would imagine that "so" means "sign out", "si" means "sign in", and "sia" means "sign in AIM". Can I somehow call these actions directly?

Is there some other alternative for disabling chat?

+2  A: 

I use gmail chat both within a gmail window and using Adium, and when a friend initiates a chat I get his or her message in both windows, so being logged in in two separate places isn't a problem.

Does this not work for you?

EDIT: As the commenter said below, you could decipher gmail's obfuscated javascript to try and find out how the links are attached to javascript functions, and which functions are called. Then you don't need to simulate a click on the link, you just need to call the appropriate javascript function.

Brian Ramsay
This happens with me too. I leave my Gmail chat signed in at home and when I connect at work, I get the messages at work too.
Nick Presta
Sometimes it shows up in both, sometimes it doesn't. I use both Gchat and AIM inside of Gmail's chat.The important thing is that there's no point in being signed into Gmail's chat when I'm already signed into Pidgin on the same computer.
endolith
You could try and decipher their obfuscated javascript and figure out what function is called for those links.
BabyCakes
Keep in mind those function names can and will change when they rebuild their code
bdonlan
+1  A: 

I'm not sure if you're aware, but you can end a Gmail session remotely. Click the link that says this at the bottom of your Gmail page:

Last Account Activity: blah blah Details

Dan Lorenc
This has nothing to do with my question.
endolith
Then I don't understand the question. The link in my post lets you remotely close a Gmail connection like this sentence "When I log into GMail at home, I have to log out, or messages will end up in the wrong place. When I log into GMail at work, I have to log back in." led me to believe you wanted to do.
Dan Lorenc
I mean that when I log into Gmail at home, I want chat disabled. When I log into Gmail at work, I want chat enabled. I don't want to log out of my Home session from Work or my Work session from Home, which is what you're describing. I just want to log out of chat itself. I've tried to clarify the question.
endolith
+1  A: 

Can people still chat to you if it's not even displayed?

I only have a couple of contacts on gchat, so can't test easily...

    window.addEventListener('load', function() {
  if (unsafeWindow.gmonkey) {
    unsafeWindow.gmonkey.load('1.0', function(gmail) {
      function logOffChat() {
     var leftPane = gmail.getNavPaneElement().childNodes[0];
     var chat = leftPane.childNodes[3];

     chat.id = 'googleChatElement';
 chat.parentNode.removeChild(chat);
      }

      logOffChat();

    });
  }
}, true);

My guess is, it'll still run everything in the background and you'll appear logged in...

davewasthere
Just tried with another account, and no, it still stays logged in in the background. Nice try, though. :)
endolith
A: 

May be I do not understand. But can you try using Selenium to work this out somehow? Its an framework to automate functional testing in web apps.

Xinxua
I have never heard of Selenium. Maybe someone who knows what they are doing should use it to figure out the link clicking, and then tell me the solution. :)
endolith
Probably what you are asking me is to code up and provide you the solution? Thats like doing consulting work. The first result for selenium in google - http://seleniumhq.org/
Xinxua
A: 

Adding *chatenabled.mail.google.com* to Adblock's filter list prevents Gmail chat from connecting. This will solve my problem, even though I wasn't able to figure out how to click the "link".

endolith
Now this is making Firefox hog my CPU, maybe from Adblock and Gmail fighting with each other over this. I need to find some other solution.
endolith
That CPU hog may not be related to adBlock, because at work I have filtered chatenabled.mail.google.com (f*cking proxies) and when the chat window is visible I get that hog. The solution was to raise it clicking the minus sign beside your name.
diega
That works for me too. Thanks!
endolith
Of course I have to remember the close the window each time, which negates the whole point of this question. >:(
endolith
The CPU hog appears to have been fixed!
endolith
+2  A: 

I know the original post is old, but I'm posting here for reference.

var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); YourElement.dispatchEvent(evt);

dispatchEvent reference from: https://developer.mozilla.org/en/DOM/element.dispatchEvent

KB
Can you explain how that works?
endolith
document.createEvent is creating an generic mouse event object, then you make that generic mouse event object into a click and send that event to your span. The span then sees it just as a mouse click (not knowing it's any different from a human user clicking on the span.The only thing you have to change in the example is the YourElement should be the span element you want to click. The rest are just to create a mouse click event.
KB
Ok. I can't figure out how to get it to trigger the links in the question, though, based on value="so", for instance.
endolith