thetenfold

Untitled

Aug 7th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           PlayLanguage
  3. // @include        https://play.google.com/*
  4. // @include        https://play.google.com/store/*
  5. // @include        https://play.google.com/store/apps/*
  6. // @include        http://play.google.com/*
  7. // ==/UserScript==
  8.  
  9. window.addEventListener('load', function () {
  10.     var newP = document.createElement('p'),
  11.         url = window.location.href,
  12.         regex = /([?&]hl=)\w*/,
  13.         langInUrl = regex.test(url),
  14.         paramInUrl = /\?\w+=/.test(url),
  15.         position = document.querySelector('.document-title'),
  16.         tmpA, langs, i;
  17.  
  18.     function handle_click(event) {
  19.         event.preventDefault();
  20.         event.stopPropagation();
  21.         window.top.location.href = event.target.href;
  22.     }
  23.  
  24.     // Make sure the page is not in a frame
  25.     if (window.self !== window.top || !position) { return; }
  26.  
  27.     // define languages here
  28.     langs = [
  29.         {name : 'English', abbrev : 'en'},
  30.         {name : 'German', abbrev : 'de'}
  31.     ];
  32.  
  33.     for (i = 0; i < langs.length; i += 1) {
  34.         tmpA = document.createElement('a');
  35.         tmpA.href = langInUrl ? url.replace(regex, '$1' + langs[i].abbrev) : url + (paramInUrl ? '&' : '?') + 'hl=' + langs[i].abbrev;
  36.         tmpA.appendChild( document.createTextNode( langs[i].name ) );
  37.         tmpA.addEventListener('click', handle_click, false);
  38.         newP.appendChild(tmpA);
  39.         if ( (i + 1) < langs.length) {
  40.             newP.appendChild( document.createTextNode(' | ') );
  41.         }
  42.     }
  43.  
  44.     newP.setAttribute('style', 'float: right; clear: right; font-size: 13px;');
  45.     position.appendChild(newP);
  46. }, false);
Advertisement
Add Comment
Please, Sign In to add comment