SmileyAllTable

Affiche les smiley manquants sur la table des smileys

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         SmileyAllTable
// @author       Atlantis
// @namespace    SmileyAllTable
// @description  Affiche les smiley manquants sur la table des smileys
// @match        https://www.jeuxvideo.com/messages-prives/nouveau.php*
// @match        https://www.jeuxvideo.com/messages-prives/message.php*
// @match        https://www.jeuxvideo.com/forums/42-*
// @match        https://www.jeuxvideo.com/forums/1-*
// @match        https://www.jeuxvideo.com/forums/0-*
// @version      1.6.2
// @icon         https://image.jeuxvideo.com/smileys_img/11.gif
// @grant        none
// @license      MIT
// ==/UserScript==

/* icon         https://image.noelshack.com/fichiers-xs/2017/13/1490998260-noel.png */

//attendre_le_dom_JVC_2.0_a_larrache
let tentatives = 0;
(function check() {
    const el = document.querySelector('.messageEditor__containerEdit');
    if (el) {
        intialsmileyfun();
    } else if (++tentatives < 6) {
        setTimeout(check, 500);
    }
})();

// Associer le gestionnaire d'événements au bouton smiley
function intialsmileyfun() {
    var button = document.querySelector('.jvcode-smiley').parentElement;
    button.addEventListener('click', function() {
        onSmileyButtonClick();
    });
}

// Position curseur mémorisée au clic
let lastCursorPosition = null;

// Clic sur bouton smiley
function onSmileyButtonClick() {
    const textarea = document.querySelector('#bloc-formulaire-forum #message_topic, #message');
    lastCursorPosition = textarea.selectionStart;
    waitForSmileyPanel();

}

// Boucle pour détecter le panneau smiley
function waitForSmileyPanel(attempt = 0) {
  const maxAttempts = 10;
  const delay = 30;
  const panel = document.querySelector('.modalWrapper__main.smileys__modal');

    if (panel) {
        customsmileysplus();
        return;
    }

    if (attempt < maxAttempts) {
        setTimeout(() => waitForSmileyPanel(attempt + 1), delay);
    }
}


// Remplacement des smileys (classe .smileys__adds pour ajouter la logique javascript)
function customsmileysplus() {
    const smileysTable = document.querySelector(".smileys__modal .smileys__table");
    smileysTable.querySelector("tr:nth-child(5)").insertAdjacentHTML("afterend", `
      <tr>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":hapoelparty:" src="//image.jeuxvideo.com/smileys_img/hapoelparty.gif" width="45" height="27">
        </td>
        <td class="smileys__cell">:hapoelparty:</td>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":loveyou:" src="//image.jeuxvideo.com/smileys_img/loveyou.gif" width="64" height="30">
        </td>
        <td class="smileys__cell">:loveyou:</td>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":opps:" src="//image.jeuxvideo.com/smileys_img/opps.gif" width="16" height="16">
        </td>
        <td class="smileys__cell">:opps:</td>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":fish:" src="//image.jeuxvideo.com/smileys_img/fish.png" width="16" height="16">
        </td>
        <td class="smileys__cell">:fish:</td>
      </tr>
    `);

    smileysTable.querySelector("tr:last-child").outerHTML = `
      <tr>
        <td class="smileys__cell">
           <img class="smileys__img smileys__adds" data-code=":siffle:" src="//image.jeuxvideo.com/smileys_img/siffle.gif" width="22" height="16">
        </td>
        <td class="smileys__cell">:siffle:</td>
        <td class="smileys__cell">
           <img class="smileys__img smileys__adds" data-code=":opps:" src="//image.jeuxvideo.com/smileys_img/opps.gif" width="16" height="16">
           </td>
        <td class="smileys__cell">:opps:</td>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":mac:" src="//image.jeuxvideo.com/smileys_img/16.gif" width="16" height="16">
        </td>
        <td class="smileys__cell">:mac:</td>
        <td class="smileys__cell">
            <img class="smileys__img smileys__adds" data-code=":globe:" src="//image.jeuxvideo.com/smileys_img/6.gif" width="16" height="16">
        </td>
        <td class="smileys__cell">:globe:</td>
      </tr>
    `;

    //Listener JS
    const smileysImg = smileysTable.querySelectorAll(".smileys__img.smileys__adds");
    for (const img of smileysImg) {
        img.addEventListener("click", (e) => {
            //e.stopPropagation(); e.preventDefault();
            insertTextAtCursor(` ${img.dataset.code} `);
        });
    }
}

//  Insertion texte à la position mémorise fermeture modal
function insertTextAtCursor(text) {
    /* fonction react => js vanilla
    const textarea = document.querySelector('#bloc-formulaire-forum #message_topic, #message');
    const start = lastCursorPosition;
    const end = lastCursorPosition;
    const before = textarea.value.substring(0, start);
    const after = textarea.value.substring(end);
    const message = before + text + after;

    //react
    fonctionreact(textarea, message);
    const newPos = start + text.length;
    textarea.selectionStart = textarea.selectionEnd = newPos;

    textarea.focus();
    */
    //fonction JVC (si jvc bloque => décommenter le bloc du dessus et supprimer les 2 lignes suivante)
    const apiJvc = typeof jvc !== "undefined" ? jvc : unsafeWindow.jvc;
    apiJvc.getMessageEditor('#bloc-formulaire-forum #message_topic, #message').insertText(text);
    //fonction JVC fin

    const closeBtn = document.querySelector('.smileys__modal .modalWrapper__close');
    if (closeBtn) closeBtn.click();
}


function fonctionreact(textarea, value) {
   const prototype = Object.getPrototypeOf(textarea);
   const nativeSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
   nativeSetter.call(textarea, value);
   textarea.dispatchEvent(new Event('input', { bubbles: true }));
}