SmileyAllTable

Affiche les smiley manquants sur la table des smileys

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.3.5
// @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__add pour ajouter la logique javascript)
function customsmileysplus() {
    const fifthRow = document.querySelector(".smileys__modal .smileys__table tr:nth-child(5)");
    fifthRow.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>
    `);
    
    
    const lastRow = document.querySelector(".smileys__modal .smileys__table tr:last-child");
    lastRow.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>
    `;
    
    //logique javascript
    document.querySelectorAll(".smileys__img.smileys__add").forEach(img => {
        img.addEventListener("click", (e) => {
            //e.stopPropagation();
            //e.preventDefault();
            const code = img.dataset.code;
            insertTextAtCursor(` ${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)
    let editor = jvc.getMessageEditor('#bloc-formulaire-forum #message_topic, #message');
    editor.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 }));
}