jh / Amazon Smile Redirect (com/de/co.uk)

// ==UserScript==
// @name         Amazon Smile Redirect (com/de/co.uk)
// @version      1.01
// @description  Redirects Amazon.com/de/co.uk to smile.Amazon.com/de/co.uk
// @include      http://www.amazon.com/*
// @include      https://www.amazon.com/*
// @include      http://www.amazon.de/*
// @include      https://www.amazon.de/*
// @include      http://www.amazon.co.uk/*
// @include      https://www.amazon.co.uk/*
// @exclude      http://smile.amazon.com/*
// @exclude      https://smile.amazon.com/*
// @exclude      http://smile.amazon.de/*
// @exclude      https://smile.amazon.de/*
// @exclude      http://smile.amazon.co.uk/*
// @exclude      https://smile.amazon.co.uk/*
// @exclude      https://www.amazon.com/ap/*
// @exclude      https://www.amazon.com/gp/css/*
// @exclude      https://www.amazon.de/ap/*
// @exclude      https://www.amazon.de/gp/css/*
// @exclude      https://www.amazon.co.uk/ap/*
// @exclude      https://www.amazon.co.uk/gp/css/*
// @copyright    2018+
// @updateURL    https://openuserjs.org/meta/jh/Amazon_Smile_Redirect_(comdeco.uk).meta.js
// @downloadURL  https://openuserjs.org/install/jh/Amazon_Smile_Redirect_(comdeco.uk).user.js
// @icon         https://static.amazon.jobs/assets/favicon-17d02e2db6dbedb95dd449d06868c147ac2c3b5371497bcb9407e75336a99e09.ico
// @grant        none
// @license      MIT
// ==/UserScript==


// Check to see if #nav-tools exists to check if user is logged in //
var navTools = document.getElementById( "nav-tools" );
var navLine;
var navlineText;

if ( typeof( navTools ) != "undefined" && navTools != null )
{
	fetchNavLines();
}

// Fetch nav-line-1 elms //
function fetchNavLines()
{
	var navLines = navTools.getElementsByClassName( "nav-line-1" );
    var SignedIn = 1;

	for ( var i = 0; i < navLines.length; i++ )
	{
		if ( navLines[i].innerHTML.includes( "Hello." ) || navLines[i].innerHTML.includes( "Hallo!" ) || navLines[i].innerHTML.includes( "Witaj!" ) || navLines[i].innerHTML.includes( "Merhaba." ) || navLines[i].innerHTML.includes( "Witaj!" ) || navLines[i].innerHTML.includes( "DobrĂ½ den." ) )
		{
			navLine 	= navLines[i];
			navlineText = navLines[i].innerHTML;
            SignedIn    = 0;
			break;
		}
	}

    if ( SignedIn )
    {
       	// Redirect user to corresponding page on Amazon Smile //
        if ( window.location.hostname == "www.amazon.com" )
            window.location.replace( "https://smile.amazon.com" + window.location.pathname + location.search );
        else if ( window.location.hostname == "www.amazon.de" )
            window.location.replace( "https://smile.amazon.de" + window.location.pathname + location.search );
        else if ( window.location.hostname == "www.amazon.co.uk" )
            window.location.replace( "https://smile.amazon.co.uk" + window.location.pathname + location.search );
    }
    else
    {
        // Redirect user to the Sign In page (because Smile only works if signed in) //
        if ( window.location.hostname == "www.amazon.com" )
            window.location.replace( "https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0" );
        else if ( window.location.hostname == "www.amazon.de" )
            window.location.replace( "https://www.amazon.de/ap/signin?_encoding=UTF8&ignoreAuthState=1&openid.assoc_handle=deflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0" );
        else if ( window.location.hostname == "www.amazon.co.uk" )
            window.location.replace( "https://www.amazon.co.uk/ap/signin?_encoding=UTF8&ignoreAuthState=1&openid.assoc_handle=gbflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0" );
    }
}