YouTube and Google region setter

Youtube and google regularly change your region based on your IP. This userscript automatically sets it to your preferred region instead.

  1. // ==UserScript==
  2. // @run-at document-start
  3. // @version 1.0.0
  4. // @name YouTube and Google region setter
  5. // @namespace https://github.com/emmaexe/userscripts
  6. // @author emmaexe
  7. // @description Youtube and google regularly change your region based on your IP. This userscript automatically sets it to your preferred region instead.
  8. // @license GPL-3.0-only
  9. // @homepageURL https://github.com/emmaexe/userscripts
  10. // @supportURL https://github.com/emmaexe/userscripts/issues
  11. // @include *://youtube.*/*
  12. // @include *://*.youtube.*/*
  13. // @include *://www.google.com/*
  14. // @exclude *://www.google.com/a/*
  15. // @icon https://raw.githubusercontent.com/emmaexe/userscripts/main/youtube-region-setter/assets/youtube-ico-32.png
  16. // @grant GM.registerMenuCommand
  17. // @grant GM.getValue
  18. // @grant GM.setValue
  19. // ==/UserScript==
  20.  
  21. GM.registerMenuCommand('Set preferred youtube/google region', async () => {
  22. region = prompt('Please enter your preferred region:', 'GB');
  23. await GM.setValue('region', region);
  24. window.location.reload();
  25. })
  26.  
  27. async function main(){
  28. let region = await GM.getValue('region', 'GB');
  29. let oldUrl = location.href;
  30. let arr = oldUrl.split('?');
  31. if (!(oldUrl.includes(`&gl=${region}`) || oldUrl.includes(`?gl=${region}`))) {
  32. if (arr.length > 1 && arr[1] !== '') {
  33. location.replace(oldUrl+`&gl=${region}`);
  34. } else {
  35. location.replace(oldUrl+`?gl=${region}`);
  36. }
  37. }
  38. }
  39.  
  40. main();