PHP.net redirect to english

redirects to English version of the documentation

目前為 2019-02-11 提交的版本,檢視 最新版本

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