Force Google Results in English

Automatically adds &hl=en to Google search URLs to force English results

  1. // ==UserScript==
  2. // @name Force Google Results in English
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically adds &hl=en to Google search URLs to force English results
  6. // @author You
  7. // @match *://www.google.com/*
  8. // @match *://google.com/*
  9. // @match *://www.google.co.*/*
  10. // @match *://google.co.*/*
  11. // @match *://www.google.com.au/*
  12. // @match *://www.google.ca/*
  13. // @match *://www.google.de/*
  14. // @match *://www.google.fr/*
  15. // @match *://www.google.es/*
  16. // @match *://www.google.it/*
  17. // @match *://www.google.jp/*
  18. // @match *://www.google.ru/*
  19. // @match *://www.google.br/*
  20. // @match *://www.google.in/*
  21. // @grant none
  22. // @run-at document-start
  23. // ==/UserScript==
  24.  
  25. (function() {
  26. 'use strict';
  27. // Run immediately to minimize any visible delay
  28. const enforceEnglishResults = () => {
  29. // Only proceed if this is a Google search page
  30. if (!window.location.href.includes('google.')) return;
  31. // Don't modify the URL if it already has the language parameter
  32. if (window.location.href.includes('&hl=en') || window.location.href.includes('?hl=en')) return;
  33. // Get the current URL
  34. let currentUrl = window.location.href;
  35. // Add the English language parameter
  36. if (currentUrl.includes('?')) {
  37. // URL already has parameters, append our parameter
  38. if (!currentUrl.endsWith('&')) {
  39. currentUrl += '&';
  40. }
  41. currentUrl += 'hl=en';
  42. } else {
  43. // URL doesn't have parameters yet, add our parameter as the first one
  44. currentUrl += '?hl=en';
  45. }
  46. // Update the URL without refreshing the page
  47. window.history.replaceState({}, document.title, currentUrl);
  48. // For cases where the page is still loading, also change the location
  49. // This provides a fallback but will cause a page refresh
  50. if (document.readyState !== 'complete') {
  51. window.location.href = currentUrl;
  52. }
  53. };
  54. // Run the function immediately
  55. enforceEnglishResults();
  56. // Monitor URL changes for single-page behavior
  57. let lastUrl = window.location.href;
  58. new MutationObserver(() => {
  59. if (lastUrl !== window.location.href) {
  60. lastUrl = window.location.href;
  61. enforceEnglishResults();
  62. }
  63. }).observe(document, {subtree: true, childList: true});
  64. // Add event listener for when the page is loaded
  65. window.addEventListener('load', enforceEnglishResults);
  66. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址