PHP.net redirect to english

redirects to English version of the documentation

  1. // ==UserScript==
  2. // @name PHP.net redirect to english
  3. // @namespace https://greasyfork.org/en/scripts/40797-php-net-redirect-to-english
  4. // @version 0.3.2
  5. // @description redirects to English version of the documentation
  6. // @author adamaru
  7. // @match http://php.net/manual/*
  8. // @match https://php.net/manual/*
  9. // @match http://*.php.net/manual/*
  10. // @match https://*.php.net/manual/*
  11. // @grant none
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. /* jshint esversion: 6 */
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. const url = window.location.href;
  21. const regex = /(https?:\/\/(?:[^\.]+\.)?php\.net\/manual\/)([^\/]+)(\/.*)/gm;
  22. const match = regex.exec(url);
  23.  
  24. if(!match){
  25. return;
  26. }
  27.  
  28. if(match[2] === 'en'){
  29. return;
  30. }
  31.  
  32. const newUrl = match[1] + 'en' + match[3];
  33. window.location.replace(newUrl);
  34. })();