PHP.net redirect to english

redirects to English version of the documentation

目前为 2019-05-07 提交的版本。查看 最新版本

  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.1
  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 https://secure.php.net/manual/*
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 6 */
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. const url = window.location.href;
  20. const regex = /(https?:\/\/(?:secure\.)?php\.net\/manual\/)([^\/]+)(\/.*)/gm;
  21. const match = regex.exec(url);
  22.  
  23. if(!match){
  24. return;
  25. }
  26.  
  27. if(match[2] === 'en'){
  28. return;
  29. }
  30.  
  31. const newUrl = match[1] + 'en' + match[3];
  32. window.location.replace(newUrl);
  33. })();