<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hieu</title>
    <description>The latest articles on DEV Community by Hieu (@phuchieu).</description>
    <link>https://dev.to/phuchieu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F179579%2F36b48dc2-8d2d-42cc-80be-93bd7bf11d78.png</url>
      <title>DEV Community: Hieu</title>
      <link>https://dev.to/phuchieu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/phuchieu"/>
    <language>en</language>
    <item>
      <title>How to inspect the tooltips</title>
      <dc:creator>Hieu</dc:creator>
      <pubDate>Sun, 25 Oct 2020 08:38:25 +0000</pubDate>
      <link>https://dev.to/phuchieu/how-debug-inspect-tooltip-2e5c</link>
      <guid>https://dev.to/phuchieu/how-debug-inspect-tooltip-2e5c</guid>
      <description>&lt;p&gt;There are some cases when we suffering the web and see something with interesting style, amazing animation, you’re curious and want to know to how the web’s author implement that, especially if you’re a web designer. So the easiest way to answer that question is using inspect tool to inspect that element. But the problem is whenever we run inspect element tool, the style we want to inspect is disappear immediately regardless of how much effort. For example: tooltips, popups or something happen very quickly.&lt;/p&gt;

&lt;p&gt;The example below show you how difficult to inspect tooltip content element that will disappear very quickly&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7605x4iycbhhus8oq013.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7605x4iycbhhus8oq013.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make our life become easier, in this blog I gonna show you 2 ways how to force the web stop immediately in order to use inspect element tool to inspect something only visible in a short period of time. Both of them base on the idea that we put a break point and force the website run into that breakpoint, by doing that we can force it stop their behavior and we can do everything wen want &lt;/p&gt;

&lt;h1&gt;
  
  
  The first way is using Event Listener Breakpoint
&lt;/h1&gt;

&lt;p&gt;To use Event listener breakpoint, we just simple open chrome developer tool (by pressing F12), navigate to “Sources” tab, expand “Event Listener Breakpoints” and check “contextmenu” under “Mouse” event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fndu7dlcxqabbdxx0auo2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fndu7dlcxqabbdxx0auo2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By doing this, we force the application jump right to the breakpoint whenever we trigger a right click event, stop their functionalities and let’s us do whatever we want while the application is in “sleep mode”. The reason we choose context menu rather than other events due to it’s rarely used, so we can make sure our breakpoint event can easily trigger and unique&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff69d41p7nj3jdoeh9kt5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff69d41p7nj3jdoeh9kt5.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But this way also have one drawback that it need one trigger to force stop the application which is not suitable in some case. SO to overcome that problem we need to find another way that can force application jump to breakpoint automatically, without require any more event trigger. This lead us to the second solution is setTimeout&lt;/p&gt;

&lt;h1&gt;
  
  
  We also can use setTimeout to make the breakpoint
&lt;/h1&gt;

&lt;p&gt;Yes you don’t see wrong, setTimeout can be able to used to put the breakpoint. setTimeout is very handy in some cases it’s impossible to trigger another event to put the breakpoint due to website’s behavior. Let’s me show you how to do that&lt;/p&gt;

