Last active
March 29, 2018 11:58
-
-
Save dennyweiss/4a3d09d7044b07fbf52ff97d116d763a to your computer and use it in GitHub Desktop.
bookmarklet for switching languages from german to english
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function() { | |
/* add this code starting at 'javscript:' as address to a bookmark entry */ | |
var currentUrl = window.location.href; | |
var targetUrl = null; | |
var BreakException = {}; | |
var replaceMatrix = [ | |
{ search: '/de/', replace: '/en/'}, | |
{ search: '/de-de/', replace: '/en-us/'} | |
]; | |
try { | |
replaceMatrix.forEach(function(item){ | |
if (currentUrl.includes(item.search)) { | |
targetUrl = currentUrl.replace(item.search,item.replace); | |
throw BreakException; | |
} | |
}); | |
} catch(e) { | |
if (e !== BreakException) { | |
throw e; | |
} | |
} | |
/*check if new target url is not null*/ | |
if (!!targetUrl) { | |
window.location.href = targetUrl; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment