Auto Redirect

网站外部链接自动跳转 | 知乎 | 简书 | Steam

  1. // ==UserScript==
  2. // @name Auto Redirect
  3. // @namespace coderzhaoziwei@outlook.com
  4. // @description 网站外部链接自动跳转 | 知乎 | 简书 | Steam
  5. // @version 1.0.2
  6. // @homepage https://greasyfork.org/scripts/426352
  7. // @author Coder Zhao
  8. // @match https://link.zhihu.com/*
  9. // @match https://www.jianshu.com/go-wild*
  10. // @match https://steamcommunity.com/linkfilter*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. "use strict";
  16.  
  17. /**
  18. * @key paramkey - 查询字串 location.search 中指定的 key
  19. * @key hostname - 主机名称 location.hostname 的值
  20. * @key testlink - 测试链接 可省略
  21. */
  22. const list = [
  23. {
  24. "paramkey": "target",
  25. "hostname": "link.zhihu.com",
  26. "testlink": "https://link.zhihu.com/?target=https://github.com/coderzhaoziwei",
  27. },
  28. {
  29. "paramkey": "url",
  30. "hostname": "www.jianshu.com",
  31. "testlink": "https://www.jianshu.com/go-wild?ac=2&url=https://github.com/coderzhaoziwei",
  32. },
  33. {
  34. "paramkey": "url",
  35. "hostname": "steamcommunity.com",
  36. "testlink": "https://steamcommunity.com/linkfilter/?url=https://github.com/coderzhaoziwei",
  37. },
  38. ];
  39.  
  40. list.find(data => {
  41. if (location.hostname === data.hostname) {
  42. const params = new URLSearchParams(location.search);
  43. const key = data.paramkey;
  44.  
  45. if (params.has(key)) {
  46. location.replace(params.get(key));
  47. }
  48.  
  49. return params.has(key);
  50. }
  51. });
  52.  
  53. })();