preface

As a front-end developer, sometimes business scenarios are impossible to simulate at hand speed, and old drivers sometimes roll over. So I specially write this article, hoping to be helpful to you.

Contents involved:

1. Chrome 2. Js code 3Copy the code

The first step

Open chrome and use Ctrl+ Shift + I to open developer tools, as shown in the following image.


The second step

As is shown in


The third step

As is shown in


Js script code

1. Here is the code on the website:

<body>
        <div class="box">
            <img class="img" src="image/pict.png" />
            <button class="btn" id='btn'</button> </div> <scripttype="text/javascript"< span style = "max-width: 100%; clear: both; min-height: 1emfunction(){
                console.log('Snap it up! ');
            };
        </script>
    </body>Copy the code

Every time you click the Snap console, the snap is successful! 2. Script code

/** * The simplest scripting code * version 1.0.1 */ btn.click(); // Trigger the button to execute the click event /** * useforThe script code that executes the buying cycle * version 1.0.2 * */for(var i=0; i<100; i++){ btn.click(); }Copy the code

As you can see from the script js code above, we can build scripts in Chrome and control their execution.



Juejin. Cn/post / 684490…


/** ** / btn.onclick=function(){
     throttle(function(){
        console.log('Snap it up! '); }, 500); }; /** * function throttling * @fn {function} callback * @time {number} time, milliseconds * * */function throttle(fn,time){
    if(throttle.id){
        clearTimeout(throttle.id);
    };
    throttle.id=setTimeout(function(){
        fn();
    },time||200);
}Copy the code

In this way we can filter out malicious loop trigger events. This function throttling method has also been unanimously recognized and promoted.

conclusion

In this way, we have not only learned to make simple JS scripts, but also learned a simple way to block JS scripts. To really write some useful JS scripts also need your own efforts! Want to shield malicious JS scripts, simple use of front-end technology is actually very difficult! This is dedicated to those who are trying to learn the front end and want to go further and further on the road of the front end. Bless you. You can order it if you feel good.