Leetcode CN/EN site switcher

Leetcode中英文网站切换,切换使用ctr+`(Esc下面,数字1左边那个按钮); 屏蔽中文跳转banner,可以将"||leetcode.cn/api/is_china_ip/"填入到adblocker

  1. // ==UserScript==
  2. // @name Leetcode CN/EN site switcher
  3. // @namespace http://tampermonkey.net/
  4. // @license MIT
  5. // @version 0.2
  6. // @description Leetcode中英文网站切换,切换使用ctr+`(Esc下面,数字1左边那个按钮); 屏蔽中文跳转banner,可以将"||leetcode.cn/api/is_china_ip/"填入到adblocker
  7. // @author GeeMaple
  8. // @match *://leetcode.com/*
  9. // @match *://leetcode.cn/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  11.  
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. document.addEventListener('keydown', function(event) {
  18. if ((event.ctrlKey && event.key === '`')) {
  19. event.preventDefault();
  20. let url = window.location.href;
  21. if (url.includes('leetcode.com')) {
  22. window.location.assign(url.replace('leetcode.com', 'leetcode.cn'))
  23. } else {
  24. window.location.assign(url.replace('leetcode.cn', 'leetcode.com'))
  25. }
  26. }
  27. });
  28. })();