Greasy Fork is available in English.

SmileyAllTable

Affiche les smiley manquants sur la table des smileys

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

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

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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      2.7.0
// @icon         https://image.jeuxvideo.com/smileys_img/11.gif
// @grant        none
// @license      MIT
// ==/UserScript==


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


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

// Associer le gestionnaire d'événements au bouton smiley
function main() {
    const buttonSmileys = document.querySelector('.jvcode-smiley').parentElement;
    buttonSmileys.addEventListener('click', () => {
        const textarea = [...document.querySelectorAll('.messageEditor__edit')].pop();
        lastCursorPosition = textarea.selectionStart;
        waitForSmileyPanel();
    });
}

// Boucle pour détecter le panneau smiley
let tryPannel = 0;
function waitForSmileyPanel() {
    const panel = document.querySelector('.smileys__modal');
    if (panel) {
        handleSmileyPanel();
        tryPannel = 0;
    } else if (++ tryPannel < 10) {
        setTimeout(waitForSmileyPanel, 30);
    }
}


// Remplacement des smileys (classe .smileys__add pour ajouter la logique javascript)
function handleSmileyPanel() {
    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__add" 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__add" 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__add" 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__add" 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__add" 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__add" 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__add" 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__add" 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__add");
    for (const img of smileysImg) {
        img.addEventListener("click", (e) => {
            //e.stopPropagation(); e.preventDefault();
            insertTextAtCursor(` ${img.dataset.code} `);
        });
    }
}

//  Insertion texte à la position mémorisée + fermeture modal
function insertTextAtCursor(text) {
    /* fonction react
    const textarea = [...document.querySelectorAll('.messageEditor__edit')].pop();
    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('.container__post .messageEditor__edit, #message').insertText(text);

    document.querySelector('.smileys__modal .modalWrapper__close')?.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 }));
}