Escape From WebVPN

避免WebVPN劫持CC98站外链接

目前为 2022-03-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Escape From WebVPN
  3. // @version 0.0.2
  4. // @description 避免WebVPN劫持CC98站外链接
  5. // @icon https://www.cc98.org/static/98icon.ico
  6. // @author ml98
  7. // @namespace http://tampermonkey.net/
  8. // @license MIT
  9. // @match http://www-cc98-org-s.webvpn.zju.edu.cn:8001/*
  10. // @run-at document-idle
  11. // @grant none
  12. // ==/UserScript==
  13. /* eslint-env jquery */
  14. function decodeWebVPNURL(url) {
  15. try {
  16. var urlObj = new URL(url);
  17. } catch(e) {
  18. return '';
  19. }
  20. let host = urlObj.host;
  21. let suffix = '.webvpn.zju.edu.cn:8001';
  22. if (host.endsWith(suffix)) {
  23. host = host.slice(0, host.length - suffix.length);
  24. } else {
  25. return url;
  26. }
  27. if (host.endsWith('-s')) {
  28. urlObj.protocol = 'https:';
  29. host = host.slice(0, host.length - 2);
  30. }
  31. if (host.endsWith('-p')) {
  32. host = host.slice(0, host.length - 2);
  33. urlObj.port = host.slice(host.lastIndexOf('-') + 1);
  34. host = host.slice(0, host.lastIndexOf('-'));
  35. } else {
  36. urlObj.port = '';
  37. }
  38. urlObj.host = host.replaceAll('-', '.').replaceAll('..', '-');
  39. return urlObj + '';
  40. }
  41. $(document).on('click', 'a', function(e) {
  42. if(this.href && !(new URL(this.href).host.includes('cc98.org'))) {
  43. e.preventDefault();
  44. window.open().location = decodeWebVPNURL(this.href);
  45. return false;
  46. }
  47. })