Are you aware that one of the most cliché jokes told outside of the U.S. is some variation of "when an American says democracy, everyone ducks for cover"?
I don't think there were designs on Afghanistan, but these strategies usually work like chess, where having an opposing piece in one place constrains actions in another. Afghanistan is next to Xinjiang, where some subversive actions were demonstrated, so China ended up having to pay a lot of attention to the western front and therefore had less strategic flexibility in the near Pacific where her main interests lie.
Having said that, it didn't work at all. China patiently used those 20 years to develop its economy and infrastructure, locked down Xinjiang against subversion, set up Belt and Road, and gained strategic tempo in the South China Sea and the Taiwan Strait while the US got much too carried away in Central Asia.
China would be happy if US stayed and maintained stability in the region, so US didn't lose, they created a problem for China. The military industry made a lot of money, Afghanistan has been the training ground for terrorists attack in Pakistan (recently a bus bomb against Chinese), and Xinjiang. Let's see how Taliban manage the country. If Afghanistan become stable, then US might not be very happy about it.
"Afghanistan may be sitting on one of the richest troves of minerals in the world, valued at nearly $1 trillion, scientists say."
https://www.nbcnews.com/science/science-news/rare-earth-afgh...
The Chinese will ask no questions, will do the work, and wont bother the Taliban with annoying issues like freedom and democracy. A perfect match.