Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local HttpService = game:GetService("HttpService")
- local Players = game:GetService("Players")
- -- Создаем ScreenGui
- local screenGui = Instance.new("ScreenGui")
- screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
- -- Создаем TextBox для ввода запроса
- local searchBox = Instance.new("TextBox")
- searchBox.Size = UDim2.new(0.5, 0, 0.1, 0)
- searchBox.Position = UDim2.new(0.25, 0, 0.1, 0)
- searchBox.PlaceholderText = "Введите запрос"
- searchBox.Parent = screenGui
- -- Создаем ScrollingFrame для отображения результатов
- local scrollingFrame = Instance.new("ScrollingFrame")
- scrollingFrame.Size = UDim2.new(0.5, 0, 0.5, 0)
- scrollingFrame.Position = UDim2.new(0.25, 0, 0.25, 0)
- scrollingFrame.CanvasSize = UDim2.new(0, 0, 2, 0) -- Увеличиваем размер холста для прокрутки
- scrollingFrame.Parent = screenGui
- -- URL API Википедии
- local apiUrl = "https://ru.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch="
- -- Функция для загрузки данных
- local function loadResults(query)
- local response = game:HttpGetAsync(apiUrl .. HttpService:UrlEncode(query))
- local data = HttpService:JSONDecode(response)
- return data.query.search
- end
- -- Функция для очистки текста от HTML-тегов
- local function cleanText(text)
- -- Убираем теги <span class="searchmatch"></span>
- text = text:gsub('<span class="searchmatch">', '')
- text = text:gsub('</span>', '')
- return text
- end
- -- Функция для создания блока
- local function createBlock(result)
- local block = Instance.new("TextButton")
- block.Size = UDim2.new(1, 0, 0, 50)
- block.Text = result.title
- block.TextScaled = true
- block.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- block.BorderSizePixel = 1
- block.Parent = scrollingFrame
- -- Добавляем событие нажатия
- block.MouseButton1Click:Connect(function()
- local explanation = Instance.new("TextLabel")
- explanation.Size = UDim2.new(1, 0, 0, 100)
- explanation.Position = UDim2.new(0, 0, 0, block.AbsolutePosition.Y + block.AbsoluteSize.Y)
- explanation.Text = cleanText("Это из API Википедии: " .. result.snippet)
- explanation.TextScaled = true
- explanation.BackgroundColor3 = Color3.fromRGB(240, 240, 240)
- explanation.BorderSizePixel = 1
- explanation.Parent = scrollingFrame
- end)
- end
- -- Функция для обработки запроса
- local function onSearch()
- scrollingFrame:ClearAllChildren()
- local query = searchBox.Text
- local results = loadResults(query)
- for _, result in ipairs(results) do
- createBlock(result)
- end
- end
- -- Подключение функции к событию изменения текста
- searchBox.FocusLost:Connect(onSearch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement