Для начала мы создадим отдельную папку для примера и создадим внутри папки 2 файла. Я назвал ceftime.html и style.css
Открываем ceftime.html любым редактором вставляем основу html страницы
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>[CEF] Time and Date</title>
<link rel="stylesheet" type="text/css" href="style.css"> <!-- подключаем файл стилей -->
</head>
<body>
</body>
</html>
Основа страницы готова. Теперь нам нужно создать внутри html документа js скрипт. Заходим в <head> и эти строки
<script type="text/javascript">
function zero_first_format(value)
{
if (value < 10)
{
value='0'+value;
}
return value;
}
function date()
{
var current_datetime = new Date();
var day = zero_first_format(current_datetime.getDate());
var month = zero_first_format(current_datetime.getMonth()+1);
var year = current_datetime.getFullYear();
return day+"."+month+"."+year;
}
function time()
{
var current_datetime = new Date();
var hours = zero_first_format(current_datetime.getHours());
var minutes = zero_first_format(current_datetime.getMinutes());
var seconds = zero_first_format(current_datetime.getSeconds());
return hours+":"+minutes+":"+seconds;
}
document.getElementById('current_date_time_block2').innerHTML = date();
document.getElementById('current_date_time_block3').innerHTML = time();
</script>
Отлично, теперь нам нужно отобразить само время и дату. Для этого добавляем в <body> следующий код.
<div id="current_date_time_block2"></div>
<div id="current_date_time_block3"></div>
<script type="text/javascript">
setInterval(function () {
document.getElementById('current_date_time_block2').innerHTML = date();
document.getElementById('current_date_time_block3').innerHTML = time();
}, 1000);
</script>
Вот что у нас получилось. Состав html документа
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Пример веб-страницы</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
function zero_first_format(value)
{
if (value < 10)
{
value='0'+value;
}
return value;
}
function date()
{
var current_datetime = new Date();
var day = zero_first_format(current_datetime.getDate());
var month = zero_first_format(current_datetime.getMonth()+1);
var year = current_datetime.getFullYear();
return day+"."+month+"."+year;
}
function time()
{
var current_datetime = new Date();
var hours = zero_first_format(current_datetime.getHours());
var minutes = zero_first_format(current_datetime.getMinutes());
var seconds = zero_first_format(current_datetime.getSeconds());
return hours+":"+minutes+":"+seconds;
}
document.getElementById('current_date_time_block2').innerHTML = date();
document.getElementById('current_date_time_block3').innerHTML = time();
</script>
</head>
<body>
<div id="current_date_time_block2"></div>
<div id="current_date_time_block3"></div>
<script type="text/javascript">
setInterval(function () {
document.getElementById('current_date_time_block2').innerHTML = date();
document.getElementById('current_date_time_block3').innerHTML = time();
}, 1000);
</script>
</body>
</html>
Итак, дата и время готовы. А если я например хочу текст разукрасить, сменить расположение или увеличить. Что же мне делать? Заходим в style.css. Открываем с помощью текстового редактора и добавляем следующий код
#current_date_time_block2 {
width:100%;
display:flex;
justify-content:flex-end;
font-size: 150%;
}
#current_date_time_block3 {
float: right;
font-size: 150%;
}
current_date_time_block2 - это дата
current_date_time_block3 - это время
Если вы хотите все в одну строку. Вот вам готовый вариант. HTML файла
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Пример веб-страницы</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
function zero_first_format(value)
{
if (value < 10)
{
value='0'+value;
}
return value;
}
function date_time()
{
var current_datetime = new Date();
var day = zero_first_format(current_datetime.getDate());
var month = zero_first_format(current_datetime.getMonth()+1);
var year = current_datetime.getFullYear();
var hours = zero_first_format(current_datetime.getHours());
var minutes = zero_first_format(current_datetime.getMinutes());
var seconds = zero_first_format(current_datetime.getSeconds());
return day+"."+month+"."+year+" "+hours+":"+minutes+":"+seconds;
}
document.getElementById('current_date_time_block').innerHTML = date_time();
</script>
</head>
<body>
<div id="current_date_time_block2"></div>
<script type="text/javascript">
setInterval(function () {
document.getElementById('current_date_time_block2').innerHTML = date_time();
}, 1000);
</script>
</body>
</html>
Осталось вывести в самом pawno
В начало мода
#include <cef> #include <fmt>
Ко всем define
#define SCMf SendClientMessagef #define CEF_INTERFACE_BROWSER_ID 2
В OnGameModeInit
initialize_interface(playerid);
В конец мода
stock initialize_interface(playerid)
{
cef_create_browser(playerid, CEF_INTERFACE_BROWSER_ID, "Ссылка на сайт", false, false);
return 1;
}
В конец мода, если у вас все еще нет этих строк
forward OnCefBrowserCreated(player_id, browser_id, status_code);
public OnCefBrowserCreated(player_id, browser_id, status_code)
{
SCMf(player_id, -1, "public OnCefBrowserCreated(player_id(%i), browser_id(%i), status_code(%i))", player_id, browser_id, status_code);
if (status_code != 200)
{
SendClientMessage(player_id, -1, "У вас проблемы с интернетом возможные, могут быть сбои.");
return;
}
else
{
SendClientMessage(player_id, -1, "Иницилизация браузера в игру прошла успешно!");
}
return;
}
forward OnCefInitialize(player_id, success);
public OnCefInitialize(player_id, success)
{
SCMf(player_id, -1, "public OnCefInitialize(player_id(%i), success(%i))", player_id, success);
return;
}
Ссылка на плагины, клиент - ТЫК . Версия CEF 1.4
Дата и время с помощью CEF готовы. Получившийся пример лишь демонстрирует вывод и способ. Шрифты, цвет, и прочее вы сможете сами отредактировать в style.css. Основа дана.
Демонстрация скрипта будет чуть позже. Сейчас нет возможности выложить.
Сообщение отредактировал NiceXPlayer: 30 сентября 2021 - 22:22
Вход
Регистрация
Помощь

Тема закрыта









