Today, that's called Fanfic or Fan Fiction, or, to be pedantic, Fan-Written Fiction.
Fanfic is simply fiction written by fans of a story, whether a show, movie, book or comic.
And a good sign of a story's popularity these days is how much fanfic it generates.
Strictly speaking, writing and showing fanfic to others is a violation of the copyright of the originator.
The Star Trek franchise has even had fanfic contests and published anthologies of contest winning fanfic.
While most television shows will turn a blind eye to fanfic written in their universe, some book authors are not so forgiving (while some, like Flint mentioned above, are quite open to fanfic).
The authors that will come after fanfic writers in their universe, of course, have legal right on their side.
I suspect that this is only part of the total reason why some authors object to fanfic.
Authors who object to fanfic in their universes include Anne McCaffrey, Anne Rice.
The motives for writing fanfic are many and varied.
Fanfic allows fans to put characters in genuine peril from which they might not escape.
Main characters are often 'offed' in fanfic, if it suits the story, something you will rarely see in show 'canon'.
And of course, fanfic allows the fictional characters to finally have a love life.
Novice actors who find themselves in a 'cult hit' often have to be gently introduced to what is fanfic, to prevent culture shock.
A question perhaps more relevant than 'what is Fanfic?' might be 'Where is all the fanfic?'
The original source material from which all fanfic flows.
An erotic piece of fanfic that posits a romantic relationship between a male and female character from source.
While the characters might be romantically involved in the source material, a het fanfic will, more than likely, spare no details of their sexual relationship.
An erotic piece of fanfic that posits a romantic relationship between two male characters from the source.
Marysue is a much maligned Original Character (OC) that the fanfic author inserts in her story to serve as her avatar.
If you write fan fiction (or fanfic for short) you should be aware of both your legal rights and the rights of the author you are deriving your work from.
The word usage examples above have been gathered from various sources to reflect current and historial usage. They do not represent the opinions of YourDictionary.com.