&lt;p&gt;Firstly, open chrome developer tool, navigate to console tab and execute this line of code&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Stop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="s2"&gt;```

After executing that code, wait 5 more seconds to see a log message. when a log message is printed out, we click on the debugger at the rightsize to open the code that print the message. It will bring us to the source tab and show on the setTimeout code we have just executed. Put the breakpoint at line 2.

And now whenever we want to inspect something, just return that piece of code, make sure the element we want to inspect on the view, wait 5 seconds and the application will automatically run in sleep mode without require trigger any extra event

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2f05gg65rhg1tf5tt6yl.gif)
#Final word

Hope that 2 ways above I have just show you will be on your toolbox kit. When we want to inspect something in the view which only visible on the view in very short period of time or simply when we want to stop the application, at least we know more way to do that.




&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>debug</category>
      <category>breakpoint</category>
    </item>
    <item>
      <title>Cheating 10fastfingers</title>
      <dc:creator>Hieu</dc:creator>
      <pubDate>Sat, 03 Aug 2019 04:00:58 +0000</pubDate>
      <link>https://dev.to/phuchieu/cheating-10fastfingers-54j1</link>
      <guid>https://dev.to/phuchieu/cheating-10fastfingers-54j1</guid>
      <description>&lt;p&gt;&lt;a href="//10fastfingers.com"&gt;10fastfingers.com&lt;/a&gt; is an awesome application let you play typing game with your friends. Nothing is funnier than beating your friends by your extremely fast typing. But if you can't type fast, a little cheating is harmless. Moreover, learning the new thing while you make a cheat is a wonderful way to learn new knowledge. Now let start&lt;/p&gt;

&lt;h1&gt;
  
  
  Trying out &lt;a href="//10fastfingers.com"&gt;10fastfingers.com&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;At the first step, we must access &lt;a href="//10fastfingers.com"&gt;10fastfingers.com&lt;/a&gt; and play around with it. The rule of this game is very simple, we have to type as fast and correct as possible to defeat your friends. Who has the highest score will win the game. If you’re like me can’t type fast, we need a little cheat here. Why don’t let the computer type for us? Who can defeat the speed of the computer?&lt;/p&gt;

&lt;p&gt;To cheat that game, we need 2 essential things: how to get or retrieve the text for typing and how to send that text to the input field&lt;/p&gt;

&lt;h1&gt;
  
  
  Retrieve the text for typing
&lt;/h1&gt;

&lt;p&gt;By using our best friend “Developer tool”, we can inspect the element which is highlighted for the current word like&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2F1.jpeg%3Fw%3D1518%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2F1.jpeg%3Fw%3D1518%26ssl%3D1" alt="Code"&gt;&lt;/a&gt;&lt;br&gt;
We can easily detect that the text “children” which we want to retrieve is put inside a div element with a class name &lt;strong&gt;highlight&lt;/strong&gt;. To get that value, just easily write&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.highlight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;try to run this in console window:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fimage-17.png%3Fw%3D1052%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fimage-17.png%3Fw%3D1052%26ssl%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have finished retrieving the word job. Now move on to step 2&lt;/p&gt;

&lt;h1&gt;
  
  
  Sending the text to the input field
&lt;/h1&gt;

&lt;p&gt;Besides sending the retrieved text to input, we also need to fire and InputEvent in order to let the system to recognize the text and continue with the following texts. Simply like this&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.highlight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inputEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputEvent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Try to run this block of code in the console window to see. If you’re lucky, you will get the error message instead of the input is auto-filled.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fimage-19.png%3Fw%3D1066%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fimage-19.png%3Fw%3D1066%26ssl%3D1" alt="Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why does this happen? Because you’re unlucky. I’m just kidding :), the problem is because we’re trying to access the &lt;em&gt;highlight&lt;/em&gt; and &lt;em&gt;input&lt;/em&gt; element which is not the same frame we run the code. Our code at the moment running at “top” frame, but &lt;em&gt;highlight&lt;/em&gt; and &lt;em&gt;input&lt;/em&gt; are rendered under other frame named &lt;em&gt;10ff.net&lt;/em&gt;. To fix this problem just simply select &lt;em&gt;10ff.net&lt;/em&gt; as a context in the console window and try one more time&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating.gif%3Fzoom%3D2%26fit%3D759%252C331%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi0.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating.gif%3Fzoom%3D2%26fit%3D759%252C331%26ssl%3D1"&gt;&lt;/a&gt;&lt;br&gt;
Yeah, it works. But how can we defeat other people with we need to paste the code and enter so many times, this process is even slower than your typing, we need to make this code run continuously.&lt;/p&gt;

&lt;h1&gt;
  
  
  Run the code continuously
&lt;/h1&gt;

&lt;p&gt;Beside run the code continuously, we also need to wait a few moments between each turn to let the system render the next word for us. We can use setTimeout at different time. Something like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.highlight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inputEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//Each turn is 100 miliseconds apart &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating-2.gif%3Fzoom%3D2%26fit%3D759%252C396%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating-2.gif%3Fzoom%3D2%26fit%3D759%252C396%26ssl%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We won !! But we still have a problem that we set the number of turns we want to run the code at the beginning, in this case, we set 100 times. In the beginning, we create 100 timeout functions, which is 100 milliseconds apart this way works well. However it’s not good enough because in some cases, the number of words is different from 100, so our code may don’t run enough time or run more times than we need. So we need to determine exactly the number of the turn we want to run during the execution time rather than in the beginning time. How can we do that? promises our answer. The promise in javascript give 2 possibilities to run the next turn: resolve lets us run the next turn or reject lets us break the loop. Let's convert our code to using Promise&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.highlight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.highlight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;inputEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;dispatchEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inputEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enjoy your champion!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating-3.gif%3Fzoom%3D2%26fit%3D759%252C439%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi2.wp.com%2Ffrontend.cloudaccess.host%2Fwp-content%2Fuploads%2F2019%2F07%2Fcheating-3.gif%3Fzoom%3D2%26fit%3D759%252C439%26ssl%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrap up
&lt;/h1&gt;

&lt;p&gt;In this tutorial, we have just learned the way to inspect element, retrieve the data as well as the way to trigger an input event to simulate the user action. Moreover, we also learned how to create a loop which has the gap between each turn by using Promise comes with await. For deeper learning about Promise, you can visit &lt;a href="https://frontend.cloudaccess.host/promise-in-javascript" rel="noopener noreferrer"&gt;Promise&lt;/a&gt; and &lt;a href="https://frontend.cloudaccess.host/await-and-async-%e2%80%8bin-javascript" rel="noopener noreferrer"&gt;Await and async&lt;/a&gt;. Please take your time to do this cheating by yourself and learn the new thing. See you soon in the next post&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>CSS Display property</title>
      <dc:creator>Hieu</dc:creator>
      <pubDate>Sat, 15 Jun 2019 08:48:38 +0000</pubDate>
      <link>https://dev.to/phuchieu/css-display-property-4nai</link>
      <guid>https://dev.to/phuchieu/css-display-property-4nai</guid>
      <description>&lt;p&gt;In &lt;a href="https://frontend.cloudaccess.host/css-property-position/"&gt;this post&lt;/a&gt;, we have talked about the most important css property: &lt;code&gt;positon&lt;/code&gt;. Besides that, it’ll be a big mistake if we forget to mention about 1 more css property which is also very important in our frontend development, that is css &lt;code&gt;display&lt;/code&gt;. Let’s come with me and talk about it&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the purpose of css display
&lt;/h1&gt;

&lt;p&gt;CSS display will define how your HTML element takes place in the view. You want your element takes the full width of the parent element, or adapt the width of the content inside, or even with custom size for your element, CSS display all you want to use in that scenarios.&lt;/p&gt;

&lt;h1&gt;
  
  
  What are the available value for css display
&lt;/h1&gt;

&lt;p&gt;There are many available values come up with css display such as: &lt;code&gt;block, inline, inline-block, flex, table ...&lt;/code&gt;.In this post, we are going to mainly focus on 3 most important values: &lt;code&gt;block, inline and inline-block&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;display: block&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;With css &lt;code&gt;display:block&lt;/code&gt; will make your element take the full width of the parent element doesn’t matter how wide the content inside. It’s usually used when we want to make our element stand alone, no other element sit next to the right or next to the left of it. In consequence, this css will make our element more distinguishable from others as well as more noticeable. For that reason, &lt;code&gt;display:block&lt;/code&gt; is the default value for the following element:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;br&gt;
&amp;lt;h1&amp;gt; – &amp;lt;h6&amp;gt;&lt;br&gt;
&amp;lt;p&amp;gt;&lt;br&gt;
&amp;lt;form&amp;gt;&lt;br&gt;
&amp;lt;header&amp;gt;&lt;br&gt;
&amp;lt;footer&amp;gt;&lt;br&gt;
&amp;lt;section&amp;gt;&lt;/code&gt;&lt;br&gt;
Example&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phuchieuct93abc/embed/NZxaae?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;As you can see in the above sample. Every block element is displayed under the previous sibling element, not on the left, not on the right, only on the bottom.&lt;/p&gt;

&lt;p&gt;One interesting thing here is the div element. Even it’s defined with a custom width (not full parent width), it’s still displayed in the whole line, because the browser will add margin for block element if it comes up with the custom size css to make sure no one can sit in the same line with block element.&lt;/p&gt;

&lt;p&gt;Keep in mind that with block elements, css &lt;code&gt;margin-right&lt;/code&gt; has no effect. Except that, we’re free to custom the size block element by css width, height, margin-top, margin-bottom and margin-left.&lt;/p&gt;

&lt;p&gt;What should we do if we want to multiple elements sit in the same line? These scenarios, we will use &lt;code&gt;display:inline&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;display: inline&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Unlike &lt;code&gt;display:block&lt;/code&gt; makes one element stand alone in the whole line, &lt;code&gt;display:inline&lt;/code&gt; make us able to put multiple elements in the same line.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;display:block&lt;/code&gt; is the default value for the following element:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;span&amp;gt;&lt;br&gt;
&amp;lt;a&amp;gt;&lt;br&gt;
&amp;lt;img&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phuchieuct93abc/embed/OeMxar?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;However, &lt;code&gt;display:inline&lt;/code&gt; will ignore our custom size (by css width, height and margin). Inline elements always fit the size of the content inside, no more no less. Simply, you can’t change the size of the inline element except changing the size of the content inside. Only use &lt;code&gt;display:inline&lt;/code&gt; only when you’re sure that you want that element fit the content size and no custom size at all.&lt;/p&gt;

&lt;p&gt;What about if we want to put multiple elements in the same line with our own custom size? &lt;code&gt;display:inline-block&lt;/code&gt; comes to our hand&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;display: inline-block&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;display:inline-block&lt;/code&gt; is the combination of &lt;code&gt;display:inline&lt;/code&gt;(can put multiple elements in the same line)and &lt;code&gt;display:block&lt;/code&gt;(can change the size of element by css width, height, margin).&lt;/p&gt;

&lt;p&gt;Firstly, we can put multiple inline-block elements in the same line. Next, we can custom the size for every single element to make it matches our need. We can define the width, the height, margin for those elements freely.&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phuchieuct93abc/embed/GboQMx?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrap up
&lt;/h1&gt;

&lt;p&gt;Alongside with CSS position, display in one of the most important CSS property help us to develop attractive web applications. The only way to master css display we need to understand how it works and how to use it properly. &lt;br&gt;
Hope you learned something and see you in the next post. Don’t forget to put your comment below&lt;/p&gt;

&lt;p&gt;You can also visit my blog to read more interesting topics: &lt;a href="https://frontend.cloudaccess.host/css-display-property/"&gt;https://frontend.cloudaccess.host/css-display-property/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>layout</category>
    </item>
    <item>
      <title>Dark theme with CSS variable</title>
      <dc:creator>Hieu</dc:creator>
      <pubDate>Wed, 12 Jun 2019 15:21:05 +0000</pubDate>
      <link>https://dev.to/phuchieu/dark-theme-with-css-variable-1fjo</link>
      <guid>https://dev.to/phuchieu/dark-theme-with-css-variable-1fjo</guid>
      <description>&lt;p&gt;Nowadays, more and more applications and OS are going to adapt to the new trend: dark theme and web applications are not exceptions. Dark theme is not the necessary feature for the web application but it's nice to have. Giving your users more choice base on their preference always help your application more attractive. Today I gonna show you some way to apply the dark theme in your application.&lt;/p&gt;



&lt;h2&gt;Solution 1: Use css nested&lt;/h2&gt;

&lt;p&gt;Let imagine that your current web application only supports the light theme, and now you want to add a new feature that allows users to change the application's theme in runtime. So the easiest way to we defined a new class for dark theme, apply that class to the root element (&lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;). Because the application's theme must be consistent for the whole application so to make sure every element of our application follow the selected theme, we must set that class to root element.&lt;/p&gt;

&lt;p&gt;After we have a class for the dark theme, we will jump to customize the look &amp;amp; feel for every child inside. 2 most important CSS properties we need bear in mind is &lt;code&gt;color&lt;/code&gt;and &lt;code&gt;background-color&lt;/code&gt;. Beside that, we also need to take care of other CSS properties as well depend on your application's implementation. &lt;/p&gt;

&lt;p&gt;Something like this&lt;/p&gt;

&lt;pre class="wp-block-syntaxhighlighter-code"&gt;/* Default css for light theme */
body {
  background-color: white;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: all linear 1s;
}
.panel {
  background-color: lightblue;
}
label{
  color:#0d47a1;
}
/* Custom css for dark theme */
[data-theme=dark-theme] {
  background-color:gray ;
}
[data-theme=dark-theme] .panel {
  background-color: darkgray;
}
[data-theme=dark-theme] label {
  color: rgb(245,245,245);
}&lt;/pre&gt;

Live demo
&lt;iframe height="600" src="https://codepen.io/phuchieuct93abc/embed/QXwYzK/?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;



&lt;p&gt;This way works perfectly however, it still has one big drawback is we need to duplicate CSS code for every component we want to customize between light theme and dark theme. In the above sample, you can see that we need to redefined CSS for label and panel twice, even worse we also need to repeat &lt;code&gt;[data-theme=dark-theme]&lt;/code&gt; many times. To get rid of this disadvantage, I want to introduce you another approach to apply dark theme is using css variable.&lt;/p&gt;



&lt;h2&gt;Solution 2: CSS variable&lt;/h2&gt;



&lt;p&gt;The idea behind this solution is we will define some CSS values as a variable, and we define every element will reuse CSS variable instead of defined the new one. It means the value of that variable is flexible during runtime. By this way, we only need to defined customize CSS once (these CSS properties should depend on CSS variable), besides that we also need to define 2 sets of variables: one for dark theme and one for the light theme. This way is much simpler than the solution 1 with nested CSS.&lt;/p&gt;



&lt;p&gt;Let take a look on the CSS variable version of above example:&lt;/p&gt;



&lt;pre class="wp-block-syntaxhighlighter-code"&gt;/* Default css for light theme */
body {
  --backgroundColor: white;
  --panelBackgroundColor: lightblue;
  --labelColor: #0d47a1;
}
body[data-theme="dark-theme"] {
  --backgroundColor: gray;
  --panelBackgroundColor: darkgray;
  --labelColor: rgb(245, 245, 245);
}
body {
  background-color: var(--backgroundColor);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: all linear 1s;
}
.panel {
  background-color: var(--panelBackgroundColor);
}
label {
  color: var(--labelColor);
}
&lt;/pre&gt;

&lt;p&gt;Live demo:&lt;/p&gt;

&lt;p&gt;Live demo&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/phuchieuct93abc/embed/ZdYZpd/?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt; Final words&lt;/h2&gt;

&lt;p&gt;Hope that you learned something about CSS variable and willing to apply it in your next project, not only for theme changing but also for flexible web application. Let let us know your feeling in the comment section below and see you in the next post.&lt;/p&gt;

&lt;p&gt;You can also visit my blog to read more interesting topics: &lt;a href="https://frontend.cloudaccess.host/dark-theme-with-css-variable/"&gt;https://frontend.cloudaccess.host/dark-theme-with-css-variable/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
