Special statement

This article is a series by Tomek Sułkowski published on Medium. According to the author revealed a total of 24 articles, updated until December 24, the copyright of the original author.

The author recommended our Chinese translation on Twitter, screenshot at the end

The translator had already communicated with the author before the translation to get permission to translate the whole series. In order not to disturb your reading, the record of authorization is here

The body of the

In the 24 days leading up to the holidays, I will be publishing a series of short articles on how to use development tools in a more interesting way. Yesterday we looked at the dark magic of the DevTools Workspace. Today play with Snippets:

59. Snippets

Sometimes I use JavaScript as an automated tool to work with third party websites and applications.

For example, I want to see how many people applaud on all my media posts. Medium doesn’t provide such totals, so I put together this little script:

? ('td:last-child .sortableTable-number') .map(el => parseInt(el.innerText)) .reduce((total, value) => total + value);Copy the code

When I open the status page and type this script into Console, it will return this value:

Even though it doesn’t take me much effort to write this script, I only run it once in a while, so it’s annoying for me to have to memorize one:

That’s where Snippets come in: it’s a way of letting you store JavaScript code in DevTools so you can reuse it later.

To create a Snippet go to Sources, select Snippets in the navigation bar, click “New Snippet”, enter your code, save, and you’re done! You can run it by right-clicking the menu or by [CTRL] + [Enter] shortcuts:

60.Run snippets from wherever(Run code blocks from other sources)

Once you’ve set up a nice set of code blocks, you don’t even have to visit Sources to run them. The quickest way, as we’ve discovered several times this week, is to use Command Menu. If you type! In its input box, you can select your code block by name

That’s all for today’s sharing

Routine: If you learn something new from this

→ Follow me on Twitter: Tomek Sułkowski

Other series

Other articles in this series will be translated soon, with links posted here.

  • Day 1: ‘$’ in the Console
  • Tips you might not know about Chrome debugging tools Day 2: Copying & Saving
  • Chrome debugging tools you didn’t know about
  • The Chrome debugging tool has a few tricks you don’t know about.
  • Day 5: Console log, puzzling case
  • You don’t know the Command menu for Chrome
  • 7. Fun tips you didn’t know about the Chrome Debugging Tool Consle
  • Chrome’s Color picker is a Color picker that you don’t know about.
  • Day 9: Time console
  • Custom Formatters are custom formatters for Chrome.
  • Today: Style Editors continued
  • Tips you don’t know about the Chrome Debug Tool Day 12: Ninja Log Print! (the ninja logs)
  • Chrome debugging Tool tips you didn’t know about
  • Chrome Debugging Tool tips you didn’t know About day 14: Other shortcuts
  • Chrome debugger tips you didn’t know about
  • Tips you don’t know about Chrome debugging Tools 16: Breakpoints
  • Day 17: Farewell to Console
  • What you Didn’t know about Chrome Debug Tools
  • Chrome debug tool tips you don’t know
  • Tips you didn’t know about Chrome debugging tools Day 20: The dark arts of Workspace
  • Tips you Don’t Know about Chrome Debugging Tools Day 21: Snippets
  • Chrome Debugging Tool tips you didn’t know
  • Chrome debug Tool tips you don’t know
  • Day 24: The last day, New Year’s Day, is awesome

Write in the last

If you are sure of my translation, you can also pay attention to my wave oh ~ incidentally my open source project, for a wave of star→ see here, beautiful blog system

The author recommended our Chinese translation on Twitter