Playing with JavaScript, jQuery and Regex

arenabg-clean-torrent-names-format-code-image

Have you ever been annoyed by something while surfing the internet? I was annoyed by something yesterday so I decided to change my mood and to practice my “skills” as developer in JavaScript, hah. The thing that have annoyed me was ArenaBG’s links and their title formatting. And what I’m talking about? Well, their torrent names have dots, dashes and underscores, and in this way titles are difficult to read. Here you can see before and after

arenabg-non-formatted-names arenabg-formatted-names

To manipulate the text into the browser I’ve used scripts called userscripts. Userscripts are tiny bits of code written in JavaScript that are injected into the browser page as a normal JavaScript, so I’ve written a simple userscript code with jQuery.  I used regular expressions (called regex) to match “.“, “_” and “” chars into the string and to replace it with a blank space (interval) ”  “.

The idea is simple and the result is satisfying.

Original string:

Formatted string:

 

Note that to use the script you need to rename it to “name.user.js” (the name has to end with .user.js) for Google Chrome. To install it into Chrome, just drag it from your computer and drop it into the browser. For other browsers including Chrome you can use the following extensions:

  • Violentmonkey for Opera
  • Tampermonkey for Google Chrome
  • Greasemonkey for Mozilla Firefox

The source code of the userscript:

 

The source in my Github here.

beBoss

Живота е като терена или ставаш силен, блокираш, сваляш и оцеляваш или се отказваш, падаш и си заминаваш ! beBoss™