Amazon Auto-Smile

Automatically redirects all www.amazon.com URLs to their smile.amazon.com equivalent.

  1. // ==UserScript==
  2. // @name Amazon Auto-Smile
  3. // @namespace
  4. // @version 0.1
  5. // @description Automatically redirects all www.amazon.com URLs to their smile.amazon.com equivalent.
  6. // @match http://www.amazon.com/*
  7. // @match https://www.amazon.com/*
  8. // @run-at document-start
  9. // @copyright 2013
  10. // ==/UserScript==
  11.  
  12. // Only redirect if we're the top window
  13. //
  14. // This prevents iframes embedded within www.amazon.com pages from
  15. // triggering redirects themselves: we only want the outer window to do that.
  16. // Unfortunately, it has the side-effect that if amazon.com is embedded
  17. // in a frame on some other website, we'll skip doing the redirect even though
  18. // we're supposed to.
  19.  
  20. if (window.self === window.top) {
  21. var new_host = window.location.host.replace(/^www\./, 'smile.');
  22. var new_url = window.location.protocol + '//' + new_host + window.location.pathname + window.location.search + window.location.hash;
  23. window.location.replace(new_url);
  24. }