forked from Simnation/Main
fix
This commit is contained in:
parent
a32228ba5f
commit
93926f0de7
5 changed files with 126 additions and 213 deletions
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
local spawnedObjects = {}
|
local spawnedObjects = {}
|
||||||
|
|
||||||
local imageDisplayed = false
|
local imageDisplayed = false
|
||||||
|
|
||||||
RegisterNetEvent('pl_printer:notification')
|
RegisterNetEvent('pl_printer:notification')
|
||||||
AddEventHandler('pl_printer:notification', function(message, type)
|
AddEventHandler('pl_printer:notification', function(message, type)
|
||||||
|
|
||||||
if Config.Notify == 'ox' then
|
if Config.Notify == 'ox' then
|
||||||
TriggerEvent('ox_lib:notify', {description = message, type = type or "success"})
|
TriggerEvent('ox_lib:notify', {description = message, type = type or "success"})
|
||||||
elseif Config.Notify == 'esx' then
|
elseif Config.Notify == 'esx' then
|
||||||
|
@ -28,69 +31,40 @@ function enableControls()
|
||||||
FreezeEntityPosition(PlayerPedId(), false)
|
FreezeEntityPosition(PlayerPedId(), false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Event für QB-Core Inventar
|
|
||||||
RegisterNetEvent("pl_printer:showImageQB")
|
RegisterNetEvent("pl_printer:showImageQB")
|
||||||
AddEventHandler("pl_printer:showImageQB", function(imageName)
|
AddEventHandler("pl_printer:showImageQB", function(imageName)
|
||||||
print("[DEBUG] Received showImageQB event with imageName: " .. tostring(imageName))
|
TriggerServerEvent('pl_printer:fetchImageLink',imageName)
|
||||||
TriggerServerEvent('pl_printer:fetchImageLink', imageName)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hauptevent zum Anzeigen des Bildes
|
|
||||||
RegisterNetEvent("pl_printer:showImage")
|
RegisterNetEvent("pl_printer:showImage")
|
||||||
AddEventHandler("pl_printer:showImage", function(imageUrl)
|
AddEventHandler("pl_printer:showImage", function(imageName)
|
||||||
print("[DEBUG] Received showImage event with URL: " .. tostring(imageUrl))
|
|
||||||
|
|
||||||
if not imageDisplayed then
|
if not imageDisplayed then
|
||||||
imageDisplayed = true
|
imageDisplayed = true
|
||||||
SetNuiFocus(true, true)
|
SetNuiFocus(true, true)
|
||||||
|
|
||||||
-- Extrahiere den Dateinamen aus der URL für die Dokument-ID
|
|
||||||
local documentId = imageUrl:match(".*/(.*)$") or "unknown"
|
|
||||||
|
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
action = "show",
|
action = "show",
|
||||||
imageUrl = imageUrl,
|
imageUrl = imageName
|
||||||
documentId = documentId -- Füge die Dokument-ID hinzu
|
|
||||||
})
|
})
|
||||||
|
|
||||||
disableControls()
|
disableControls()
|
||||||
else
|
|
||||||
print("[DEBUG] Image already displayed, ignoring request")
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- NUI-Callback zum Schließen des Bildes
|
|
||||||
RegisterNUICallback('hideFrame', function(data, cb)
|
RegisterNUICallback('hideFrame', function(data, cb)
|
||||||
print("[DEBUG] Hiding image frame")
|
|
||||||
imageDisplayed = false
|
imageDisplayed = false
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
enableControls()
|
enableControls()
|
||||||
|
|
||||||
-- Füge einen Callback hinzu, wenn er benötigt wird
|
|
||||||
if cb then cb('ok') end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Sicherheits-Callback für den Fall, dass die Seite neu geladen wird
|
|
||||||
RegisterNUICallback('pageLoaded', function(data, cb)
|
|
||||||
print("[DEBUG] NUI page loaded")
|
|
||||||
-- Stelle sicher, dass der Focus zurückgesetzt wird, falls die Seite neu geladen wurde
|
|
||||||
if not imageDisplayed then
|
|
||||||
SetNuiFocus(false, false)
|
|
||||||
end
|
|
||||||
if cb then cb('ok') end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Event zum Öffnen des Druckermenüs
|
|
||||||
RegisterNetEvent("pl_printer:openprinter")
|
RegisterNetEvent("pl_printer:openprinter")
|
||||||
AddEventHandler("pl_printer:openprinter", function()
|
AddEventHandler("pl_printer:openprinter", function()
|
||||||
|
|
||||||
local input = lib.inputDialog('Print Menu', {
|
local input = lib.inputDialog('Print Menu', {
|
||||||
{type = 'input', label = Locale("image_link"), description = Locale("image_url"), required = true},
|
{type = 'input', label = Locale("image_link"), description = Locale("image_url"), required = true},
|
||||||
{type = 'number', label = Locale("copies"), description = Locale("image_url"), required = true, placeholder='1', icon = 'hashtag'},
|
{type = 'number', label = Locale("copies"), description = Locale("image_url"),required = true,placeholder='1', icon = 'hashtag'},
|
||||||
})
|
|
||||||
|
|
||||||
|
})
|
||||||
if input then
|
if input then
|
||||||
if input[1] and input[2] then
|
if input[1] and input[2] then
|
||||||
print("[DEBUG] Sending image data to server: " .. input[1] .. ", copies: " .. input[2])
|
|
||||||
TriggerServerEvent('pl_printer:insertImageData', input[1], input[2])
|
TriggerServerEvent('pl_printer:insertImageData', input[1], input[2])
|
||||||
else
|
else
|
||||||
_debug('[DEBUG] '..'Invalid Input'..'')
|
_debug('[DEBUG] '..'Invalid Input'..'')
|
||||||
|
@ -98,7 +72,6 @@ AddEventHandler("pl_printer:openprinter", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Target-System-Konfiguration
|
|
||||||
for _, model in ipairs(Config.PrinterModel) do
|
for _, model in ipairs(Config.PrinterModel) do
|
||||||
if GetResourceState('qb-target') == 'started' then
|
if GetResourceState('qb-target') == 'started' then
|
||||||
exports['qb-target']:AddTargetModel(model, {
|
exports['qb-target']:AddTargetModel(model, {
|
||||||
|
@ -113,7 +86,7 @@ for _, model in ipairs(Config.PrinterModel) do
|
||||||
},
|
},
|
||||||
distance = 2
|
distance = 2
|
||||||
})
|
})
|
||||||
elseif GetResourceState('qtarget') == 'started' or GetResourceState('ox_target') == 'started' then
|
elseif GetResourceState('qtarget') == 'started' or GetResourceState('ox_target') == 'started'then
|
||||||
exports.ox_target:addModel(model, {
|
exports.ox_target:addModel(model, {
|
||||||
{
|
{
|
||||||
name = 'printer_interaction',
|
name = 'printer_interaction',
|
||||||
|
@ -128,7 +101,7 @@ for _, model in ipairs(Config.PrinterModel) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Funktion zum Spawnen von Objekten
|
|
||||||
local function spawnObject(object, coords, heading)
|
local function spawnObject(object, coords, heading)
|
||||||
lib.requestModel(object)
|
lib.requestModel(object)
|
||||||
|
|
||||||
|
@ -136,7 +109,6 @@ local function spawnObject(object, coords, heading)
|
||||||
_debug('[DEBUG] '..object..' failed to load.'..'')
|
_debug('[DEBUG] '..object..' failed to load.'..'')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local entity = CreateObject(object, coords.x, coords.y, coords.z, true, true, true)
|
local entity = CreateObject(object, coords.x, coords.y, coords.z, true, true, true)
|
||||||
|
|
||||||
if DoesEntityExist(entity) then
|
if DoesEntityExist(entity) then
|
||||||
|
@ -148,7 +120,7 @@ local function spawnObject(object, coords, heading)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Funktion zum Löschen von gespawnten Objekten
|
|
||||||
local function deleteSpawnedObjects()
|
local function deleteSpawnedObjects()
|
||||||
for _, obj in ipairs(spawnedObjects) do
|
for _, obj in ipairs(spawnedObjects) do
|
||||||
if DoesEntityExist(obj) then
|
if DoesEntityExist(obj) then
|
||||||
|
@ -158,7 +130,7 @@ local function deleteSpawnedObjects()
|
||||||
spawnedObjects = {}
|
spawnedObjects = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Resource-Start-Event
|
|
||||||
AddEventHandler('onResourceStart', function(resourceName)
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
if GetCurrentResourceName() ~= resourceName then return end
|
if GetCurrentResourceName() ~= resourceName then return end
|
||||||
for _, location in ipairs(Config.Locations) do
|
for _, location in ipairs(Config.Locations) do
|
||||||
|
@ -166,13 +138,12 @@ AddEventHandler('onResourceStart', function(resourceName)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Resource-Stop-Event
|
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
if GetCurrentResourceName() ~= resourceName then return end
|
if GetCurrentResourceName() ~= resourceName then return end
|
||||||
deleteSpawnedObjects()
|
deleteSpawnedObjects()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Funktion für Spieler-Login
|
|
||||||
function onPlayerLoaded()
|
function onPlayerLoaded()
|
||||||
Wait(3000)
|
Wait(3000)
|
||||||
for _, location in ipairs(Config.Locations) do
|
for _, location in ipairs(Config.Locations) do
|
||||||
|
@ -180,52 +151,8 @@ function onPlayerLoaded()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debug-Hilfsfunktion
|
|
||||||
function _debug(...)
|
function _debug(...)
|
||||||
if Config.Debug then
|
if Config.Debug then
|
||||||
print(...)
|
print(...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Notfall-Thread zum Zurücksetzen des NUI-Focus, falls etwas schief geht
|
|
||||||
Citizen.CreateThread(function()
|
|
||||||
while true do
|
|
||||||
Citizen.Wait(1000)
|
|
||||||
if imageDisplayed then
|
|
||||||
-- Prüfe, ob ESC gedrückt wurde (Fallback für den Fall, dass der NUI-Callback nicht funktioniert)
|
|
||||||
if IsControlJustReleased(0, 177) then -- ESC-Taste
|
|
||||||
print("[DEBUG] ESC key detected in thread, resetting focus")
|
|
||||||
imageDisplayed = false
|
|
||||||
SetNuiFocus(false, false)
|
|
||||||
enableControls()
|
|
||||||
SendNUIMessage({
|
|
||||||
action = "hide"
|
|
||||||
})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Citizen.Wait(1000) -- Längere Wartezeit, wenn kein Bild angezeigt wird
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Füge diesen Code hinzu, um das HTML zu aktualisieren, wenn die Ressource neu gestartet wird
|
|
||||||
AddEventHandler('onResourceStart', function(resourceName)
|
|
||||||
if GetCurrentResourceName() == resourceName then
|
|
||||||
-- Stelle sicher, dass der NUI-Focus zurückgesetzt wird
|
|
||||||
SetNuiFocus(false, false)
|
|
||||||
imageDisplayed = false
|
|
||||||
enableControls()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Füge diesen Code hinzu, um den NUI-Focus zurückzusetzen, wenn der Spieler stirbt
|
|
||||||
AddEventHandler('playerSpawned', function()
|
|
||||||
if imageDisplayed then
|
|
||||||
imageDisplayed = false
|
|
||||||
SetNuiFocus(false, false)
|
|
||||||
enableControls()
|
|
||||||
SendNUIMessage({
|
|
||||||
action = "hide"
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
|
|
||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
Config.Locale = 'de' -- 'en', 'fr', 'de', 'es', 'it', 'pt', 'tr' -- Language
|
Config.Locale = 'en' -- 'en', 'fr', 'de', 'es', 'it', 'pt', 'tr' -- Language
|
||||||
|
|
||||||
Config.Debug = true
|
Config.Debug = false
|
||||||
|
|
||||||
Config.Notify = 'okok' --ox, esx, okok,qb,wasabi,custom
|
Config.Notify = 'ox' --ox, esx, okok,qb,wasabi,custom
|
||||||
|
|
||||||
Config.CheckItem = false --If you want player to have item before opening
|
Config.CheckItem = false --If you want player to have item before opening
|
||||||
|
|
||||||
Config.PrinterModel = {`prop_printer_02`,`prop_printer_01`,`v_res_printer`}
|
Config.PrinterModel = {`prop_printer_02`,`prop_printer_01`}
|
||||||
|
|
||||||
Config.ItemName = 'printerdocument'
|
Config.ItemName = 'paper'
|
||||||
|
|
||||||
Config.Print = {
|
Config.Print = {
|
||||||
Price = 0, --Price
|
Price = 50, --Price
|
||||||
Account = 'bank' --This is the account your money will be deducted
|
Account = 'bank' --This is the account your money will be deducted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"copies": "Kopien",
|
"copies": "Kopien",
|
||||||
"image_url": "Bild-URL eingeben",
|
"image_url": "Bild-URL eingeben",
|
||||||
"enter_copies": "Anzahl der Kopien eingeben",
|
"enter_copies": "Anzahl der Kopien eingeben",
|
||||||
"prints": "Drucken",
|
"prints": "Drucke",
|
||||||
"Money_Removed": "Geld vom Bankkonto entfernt: $",
|
"Money_Removed": "Geld vom Bankkonto entfernt: $",
|
||||||
"not_enough": "Nicht genug Geld"
|
"not_enough": "Nicht genug Geld"
|
||||||
}
|
}
|
|
@ -1,79 +1,98 @@
|
||||||
<!DOCTYPE html>
|
if GetResourceState('qb-core') == 'started' then
|
||||||
<html lang="en">
|
QBCore = exports['qb-core']:GetCoreObject()
|
||||||
<head>
|
elseif GetResourceState('es_extended') == 'started' then
|
||||||
<meta charset="UTF-8">
|
ESX = exports['es_extended']:getSharedObject()
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
end
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
local resourceName = 'pl_printer'
|
||||||
<title></title>
|
lib.versionCheck('pulsepk/pl_printer')
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
overflow: hidden;
|
|
||||||
background-color: rgba(0, 0, 0, 0.7);
|
|
||||||
}
|
|
||||||
#image-container {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
max-width: 90%;
|
|
||||||
max-height: 90%;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
#image {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
}
|
|
||||||
#document-id {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 10px;
|
|
||||||
left: 10px;
|
|
||||||
color: white;
|
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
|
||||||
padding: 5px;
|
|
||||||
border-radius: 3px;
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="image-container">
|
|
||||||
<img id="image" src="" alt="Document">
|
|
||||||
<div id="document-id"></div>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
window.addEventListener('message', function(event) {
|
|
||||||
if (event.data.action === 'show') {
|
|
||||||
// Zeige das spezifische Dokument basierend auf der ID oder URL
|
|
||||||
document.getElementById('image').src = event.data.imageUrl;
|
|
||||||
|
|
||||||
// Zeige optional die Dokument-ID an
|
RegisterServerEvent('pl_printer:insertImageData')
|
||||||
if (event.data.documentId) {
|
AddEventHandler('pl_printer:insertImageData', function(imageUrl, amount)
|
||||||
document.getElementById('document-id').textContent = "Dokument: " + event.data.documentId;
|
local Player = getPlayer(source)
|
||||||
}
|
local account = Config.Print.Account
|
||||||
|
local TotalBill = Config.Print.Price*amount
|
||||||
|
if GetPlayerAccountMoney(Player,account,TotalBill) then
|
||||||
|
local imageName = imageUrl:match(".*/(.*)$")
|
||||||
|
AddItem(source,amount, imageName)
|
||||||
|
if imageUrl and amount then
|
||||||
|
MySQL.Async.execute('INSERT INTO printer (image_name, image_link) VALUES (@image_name, @image_link)', {
|
||||||
|
['@image_name'] = tostring(imageName),
|
||||||
|
['@image_link'] = imageUrl
|
||||||
|
}, function(rowsChanged)
|
||||||
|
|
||||||
document.getElementById('image-container').style.display = 'block';
|
end)
|
||||||
|
RemovePlayerMoney(Player,account,TotalBill)
|
||||||
|
TriggerClientEvent('pl_printer:notification',source,Locale("Money_Removed") .. TotalBill,'success')
|
||||||
|
else
|
||||||
|
_debug('[DEBUG] '..' Invalid data received for image. '..'')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
TriggerClientEvent('pl_printer:notification',source,Locale("not_enough"),'error')
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
// Logge die Dokument-Informationen zur Fehlersuche
|
|
||||||
console.log("Dokument angezeigt:", event.data);
|
|
||||||
} else if (event.data.action === 'hide') {
|
|
||||||
document.getElementById('image-container').style.display = 'none';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("keydown", function(event) {
|
RegisterServerEvent('pl_printer:fetchImageLink')
|
||||||
if (event.key === "Escape") {
|
AddEventHandler('pl_printer:fetchImageLink', function(imageName,playerSource)
|
||||||
document.getElementById('image-container').style.display = 'none';
|
local hasItem = HasItem(playerSource)
|
||||||
axios.post(`https://${GetParentResourceName()}/hideFrame`, {})
|
if not hasItem then return end
|
||||||
.then(function (response) {
|
MySQL.Async.fetchScalar('SELECT image_link FROM printer WHERE image_name = @imageName', {
|
||||||
console.log("Frame versteckt");
|
['@imageName'] = imageName
|
||||||
})
|
}, function(imageLink)
|
||||||
.catch(function (error) {
|
if imageLink then
|
||||||
console.error("Fehler beim Verstecken des Frames:", error);
|
TriggerClientEvent('pl_printer:showImage',playerSource,imageLink)
|
||||||
});
|
else
|
||||||
|
_debug('[DEBUG] '..' No Image Link Found for '..imageName..'')
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
function AddItem(source, amount, imageName)
|
||||||
|
local src = source
|
||||||
|
local info = {
|
||||||
|
id = imageName
|
||||||
}
|
}
|
||||||
});
|
if GetResourceState('qb-inventory') == 'started' then
|
||||||
</script>
|
if lib.checkDependency('qb-inventory', '2.0.0') then
|
||||||
</body>
|
exports['qb-inventory']:AddItem(src,Config.ItemName,amount,false,info)
|
||||||
</html>
|
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], 'add', amount)
|
||||||
|
else
|
||||||
|
local Player = getPlayer(src)
|
||||||
|
Player.Functions.AddItem(Config.ItemName, amount,false, info)
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[Config.ItemName], "add")
|
||||||
|
end
|
||||||
|
elseif GetResourceState('ox_inventory') == 'started' then
|
||||||
|
exports.ox_inventory:AddItem(src,Config.ItemName,amount,imageName,false)
|
||||||
|
elseif GetResourceState('qs-inventory') == 'started' then
|
||||||
|
local itemMetadata ={ id = imageName }
|
||||||
|
exports['qs-inventory']:AddItem(src,Config.ItemName,amount,false,itemMetadata)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
AddEventHandler('onServerResourceStart', function()
|
||||||
|
if GetResourceState('ox_inventory') == 'started' then
|
||||||
|
exports(Config.ItemName,function (event,item,inventory,slot,data)
|
||||||
|
if event == 'usingItem' then
|
||||||
|
local item_metadata = exports.ox_inventory:GetSlot(inventory.id, slot)
|
||||||
|
TriggerEvent('pl_printer:fetchImageLink', item_metadata.metadata.type, inventory.id)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
local WaterMark = function()
|
||||||
|
SetTimeout(1500, function()
|
||||||
|
print('^1['..resourceName..'] ^2Thank you for Downloading the Script^0')
|
||||||
|
print('^1['..resourceName..'] ^2If you encounter any issues please Join the discord https://discord.gg/c6gXmtEf3H to get support..^0')
|
||||||
|
print('^1['..resourceName..'] ^2Enjoy a secret 20% OFF any script of your choice on https://pulsescripts.tebex.io/freescript^0')
|
||||||
|
print('^1['..resourceName..'] ^2Using the coupon code: SPECIAL20 (one-time use coupon, choose wisely)^0')
|
||||||
|
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
WaterMark()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: transparent;
|
|
||||||
}
|
}
|
||||||
#image {
|
#image {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -25,57 +24,25 @@
|
||||||
<body>
|
<body>
|
||||||
<img id="image" src="" alt="Image" style="display:none;">
|
<img id="image" src="" alt="Image" style="display:none;">
|
||||||
<script>
|
<script>
|
||||||
// Globale Variable, um den Status zu verfolgen
|
|
||||||
let isDisplayed = false;
|
|
||||||
|
|
||||||
window.addEventListener('message', function(event) {
|
window.addEventListener('message', function(event) {
|
||||||
if (event.data.action === 'show') {
|
if (event.data.action === 'show') {
|
||||||
document.getElementById('image').src = event.data.imageUrl;
|
document.getElementById('image').src = event.data.imageUrl;
|
||||||
document.getElementById('image').style.display = 'block';
|
document.getElementById('image').style.display = 'block';
|
||||||
isDisplayed = true;
|
|
||||||
console.log("Showing image:", event.data.imageUrl);
|
|
||||||
} else if (event.data.action === 'hide') {
|
} else if (event.data.action === 'hide') {
|
||||||
document.getElementById('image').style.display = 'none';
|
document.getElementById('image').style.display = 'none';
|
||||||
isDisplayed = false;
|
|
||||||
console.log("Hiding image");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("keydown", function(event) {
|
document.addEventListener("keydown", function(event) {
|
||||||
if (event.key === "Escape" && isDisplayed) {
|
if (event.key === "Escape") {
|
||||||
document.getElementById('image').style.display = 'none';
|
document.getElementById('image').style.display = 'none';
|
||||||
isDisplayed = false;
|
axios.post(`https://${GetParentResourceName()}/hideFrame`, {})
|
||||||
|
.then(function (response) {
|
||||||
// Sende Nachricht zurück an den Client
|
|
||||||
fetch(`https://${GetParentResourceName()}/hideFrame`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({})
|
|
||||||
})
|
})
|
||||||
.then(response => {
|
.catch(function (error) {
|
||||||
console.log("Frame hidden successfully");
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error("Error hiding frame:", error);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sicherheitsmechanismus: Wenn die Seite geladen wird, stelle sicher, dass der Focus zurückgesetzt wird
|
|
||||||
window.onload = function() {
|
|
||||||
fetch(`https://${GetParentResourceName()}/pageLoaded`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({})
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error("Error notifying page load:", error);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue