寫了油猴搜題腳本


  1 // ==UserScript==
  2 // @name 學習通手動搜題
  3 // @description 可以手動輸入關鍵詞搜題,方便有效,關鍵字可以是開頭的幾個字,或者關鍵的幾個詞語.[tip:面板可以拖拽移動位置哦]
  4 // @namespace dyh
  5 // @version 0.0.0.1
  6 // @match *://*/work/doHomeWorkNew?*
  7 // @match *://*/exam/test/reVersionPaperPreview*
  8 // @match *://*/exam/test/reVersionTestStartNew*
  9 // @match *://*.zhihuishu.com/*
 10 // @require http://code.jquery.com/jquery-3.5.1.js
 11 // @grant GM_xmlhttpRequest
 12 // ==/UserScript==
 13 
 14 (function () {
 15     'use strict';
 16 
 17     $(".edui-editor").css("z-index","600");
 18 
 19     /*****************************繪制界面****************************************/
 20     $("body").append("<div id=\"dyh_searchbyhand\" style=\"width:164px;position:fixed;top:100px;right:50px;border:1px coral dashed;z-index:999;box-sizing:content-box;\"></div>");
 21     $("#dyh_searchbyhand").html("<form id=\"dyh_form\"></form>");
 22     $("#dyh_form").html("<input id=\"dyh_text\" type=\"text\" placeholder=\"輸入問題的關鍵字/回車\" autocomplete=\"off\" autofocus=\"true\" style=\"width:160px;\"><br>");
 23     $("#dyh_form").append("Question:<p id=\"dyh_Q\" style=\"word-wrap: break-word;\"></p>");
 24     $("#dyh_form").append("Answer:<p id=\"dyh_A\" style=\"word-wrap: break-word;\"></p>");
 25     movePanel("#dyh_searchbyhand");
 26 
 27     /******************************查詢數據****************************************/
 28     $("#dyh_form").submit(function(){
 29         findAnswer();
 30         return false;
 31     });
 32 
 33     function decodeUnicode(str) {
 34         str = str.replace(/\\/g, "%");
 35         return unescape(str);
 36     }
 37 
 38     function findAnswer() {
 39         var value = $("#dyh_text").val();
 40         GM_xmlhttpRequest({
 41             method: 'GET',
 42             url: "http://????????(不公開接口了)/chati?q=" + value,
 43             onload: function (res) {
 44                 var data = res.responseText;
 45                 console.log(data);
 46                 var question = data.match(/question\".\"(.+)?\",/)[1];
 47                 var answer = data.match(/answer\".\"(.+)?\"/)[1];
 48 
 49                 $("#dyh_text").val("");
 50                 $("#dyh_Q").text(decodeUnicode(question));
 51                 $("#dyh_A").text(decodeUnicode(answer));
 52             },
 53             onerror: function (err) {
 54                 alert("服務器連接失敗");
 55             }
 56         });
 57     }
 58 
 59     function movePanel(obj,callback){
 60         var _evenObj=null;  // 觸發事件的對象
 61         var _move=false;       // 移動標識
 62         var _x,_y;  //鼠標離控件左上角的相對位置
 63 
 64         $(obj).bind({
 65             mousedown:function(e){
 66                 _evenObj=e.currentTarget;            // 當前觸發的作用對象
 67                 _move=true;
 68                 var cx=$(_evenObj).position().left; // 獲取父類的X軸偏移量,如果相對屏幕的偏移量,請把position()改為offset();
 69                 var cy=$(_evenObj).position().top;  // 獲取父類的Y軸偏移量 , 同上
 70                 _x=e.pageX-cx;
 71                 _y=e.pageY-cy;
 72             },
 73             mouseup:function(){
 74                 //判斷方法是否存在
 75                 if (typeof callback != 'undefined' && callback instanceof Function) {
 76                     $ext=$.extend({},$(obj));         // 為obj對象擴展回調方法
 77                     $ext.addMethod=callback;
 78                     $ext.addMethod();
 79                 }
 80             }
 81         });
 82         $(document).bind({
 83             mousemove:function(e){
 84                 if(e.which==1){                         // 判斷是否是左鍵按下
 85                     if(_evenObj!=null){             // 判斷觸發事件的對象是否為空
 86                         if(_move){
 87                             var x=e.pageX-_x;
 88                             var y=e.pageY-_y;
 89                             $(_evenObj).css({
 90                                 top:y,
 91                                 left:x
 92                             });
 93                         }
 94                     }
 95                 }
 96             },
 97             mouseup:function(){
 98                 _evenObj=null;
 99                 _move=false;
100             }
101         });
102     }
103 })();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM