Home > front end >  Newcomer, writing scripts run into problems, and bosses
Newcomer, writing scripts run into problems, and bosses

Time:09-21

Recently taught himself js foundation is not solid, write a script, tencent classroom automatic sign-in to achieve the user to enter the time and the number of times to automatically sign in, the value of the idea is to get the user first and then calls the function, the function of the timer would clear first and then the new invocation timer with new value,
//==UserScript==
//@ automatic sign-in name tencent class
//@ namespace http://tampermonkey.net/
//@ version 0.1
//@ description tencent class automatic check-in script, customizable check-in times and each time interval,
//@ author olivier to
//@ match https://ke.qq.com/webcourse/index.html *
//@ grant unsafeWindow
//==/UserScript==
//the default frequency and time
Var ciShu=2, denDai=10;
var d=new Date();
Var mainD;
Var HTML=(
'& lt; Div style="border: 2 px dashed RGB (0, 85, 68); Width: 330 px; position: fixed; top: 0; left: 0; Z - index: 99999; Background - color: rgba (70, 196, 38, 0.6); Overflow - x: auto;"> + '
'& lt; Span style="font - size: medium;"> + '
'& lt; Div id="yunXin" style="font - size: medium;"> The script in the normal operation of the...
+ '
'& lt; Input type="text" id="time" style="margin - right: 10 px; Width: 300 px;" Placeholder="input each time interval, the default for 10 seconds" & gt; + '
'& lt; Input type="text" id="ciShu" style="margin - right: 10 px; Width: 300 px;" Placeholder="input the number of total need to sign in, the default 2 times" & gt; + '
'& lt; The button style="margin - right: for 10 px;" The onclick="ciShu=parseFloat (document. GetElementById (\ 'ciShu \'). The value). DenDai=parseFloat (document. GetElementById (\ 'time \'), value); The main ();"> Change the Settings & lt;/button> + '
'& lt; Div style="Max - height: 300 px; Overflow - y: auto;"> + '
'& lt; The table border="1" style="font, size: 12 px;"> + '
'& lt; Thead> + '
'& lt; Tr> + '
'& lt; Th style="width: 30 px; Min - width: 100 px; font-weight: bold; The text - align: center;"> Type & lt;/th> + '
'& lt; Th style="width: 60%; Min - width: 100 px; font-weight: bold; The text - align: center;"> Time & lt;/th> + '
'& lt; Th style="min - width: 100 px; font-weight: bold; The text - align: center;"> Results & lt;/th> + '
'& lt;/tr> + '
'& lt;/thead> + '
'& lt; Tbody id="jieGuoFanKui" & gt; + '
'& lt;/tbody> + '
'& lt;/table> + '
'& lt;/div> + '
'& lt;/div> '
);
//set up live div object
Var addH=document. GetElementById (" react - body ");
//create a div to hold the HTML
Var Element=document. The createElement method (" div ");
//binding element
AddH. The appendChild (Element);
//add elements
Element. The innerHTML=HTML;
//-- -- -- -- -- -- -- -- -- tencent class sign in function -- -- -- -- -- -- -- -- --
The function qianDaoJiaoBen () {
Var qianDaoBtn=document. GetElementsByClassName (s - "BTN s - BTN - primary s - BTN - m");
If ((qianDaoBtn length & gt; 0) & amp; & (ciShu & gt; {0))
For (var I of qianDaoBtn) {
If (i.i nnerHTML=='check-in') {
I.c lick ();
TianJia ();
CiShu -=1};
If (i.i nnerHTML=='sure') {i.c lick (); break; }; };
{} else if (ciShu==0)
ClearInterval (mainD); }; }
//-- -- -- -- -- -- -- -- -- add sign in the result function -- -- -- -- -- -- -- -- -- -- -- -- --
The function tianJia () {
Var jieGuoY=(
'& lt; Tr> + '
'& lt; Td colspan="1" & gt; + '
'sign in' +
'& lt;/td> + '
'& lt; Td colspan="1" & gt; '+ String (d.g etHours ()) +', '+ String (d.g etMinutes ()) +', '+ String (d.g etSeconds ()) +' & lt;/td> + '
'& lt; Td colspan="1" & gt; + '
'success' +
'& lt;/td> + '
'& lt;/tr> ');
Document. The getElementById (' jieGuoFanKui). InnerHTML=jieGuoY; };
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- the main -- -- -- -- -- -- -- -- -- -- -- -- -- --
The function main () {
//clean up timer
ClearInterval (mainD);
//to call
MainD=setInterval (qianDaoJiaoBen, denDai * 1000);
If (ciShu==0) {document. GetElementById (' yunXin). InnerHTML='all check-in has been finished, shut script; }}
The main ();