You could have prevented this to happen we you have used metamask extension which blocks phising sites,and other malicious websites.Do a lot of research so that you wont be fooled by these hackers,use hardwallet such as trezor and ledger so that you will be able to protect your wallet whenever your computer has infected by some viruses and malwares.