The logic for doing what you want is already hard-coded into the battery and its internal charging circuits. Not only is pretty much every laptop on the market today doing this, but I imagine it's not something you can change, either. (Commenting from personal experience, I've seen this behavior in every laptop I've owned or had loaned to me over the past 6 years-- Two Dells, two MBPs, and a Lenovo)
When it comes to proper care of laptop batteries these days, the only real advice that an end-user can take is
Store the battery in a cool, dry place when it's not being used, and don't heat it up while it's charging.
Yes, that means you probably don't want to use the laptop while the battery is charging.
Pretty much every other detail with regards to charging cycles or the implementation thereof have been gone over by experts that study batteries for a living, and are likely already tailored to your battery far better than any generic internet advice will give you.