I am writing a small bot for the chat chat (without a server) and I want to add a fan function of a random word.

Because an array of ~ 1000 words will take a lot of space, I am going to use the site http://sluchajnoe.ru/slovo.php

How do I get a word from him? The entire script is simply embedded on the page twitch through the console.

    1 answer 1

    An array of 1000 words does not take up much space. Let's count.

    Suppose you encode UTF-8 text and your words are Russian.

    To encode a single letter from Cyrillic requires 2 bytes, suppose you have an average word length of 10 characters, therefore you need 20 bytes for one word. You will need approximately 20,000 bytes or 19.5 KB for an array of 1000 words.

    You can not make a request to another resource directly through AJAX and parse the meaning of the word from this resource, the browser policy prohibits directly making any requests for third-party resources. You can try to find a resource that supports and allows you to do this via JSONP or CORS, but you will probably find it easier to have a copy of such a database, because I did not find such resources with these permissions.

    It is more logical that the server script be on the server side and produce a random word, but the server script can connect anywhere and receive data from anywhere, but this does not suit you, you just have to embed the JS on the page, without the possibility of the server part on this same domain.

    • Thanks, and how to do it, for example, on Node.js? I worked with queries when I had full access to both the server and the site, and how to do it here, until I understand: / - Vitaly
    • @Vitaliy Nodejs has the same backend as PHP or Java, and not the client part, write a method on it which can be accessed, which returns a random word, and yank the server method on the same domain on which the script is connected via client javascript . - Firepro