SmileyAllTable

Affiche les smiley manquants sur la table des smileys

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला 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 }));
}