PHP.net redirect to chinese

redirects to Chinese version of the documentation

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