Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name PlayLanguage
- // @include https://play.google.com/*
- // @include https://play.google.com/store/*
- // @include https://play.google.com/store/apps/*
- // @include http://play.google.com/*
- // ==/UserScript==
- window.addEventListener('load', function () {
- var newP = document.createElement('p'),
- url = window.location.href,
- regex = /([?&]hl=)\w*/,
- langInUrl = regex.test(url),
- paramInUrl = /\?\w+=/.test(url),
- position = document.querySelector('.document-title'),
- tmpA, langs, i;
- function handle_click(event) {
- event.preventDefault();
- event.stopPropagation();
- window.top.location.href = event.target.href;
- }
- // Make sure the page is not in a frame
- if (window.self !== window.top || !position) { return; }
- // define languages here
- langs = [
- {name : 'English', abbrev : 'en'},
- {name : 'German', abbrev : 'de'}
- ];
- for (i = 0; i < langs.length; i += 1) {
- tmpA = document.createElement('a');
- tmpA.href = langInUrl ? url.replace(regex, '$1' + langs[i].abbrev) : url + (paramInUrl ? '&' : '?') + 'hl=' + langs[i].abbrev;
- tmpA.appendChild( document.createTextNode( langs[i].name ) );
- tmpA.addEventListener('click', handle_click, false);
- newP.appendChild(tmpA);
- if ( (i + 1) < langs.length) {
- newP.appendChild( document.createTextNode(' | ') );
- }
- }
- newP.setAttribute('style', 'float: right; clear: right; font-size: 13px;');
- position.appendChild(newP);
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment