So, you're trying to host a javascript-mining website that uses your visitors' resources to mine and send the profits to your address? Or are you trying to run your own cloud mining service? Both of them are terrible services and most of the time is known for scams. I'll try to be positive here and not jump to conclusion that you want to build a malware site that tricks visitors to mine with their computers.
If you do find a free mining script, I won't be surprised if it runs other malicious scripts without notifying you. Your best bet is probably to commission some developer to build the script for you. If you want to mine and earn Monero without doing any of that, just mine with a rig and mining software.
My other question: How can I write my own javascript based monero mining algorithm from scratch? Any lesson, training set, book, etc. about what I want. I couldn't find it. If there is a training set that explains in this way, can you write it?
Well, you will need to know some Javascript at least. There is no dedicated book/article that explains it since mining script is a niche program compared to other Javascript applications. If you don't want to learn from the big picture, your best option would be to find an existing Javascript mining algorithm software and then learn from there. Find out what this or that function does, ask around if you don't understand the flow of the algorithm, etc.