mainHook.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. if (typeof $ === 'function'&& typeof(isSpiderPage)==='undefined') {
  2. $.ajaxPrefilter(function (options, orginOption, jqXHR) {
  3. var beforeCallBack = options.success;
  4. var beforeSettring = orginOption;
  5. options.success = function (r) {
  6. if (r.antiVerify) {
  7. if (r.antiVerify === 1) {
  8. antiReload(); //重新请求数据
  9. //移除验证码
  10. var antiVerify = document.querySelector("#antiVerify");
  11. antiVerify.parentNode.removeChild(antiVerify);
  12. } else {
  13. window.nextSetting = beforeSettring;//记录请求
  14. shwoCode(r.textVerify, r.imgData);//验证码展示
  15. }
  16. } else if (r.antiJump) {
  17. window.location.href = r.href;
  18. } else {
  19. if (r.antiData && typeof (antiDecode) !== "function") {//等待初始化完毕
  20. var localInterval = setInterval(function () {
  21. if (typeof (antiDecode) === "function") {
  22. r = JSON.parse(antiDecode(r.antiData))
  23. if (beforeCallBack) beforeCallBack(r)
  24. clearInterval(localInterval)
  25. }
  26. }, 200)
  27. } else {
  28. if (r.antiData) {
  29. r = JSON.parse(antiDecode(r.antiData))
  30. }
  31. if (beforeCallBack) beforeCallBack(r)
  32. }
  33. }
  34. }
  35. })
  36. }
  37. function antiReload(flag) {
  38. try {
  39. if (flag === 1) {
  40. window.nextSetting.data.antiVerifyCheck = document.querySelector("#antivalue").value.substr(1);
  41. window.nextSetting.data.imgw = document.querySelector("#antiimg").width;
  42. } else {
  43. if (window.nextSetting.data) {
  44. delete window.nextSetting.data.antiVerifyCheck;
  45. }
  46. }
  47. } catch (e) {
  48. console.log(e)
  49. }
  50. $.ajax(window.nextSetting)
  51. }
  52. function shwoCode(text, imgdata) {
  53. var htmlcode = '<div style="width: 100%;height: 100%;position:absolute;top:0;background-color: #382f3d;opacity: .1;z-index: 99999999999990;"></div>'
  54. + '<div style="position: fixed;top: 50%;left: 50%;transform: translateX(-50%) translateY(-50%);z-index: 999999999999990;max-width: 360px;">'
  55. + '<div>'
  56. + '<img style="width: 90vw;max-width: 360px;display: block;" src="/antiRes/images/verify_logo.png">'
  57. + '</div>'
  58. + '<div style="border: #F5F5F5 solid 1px;margin: auto;width: 90vw;max-width: 360px;background-color: #FFFFFF;box-shadow: 1px 1px 1px 1px grey;padding: 10pt;display: flex;flex-direction: column;">'
  59. + '<div style="margin-bottom:8pt"><div>请在下图依次点击:<span>' + text + '</span></div></div>'
  60. + '<div style="position:relative;width:100%">'
  61. + '<img id="antiimg" onclick="antiAdd(event,this);" src="data:image/png;base64,' + imgdata + '" style="width:100%">'
  62. + '<input type="hidden" id="antivalue" value="">'
  63. + '</div>'
  64. + '<div style="margin-top: 1vh;display: flex;flex-direction: row;justify-content: space-between;">'
  65. + '<img style="argin-left: 8pt;width: 25pt;height: 25pt;float: left;cursor: hand;" onclick="antiReload()" src="/antiRes/images/flush.png" \>'
  66. + '<div><button style="background-color: #24C0D7;text-align: center;vertical-align: middle;touch-action: manipulation;cursor: pointer;background-image: none;border: 1px solid transparent;white-space: nowrap;padding: 8px 12px;font-size: 14px;line-height: 1.42857143;border-radius: 4px;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;color: #FFFFFF;position: relative;outline-width: 0px;box-shadow: none !important;" onclick="antiReload(1);">确定</button></div>'
  67. + '</div>'
  68. + '</div>'
  69. + '</div>'
  70. if (document.querySelector("#antiVerify") == null) {
  71. var wrap = document.createElement("div");
  72. wrap.id = "antiVerify";
  73. wrap.innerHTML = htmlcode;
  74. var insertParent = document.body
  75. if (document.querySelector("#supersearchPage") && document.querySelector("#supersearchPage").className !== "hidden") {//搜索首页验证码要在搜索页内
  76. insertParent = document.querySelector("#supersearchPage")
  77. } else if (document.querySelector("#entsearchPage") && document.querySelector("#entsearchPage").className !== "hidden") {
  78. insertParent = document.querySelector("#entsearchPage")
  79. }
  80. insertParent.appendChild(wrap);
  81. } else {
  82. document.querySelector("#antiVerify").innerHTML = htmlcode;
  83. }
  84. document.querySelector("#antiVerify div").addEventListener('touchmove', function (event) {
  85. event.preventDefault();
  86. })
  87. }
  88. function antiAdd(event, obj) {
  89. if (obj.parentNode.querySelectorAll(".imgs").length < 3) {
  90. var offsetX = event.clientX - obj.getBoundingClientRect().left;
  91. var offsetY = event.clientY - obj.getBoundingClientRect().top;
  92. var offx = parseInt(offsetX);
  93. var offy = parseInt(offsetY);
  94. var icon = "<img onclick='antiRemove(this)' class='imgs' src='/antiRes/images/hoverclick.png' "
  95. + "style='position:absolute;top:" + (offsetY - 8) + "px;left:" + (offsetX - 8) + "px;' offx=" + offx + " offy=" + offy + " />";
  96. obj.parentNode.innerHTML += icon;
  97. document.querySelector("#antivalue").value += (";" + offx + "," + offy)
  98. }
  99. }
  100. function antiRemove(obj) {
  101. var offx = obj.getAttribute("offx");
  102. var offy = obj.getAttribute("offy");
  103. document.querySelector("#antivalue").value = document.querySelector("#antivalue").value.replace((";" + offx + "," + offy), "");
  104. obj.parentNode.removeChild(obj);
  105. }