Custom Javascript with MDS Sharepoint 2013

Minimal Download Strategy (MDS) is a new technology in SharePoint 2013 that reduces the amount of data that the browser has to download when users navigate from one page to another in a SharePoint site. When users browse an MDS-enabled site, the client processes only the differences (or delta) between the current page and the requested page.

But when you need a custom javascript to run everytime you navigate to another page, it's not execute your javascript if you only put it on master page when page load, your custom code just only run once time. By some research on the internet I found one blog have describe about this and use in my code, it work perfect, everytime I navigate to another link it call my function.

Here is the code, you can put this code in the master page when page loaded:

Why I need to call my script everytime navigate to another page? I have an requirement need me call custom script only for Documents library, so everytime user navigate to another link my code will be checked if this link has a Forms in the url, I will get the document name and get the information of this document to archive the requirement.

Notes: This blog just is a note for reference if needed, and I hope someone have the similar can help.
I know my english is bad :)