Chrome is my little dinosaur "hanging open", and see how my body has let it die only one line of code

Website: www.dzyong.top

Micro-channel public number: Focus on the "front end Xiaoyuan", yes, every one push

As a developer, we used the most is the Chrome browser.

When there is no network open the browser will see the following interface.

When you press the spacebar key, suddenly found that it turned out to be a game.

As a programmer, I play it how Renshoudele neatly, if a body to die of it, it would mean that may have been happy to go.

That where to start it, it's essentially a web page, it certainly can not do without JS. If this game variable is set to global variables, then I can change the rules of the game by rewriting some of its functions, so as to achieve the purpose of hanging open.

He went ahead, F12 to open the console, take a look at what global variables.

Yeah my mom, 252, so much. But these are certainly not all of the game, mostly window comes with the original. So how to filter out related to the "little dinosaur" global variables it.

Access in the browser "about: blank", bout: blank Open a command browser is a blank page. Print what global variables in this page. We can see a total of 196. That is a total of 252-196 = 56 are "little dinosaur" of.

Although this approach can be found in the global variables we want, but if you want to go one by one, then, but doing it is quite cumbersome. Is there any way to print directly to a desired result yet.

Here you can use iframe, suppose we have a blank page embedded as an iframe to a "dinosaur" of the page, use iframe.contentWindow methods in HTML iframe object to the return of the document, and then use global variables to the entire page global variable filter out the iframe, then the rest is "little dinosaur" in the.

(function() {
    const kl = []
    const iframe = document.createElement('iframe')
    iframe.onload = function(){
        const iframeKeys = Object.keys(iframe.contentWindow)
        const windowKeys = Object.keys(window)
        windowKeys.forEach(function(key) {
            if(!(iframeKeys.includes(key))){
                kl.push(key)
            }
        })
        console.log(kl)
    }
    iframe.src = 'about:blank'
    document.body.appendChild(iframe)
})()

Output as follows:

The result is got, but why is it 58, is obviously calculated before 56 fishes. The iframe just put a blank page to give it a try.

Sure enough, two more than the window is contentWindow two variables, specifically what's not clear to me whether it will be here. Take a look at the rest of the global variables, these names can clearly see are related to the "little dinosaur", many of which are related to the canvas, this "little dinosaur" is also the canvas to draw.

These variables found what use is it, it is clear that both are some of the game's judgment, the operation of the function package. For example, should Runner is to make small dinosaur "run." So there has to be a game to determine whether the end of the function.

I see first is "GameOverPanel" global variable. I took it for a moment and look at the output of the contents of this function, it is not found to determine whether the end of the game function, the display should look like after the end of a game interface panel.

English translation is not good I went to Baidu for a moment did not know the word, to find the culprit checkForCollision.

 

This is quite obvious, there is no doubt certainly detect "little dinosaur" is a collision with an obstacle collision once the game is over. Also take a look at the contents of this function. It guarantees the right time.

The judge found the end of the game function, then it is simple, with a backhand empty function to overwrite the original content, it stands to reason that this will never be a collision is detected.

 

Let my "little dinosaur" running up and try, ha ha, it really was the "immortality" of "buff".

From then on it became the whole network the most "happy" a small dinosaur

 

Published 72 original articles · won praise 75 · views 70000 +

Guess you like

Origin blog.csdn.net/DengZY926/article/details/104924133