WARNING!!! This solution provided as is (with no warranty of any kind). Be careful because the described operations rather dangerous and possibly can brick your device. Author is not responsible for your device damage.
IMPORTANT: Usage of this method will affect the state of the "Custom BIN down" counter in your device. This means that you may have problems with official warranty.
Step 1. Getting software
1. Download Odin 3.0.7 here
2. Download CWM-based recovery here
3. Download update package for rooting here (downloaded from here Thanks to Phil3759)
4. Install Samsung drivers\kies this page (This link is for S5301 but it works ok for S5310 in current case)
P.S. Sorry for ugly file storage solution - google drive. If it will open the zip archive just click "File" menu and click "Download" (or use Ctrl+S combo).
Step 2. Flash the updates
1. Switch off the device. Hold "volume down"+"home" buttons and press power button. When device switch on release the power button but continue to hold volume down and home until Download mode warning appear. Plug in the USB cable and press volume up button to continue. The device will load in ODIN download mode.
2. Run ODIN 3.0.7. Don't change any setting (checkboxes ) - leave them in default state. Your device should appear in "ID:COM" part of the screen as serial device (i.e. "COM38") - if not check if your USB port is functional and Samsung drivers installed correctly.
3. Click on PDA button and chose CWM recovery file saved during step 1.2. Don't rename or decompress the file - otherwise it will not work.
Wait until ODIN decompress the package and check the checksums. After it just press START button and wait until the process is over.
4. Copy update package for rooting on SD card and put the card in device's slot.
5. Switch off your device again. Hold "volume up"+"home" buttons and press power button to switch on. Don't release volume up and home until the recovery loaded. Using volume up and volume down buttons navigate to menu item "apply update from external card" and press power button to commit operation. Then navigate to Root_Superuser_3.1.3......zip file and press power button again.
Notice: you can use sideload feature instead of using SD card: in recovery run "update from sideload" and on your computer run the following command:
adb sideload rooting_package_filename
6. Done. Your device should be rooted now. You can check it with various free programs like Root Checker available at Google Play.