Search code examples
javascriptgreasemonkeyyahoo

How to change the Yahoo Mail, sign out URL?


This is my code I came up with (w/ lots of outside help; I'm not fluent in JS):

setTimeout(function() {
   var logout = document.querySelector('a.yucs-signout'),
   link = "http://login.yahoo.com/config/login?logout=1&.src=cdgm&.intl=us&.direct=2&.done=http://ma
il.yahoo.com";
   logout.setAttribute ('onclick', 'location.href = 
\"' + link + '\"');
   logout.setAttribute ('href', link);
}, 17000)

I'm trying to change the sign-out URL at Yahoo Mail, when clicking the "Sign Out" dropdown menu item, so that you are redirected back to the Yahoo Mail login page -- not the yahoo.com "main page". This is to make it easier to login with another account.

We couldn't get it to work. Even added a timeout to the code in case my js was running too soon. Still no go.

I was told "The class="yucs-submenu-toggle" on the <a id="yucs-menu_link_profile"> with no CSS on :hover means javascript is being used."

Logout control screenshot:
Logout control screenshot

You have to hover over that section to get the menu to dropdown & see Sign Out.

I also made sure my "Included page" was https: https://*.mail.yahoo.*/*

I'm trying to use this with Greasemonkey, why isn't it working?

Edit: I was thinking this other answer might have something useful, like the jQuery stuff in it?


Solution

    1. If the code in the question is copied verbatim, then it has syntax errors from improperly made, multi-line strings.
    2. Don't set onclick from a userscript. Ever! In this case, no form of click event handling is necessary anyway, and may block the logout operation of the page.

    Other than that, that code works for me -- at least on Yahoo, UK, mail.

    Some more minor points:

    1. You don't need a setTimeout in this case.
    2. Don't brute-force the link like that; it may not always work. Use regex to surgically change just the done variable part.


    Here's a complete working script:

    // ==UserScript==
    // @name        _Fix Yahoo mail logout
    // @include     http://mail.yahoo.com/*
    // @include     http://*.mail.yahoo.com/*
    // @include     https://mail.yahoo.com/*
    // @include     https://*.mail.yahoo.com/*
    // ==/UserScript==
    
    //-- Only run in the top page, not the various iframes.
    if (window.self === window.top) {
        var logout = document.querySelector ('a.yucs-signout');
        if (logout) {
            var link = logout.href.replace (
                /&\.done=[^&#]+(&?)/, "&.done=http://mail.yahoo.com$1"
            );
            logout.href = link;
        }
        else
            console.error ("From GM script:  Node 'a.yucs-signout' not found.");
    }