There is no single factor that uniquely determines whether a certain material is going to gain or lose electrons, but one of the most important properties is the electron's affinity of a certain material. If the affinity of a material is negative, that material will most probably be a receiver of electrons. If the affinity of a material is positive, that material will most probably be a donor of electrons. You can find here a detailed timetable showing the relation between the tendency of receiving / donating electrons and the electrons affinities for a list of materials.