« Module:MinecraftConnect » : différence entre les versions
De Nefald
Autres actions
mAucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 2 : | Ligne 2 : | ||
function p.button(frame) | function p.button(frame) | ||
-- Récupération des arguments | -- Récupération des arguments | ||
local args = frame.args | local args = frame.args | ||
if not args[1] and frame:getParent() then | if not args[1] and frame:getParent() then | ||
| Ligne 8 : | Ligne 8 : | ||
end | end | ||
local server = mw.text.trim(args[1] or args.serveur or 'play.exemple.fr') | local server = mw.text.trim(args[1] or args.serveur or 'play.exemple.fr') | ||
local port = mw.text.trim(args[2] or args.port or '25565') | local port = mw.text.trim(args[2] or args.port or '25565') | ||
| Ligne 14 : | Ligne 13 : | ||
-- Construction de l'adresse complète | -- Construction de l'adresse complète | ||
local adresseComplete | local adresseComplete = (port == '25565') and server or (server .. ':' .. port) | ||
-- Génération d'un ID unique | -- Génération d'un ID unique | ||
local uniqueId = 'mc-btn-' .. | local uniqueId = 'mc-btn-' .. mw.hash('crc32', server .. port) | ||
-- HTML du bouton | -- HTML du bouton | ||
local html = mw.html.create(' | local html = mw.html.create('button') | ||
:addClass('minecraft-connect-button') | :addClass('mw-ui-button mw-ui-progressive minecraft-connect-btn') | ||
:attr('type', 'button') | |||
:attr('id', uniqueId) | :attr('id', uniqueId) | ||
: | :attr('data-copy-text', adresseComplete) | ||
:attr('title', 'Cliquer pour copier : ' .. mw.text.encode(adresseComplete)) | |||
:wikitext(mw.text.encode(texte) .. ' 📋') | |||
-- Ajout du module ResourceLoader | |||
frame:extensionTag('templatestyles', '', {src = 'Module:MinecraftConnect/styles.css'}) | |||
return tostring(html | return tostring(html) | ||
end | end | ||
return p | return p | ||
Version du 10 novembre 2025 à 13:46
La documentation pour ce module peut être créée à Module:MinecraftConnect/doc
local p = {}
function p.button(frame)
-- Récupération des arguments
local args = frame.args
if not args[1] and frame:getParent() then
args = frame:getParent().args
end
local server = mw.text.trim(args[1] or args.serveur or 'play.exemple.fr')
local port = mw.text.trim(args[2] or args.port or '25565')
local texte = mw.text.trim(args[3] or args.texte or "Copier l'adresse")
-- Construction de l'adresse complète
local adresseComplete = (port == '25565') and server or (server .. ':' .. port)
-- Génération d'un ID unique
local uniqueId = 'mc-btn-' .. mw.hash('crc32', server .. port)
-- HTML du bouton
local html = mw.html.create('button')
:addClass('mw-ui-button mw-ui-progressive minecraft-connect-btn')
:attr('type', 'button')
:attr('id', uniqueId)
:attr('data-copy-text', adresseComplete)
:attr('title', 'Cliquer pour copier : ' .. mw.text.encode(adresseComplete))
:wikitext(mw.text.encode(texte) .. ' 📋')
-- Ajout du module ResourceLoader
frame:extensionTag('templatestyles', '', {src = 'Module:MinecraftConnect/styles.css'})
return tostring(html)
end
return p