答题活动

答题活动工具

目前为 2019-12-02 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 答题活动
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description 答题活动工具
  6. // @author You
  7. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  8. // @require https://cdn.jsdelivr.net/npm/vue
  9. // @match https://zhidao.baidu.com/mobile/replyseason/teampage?*
  10. // ==/UserScript==
  11.  
  12. $(function () {
  13. fetch(`https://zhidao.baidu.com/metis/team/view`, {
  14. method: "get",
  15. headers: {
  16. Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
  17. 'Accept-Encoding': 'gzip, deflate, br',
  18. 'Accept-Language': 'zh-CN,zh;q=0.9',
  19. 'Cache-Control': 'no-cache',
  20. Connection: 'keep-alive',
  21. Host: 'zhidao.baidu.com',
  22. Pragma: 'no-cache',
  23. 'Upgrade-Insecure-Requests': 1,
  24. 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
  25. },
  26. }).then(function (response) {
  27. if (response.status == 200) {
  28. return response;
  29. }
  30. }).then(function (data) {
  31. return data.arrayBuffer();
  32. }).then(function (result) {
  33. let body = new TextDecoder('gbk').decode(result);
  34. let teamInfo = jQuery(body).find(".home-team-qq-notice").text();
  35. let teamName = teamInfo.match(`您已加入(.*)认证团`)[1];
  36. if (![`知道合伙人精英团`, `冠军团`, `专业知识团`, `猛虎团`, `合伙人-答题小能手`].includes(teamName)) {
  37. return;
  38. }
  39. init();
  40. }).catch(function (e) {
  41. console.error(e)
  42. });
  43.  
  44. function init() {
  45.  
  46. let addSearchButton = () => {
  47. let items = $(".question-item").toArray();
  48. for (let item of items) {
  49. let question_title = encodeURIComponent($(item).find(".question-item-title-wp").text());
  50. if ($(item).find(".my-append").length) {
  51. continue;
  52. }
  53. $(item).append(
  54. `<p class="my-append">
  55. <button class="my-search" data-type="0">搜百度</button>&nbsp;
  56. <button class="my-search" data-type="1">搜知乎</button>&nbsp;
  57. <button class="my-search" data-type="2">搜谷歌</button>&nbsp;
  58. <button class="my-search" data-type="3">搜微信</button>
  59. <button class="my-search" data-type="4">搜头条</button>
  60. <button class="my-search" data-type="5">搜微博</button></span>
  61. </p>`
  62. );
  63. }
  64. };
  65.  
  66. // 简单的节流函数
  67. function throttle(func, wait, mustRun) {
  68. var timeout,
  69. startTime = new Date();
  70.  
  71. return function() {
  72. var context = this,
  73. args = arguments,
  74. curTime = new Date();
  75.  
  76. clearTimeout(timeout);
  77. // 如果达到了规定的触发时间间隔,触发 handler
  78. if (curTime - startTime >= mustRun) {
  79. func.apply(context, args);
  80. startTime = curTime;
  81. // 没达到触发间隔,重新设定定时器
  82. } else {
  83. timeout = setTimeout(func, wait);
  84. }
  85. };
  86. };
  87.  
  88. // 实际想绑定在 scroll 事件上的 handler
  89. function realFunc() {
  90. //判断是否滚动到页面最底部
  91. console.log(1);
  92. addSearchButton();
  93. }
  94.  
  95. // 采用了节流函数
  96. $(window).scroll(throttle(realFunc, 500, 1000))
  97.  
  98. $(document).on('click', ".my-search", function () {
  99. console.log($(this))
  100. let question_title = encodeURIComponent($(this).parent().parent().find(".question-item-title-wp").text());
  101.  
  102. let url = [
  103. `https://www.baidu.com/s?ie=UTF-8&wd=${question_title}`,
  104. `https://www.zhihu.com/search?type=content&q=${question_title}`,
  105. `https://www.google.com/search?q=${question_title}`,
  106. `https://weixin.sogou.com/weixin?type=2&query=${question_title}`,
  107. `https://www.toutiao.com/search/?keyword=${question_title}`,
  108. `https://s.weibo.com/article?q=${question_title}&Refer=weibo_article`,
  109. ][$(this).data("type")];
  110. window.open(url);
  111. });
  112. }
  113. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址