AK Box

a box

  1. // ==UserScript==
  2. // @name AK Box
  3. // @namespace github.com/starxg
  4. // @version 0.0.1
  5. // @author starxg
  6. // @description a box
  7. // @license https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh-hans
  8. // @match *://www.baidu.com/*
  9. // @require https://registry.npmmirror.com/jquery/3.7.1/files/dist/jquery.min.js
  10. // @connect baidu.com
  11. // @connect localhost
  12. // @connect *
  13. // @grant GM_xmlhttpRequest
  14. // @run-at document-start
  15. // ==/UserScript==
  16.  
  17. (function ($) {
  18. 'use strict';
  19.  
  20. var _GM_xmlhttpRequest = /* @__PURE__ */ (() => typeof GM_xmlhttpRequest != "undefined" ? GM_xmlhttpRequest : void 0)();
  21. function directLink() {
  22. const links = [];
  23. const suffix = "www.baidu.com/link";
  24. links.push(...$(`a[href^='http://${suffix}']`));
  25. links.push(...$(`a[href^='https://${suffix}']`));
  26. for (const e of links) {
  27. let url = $(e).prop("href");
  28. if (!url.startsWith(location.protocol)) {
  29. const segments = url.split(":", 2);
  30. segments[0] = location.protocol;
  31. url = segments.join("");
  32. }
  33. _GM_xmlhttpRequest({
  34. url: url + "&wd=&eqid=",
  35. timeout: 15e3,
  36. onload: function(response) {
  37. const urls = response.responseText.match(/https?:\/\/[^\s'"]+/);
  38. if (urls instanceof Array && urls.length > 0) {
  39. $(e).prop("href", urls[0]);
  40. }
  41. }
  42. });
  43. }
  44. }
  45. function callback() {
  46. directLink();
  47. }
  48. location.host === "www.baidu.com" ? $(callback) : false;
  49.  
  50. })(jQuery);