TJUPT - Direct Links

将 TJUPT 中的外链转换为直接链接

  1. // ==UserScript==
  2. // @name TJUPT - Direct Links
  3. // @namespace https://github.com/whtsky/userscripts/
  4. // @version 20200213
  5. // @description 将 TJUPT 中的外链转换为直接链接
  6. // @match https://tjupt.org/*
  7. // @grant none
  8. // @supportURL https://github.com/whtsky/userscripts/issues
  9. // ==/UserScript==
  10.  
  11. function removeTo(s, to) {
  12. const index = s.search(to)
  13. if (index !== -1) {
  14. return s.substr(index + to.length)
  15. }
  16. return s
  17. }
  18.  
  19. document.querySelectorAll('a').forEach(anchor => {
  20. let link = anchor.href
  21. if (link.startsWith('https://tjupt.org/adredir.php')) {
  22. link = removeTo(link, 'url=')
  23. } else if (link.startsWith('https://tjupt.org/jump_external.php')) {
  24. link = removeTo(link, 'ext_url=')
  25. } else {
  26. return
  27. }
  28. anchor.href = decodeURIComponent(link)
  29. })