Utilisateur:Alu/code en jeu.js
Aller à la navigation
Aller à la recherche
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
- Opera : appuyez sur Ctrl + F5.
/** * gw2wiki - Code en jeu * * Fonctions qui servent à rendre les codes en jeu cliquable pour faciliter leur sélection */ (function($) { function focusGameLink() { var x = this.previousSibling; x.style.display = 'inline-block'; this.style.visiblity = 'hidden'; x.focus(); x.select(); } function blurGameLink() { var y = this.nextSibling; y.style.visiblity = 'visible'; this.style.display = 'none'; } // The main object var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; } }; function BEtoLE(be) { var le = String.fromCharCode(be.charCodeAt(0) & 255) + String.fromCharCode(be.charCodeAt(0) >> 8); return le; } function encodeId(type, id, container) { if (type.toString().match(/(1|2|4|7|8|10)/)) { var typeId = String.fromCharCode(type); if (type == 2) { typeId += String.fromCharCode(1); } id = BEtoLE(String.fromCharCode(parseInt(id))); var pad = String.fromCharCode(0) + String.fromCharCode(0); var chatLink = "[&" + Base64.encode(typeId + id + pad) + "]"; $(container).text(chatLink); // Create an input element with the same content var a = document.createElement('input'); a.type = 'text'; a.value = chatLink; // Make it overlay the plaintext, but hidden by default a.className = 'chatlink'; container.parentNode.insertBefore(a,container); // Event handlers to make the input box appear (and focus it and select the contents) when the plaintext is clicked... container.addEventListener('click', focusGameLink); // ...and to hide the input box when the user clicks away from it. a.addEventListener('blur', blurGameLink); } else { $(container).text('Erreur: type inconnu: ' + type); } } function gameLinkShow() { var gameLinks = $('.gameLink'); var id, type, elem; for (var i = 0; i < gameLinks.length; ++i) { elem = gameLinks[i]; id = elem.getAttribute('data-id') || 0; type = elem.getAttribute('data-type') || ''; var typeId; switch (type.toLowerCase()) { case "objet": typeId = 2; break; case "carte": typeId = 4; break; case "compétence": case "comp": typeId = 7; break; case "aptitude": typeId = 8; break; case "recette": typeId = 10; break; default: typeId = 0; break; } encodeId(typeId, id, elem); } } // on exécute le script dès que la page est prète. $(gameLinkShow); })(jQuery);