Edenya-Script

Addon Edenya

当前为 2018-07-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Edenya-Script
// @namespace    http://tampermonkey.net/
// @version      0.100019
// @description  Addon Edenya
// @author       Valkazaar
// @match        http://www.edenya.net/_vahal/*
// @grant        none
// @include        http://www.edenya.net/_vahal/*
// @include        https://www.edenya.net/_vahal/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==

function checkMessages(){
    $.ajax({
        type: 'GET',
        url: 'https://www.edenya.net/index2.php?loca=communiquer/forum/messages',
        //data: datas,
        success: function(data) {
            var i = (data.split("#AA2020")).length - 1;
            if(i>0){
                $('#ValkHidden').html('<a href="https://www.edenya.net/index2.php?loca=communiquer/forum/messages">'+i + (i > 1 ? ' messages non lus':' message non lu')+'</a>');
            }
        }});
    }
function Valk_Del(item){
    var z = localStorage.getItem('EdenyaShortcut');
    z = JSON.parse(z);
    delete z[item];
    localStorage.setItem('EdenyaShortcut',JSON.stringify(z));
    Valk_Refresh();
}
function Valk_Refresh(){
    var first = true;
    var z = localStorage.getItem('EdenyaShortcut');
    z = JSON.parse(z);
    var menuToAdd = document.getElementById('menuValk');
    menuToAdd.innerText='';
    for (var item in z) {
        var linkToUp = document.createElement('img');
        linkToUp.setAttribute('src', '../images/arrow-up.gif');
        linkToUp.setAttribute('onclick', 'Valk_Up(\"' + item + '\");');
        var linkToDown = document.createElement('img');
        linkToDown.setAttribute('src', '../images/arrow-down.gif');
        linkToDown.setAttribute('onclick', 'Valk_Down(\"' + item + '\");');
        var linkToModify = document.createElement('img');
        linkToModify.setAttribute('src', '../images/edit.png');
        linkToModify.setAttribute('onclick', 'Valk_Rename(\"' + item + '\");');
        var linkToDelete = document.createElement('img');
        linkToDelete.setAttribute('src', '../images/bad.gif');
        linkToDelete.setAttribute('onclick', 'Valk_Del(\"' + item + '\");');
        var ligneShortcut = document.createElement('li');
        var linkShortcut = document.createElement('a');
        linkShortcut.setAttribute('href', z[item]);
        linkShortcut.innerText = item;
        first == false ? ligneShortcut.appendChild(linkToUp): first = false;
        ligneShortcut.appendChild(linkToDown);
        ligneShortcut.appendChild(linkToModify);
        ligneShortcut.appendChild(linkToDelete);
        ligneShortcut.appendChild(linkShortcut);
        menuToAdd.appendChild(ligneShortcut);
    }
    //test();

}

function Valk_Add(){
    var nom=prompt('Nom du shortcut ?');
    if (nom!==null){
        var z = localStorage.getItem('EdenyaShortcut');
        z = JSON.parse(z);
        z[nom]=document.URL;
        localStorage.setItem('EdenyaShortcut',JSON.stringify(z));
        Valk_Refresh();
    }
}

function Valk_Up(itemIn){
    var previous = null;var y={};
    var z = localStorage.getItem('EdenyaShortcut');
    z = JSON.parse(z);
    for (let item in z) {
        if (previous != null){
            if (item == itemIn){
                y[item]=z[item];
            }
            for (bidule in previous){
                if (bidule != itemIn){
                    y[bidule]=previous[bidule];
                }
            }
        };
        previous={};
        previous[item]=z[item]
        ;
    }
    for (var bidule in previous) {
        if (bidule != itemIn){
            y[bidule]=previous[bidule];
        }
    }
    localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();
}

function Valk_Down(itemIn) {
    var next = null;
    var y = {};
    var z = localStorage.getItem('EdenyaShortcut');
    z = JSON.parse(z);
    for (var item in z) {
        if (item != itemIn) {
            y[item] = z[item];
            if (next != null) {
                for (var bidule in next) {
                    y[bidule] = next[bidule];
                }
                next = null;
            }
        }else {
            next = {};
            next[item] = z[item];
        }
    }
    localStorage.setItem('EdenyaShortcut', JSON.stringify(y));
    Valk_Refresh();
}
function Valk_Rename(itemIn){
    var nom=prompt('A renommer en ?');
    if (nom!==null){
        var y = {};
        var z = localStorage.getItem('EdenyaShortcut');
        z = JSON.parse(z);
        for (var item in z) {
            if(item == itemIn){
                y[nom]=z[item];
            }else{
                y[item]=z[item];
            }
        };
        localStorage.setItem('EdenyaShortcut',JSON.stringify(y));
        Valk_Refresh();
    }
}
(function () {
    'use strict';
    checkMessages();
    // Vérification de la présence de la variable localStorage EdenyaColor
    // et instanciation de base si nécessaire
    var localColor = localStorage.getItem('EdenyaColor');
    if (localColor === null) {
        localColor = {};
        localColor.cadre2 = '#dda0dd';
        localColor.ligneA = '#000000';
        localColor.dialogue = '#ffffff';
        localColor.narration = '#ffd700';
        localColor.cri = '#9acd32';
        localColor.hj = '#FFDAB9';
        localColor.BlackDate = '#B09070';
        localStorage.setItem('EdenyaColor', JSON.stringify(localColor));
        localColor = localStorage.getItem('EdenyaColor');
    }

    var localColorParsed = JSON.parse(localColor);
    if (localColorParsed.BlackDate === undefined) {
        localColorParsed.BlackDate = '#B09070';
        localStorage.setItem('EdenyaColor', JSON.stringify(localColorParsed));
    }

    // Remplacement des dates écrites en noir dans les forums.
    var x = document.getElementsByTagName("font");
    for (var i = 0; i < x.length; i++) {
        if (x[i].getAttribute('color') !== null) {
            x[i].setAttribute('color', (x[i].getAttribute('color')).replace('#000000', localColorParsed.BlackDate));
            x[i].setAttribute('color', (x[i].getAttribute('color')).replace('#990000', '#FF0000'));
            x[i].setAttribute('color', (x[i].getAttribute('color')).replace('\\"', ''));
            x[i].setAttribute('color', (x[i].getAttribute('color')).replace('\\"', ''));
        }
    }

    // Colorisation des éléments
    var baliseHeader = document.querySelector('head');
    var styleToAdd = document.createElement('style');
    for (var item in localColorParsed) {
        styleToAdd.innerText += '.' +item + '{color:'+ localColorParsed[item]+'}';
    }
    styleToAdd.innerText += 'menu#menuValk {padding:0px;list-style-type: none;-webkit-padding-start: 0px;};';
    baliseHeader.appendChild(styleToAdd);

    var scriptToAdd = document.createElement('script');
    scriptToAdd.setAttribute('type',"text/javascript");
    var t = document.createTextNode("function Valk_Del(item){var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);delete z[item];localStorage.setItem('EdenyaShortcut',JSON.stringify(z));Valk_Refresh();}\n");
    scriptToAdd.appendChild(t);
    t = document.createTextNode("function Valk_Refresh(){var first = true; var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);var menuToAdd = document.getElementById('menuValk');menuToAdd.innerText='';for (item in z) {var linkToUp = document.createElement('img');linkToUp.setAttribute('src', '../images/arrow-up.gif');linkToUp.setAttribute('onclick', 'Valk_Up(\"' + item + '\");');var linkToDown = document.createElement('img');linkToDown.setAttribute('src', '../images/arrow-down.gif');linkToDown.setAttribute('onclick', 'Valk_Down(\"' + item + '\");');var linkToModify = document.createElement('img');linkToModify.setAttribute('src', '../images/edit.png');linkToModify.setAttribute('onclick', 'Valk_Rename(\"' + item + '\");');var linkToDelete = document.createElement('img');linkToDelete.setAttribute('src', '../images/bad.gif');linkToDelete.setAttribute('onclick', 'Valk_Del(\"' + item + '\");');var ligneShortcut = document.createElement('li');var linkShortcut = document.createElement('a');linkShortcut.setAttribute('href', z[item]);linkShortcut.innerText = item;first == false ? ligneShortcut.appendChild(linkToUp): first = false;ligneShortcut.appendChild(linkToDown);ligneShortcut.appendChild(linkToModify);ligneShortcut.appendChild(linkToDelete);ligneShortcut.appendChild(linkShortcut);menuToAdd.appendChild(ligneShortcut);}}");
    scriptToAdd.appendChild(t);
    t = document.createTextNode("function Valk_Add(){var nom=prompt('Nom du shortcut ?');if (nom!==null){var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);z[nom]=document.URL;localStorage.setItem('EdenyaShortcut',JSON.stringify(z));Valk_Refresh();}}");
    scriptToAdd.appendChild(t);
    t = document.createTextNode("function Valk_Up(itemIn){var previous = null;var y={};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if (previous != null){if (item == itemIn){y[item]=z[item];}for (bidule in previous){if (bidule != itemIn){y[bidule]=previous[bidule];}}};previous={};previous[item]=z[item];}for (bidule in previous) {if (bidule != itemIn){y[bidule]=previous[bidule];}}localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();}");
    scriptToAdd.appendChild(t);
    t = document.createTextNode("function Valk_Down(itemIn) {var next = null;var y = {};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if (item != itemIn) {y[item] = z[item];if (next != null) {for (bidule in next) {y[bidule] = next[bidule];}next = null;}}else {next = {};next[item] = z[item];}}localStorage.setItem('EdenyaShortcut', JSON.stringify(y));Valk_Refresh();}");
    scriptToAdd.appendChild(t);
    t = document.createTextNode("function Valk_Rename(itemIn){var nom=prompt('A renommer en ?');if (nom!==null){var y = {};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if(item == itemIn){y[nom]=z[item];}else{y[item]=z[item];}};localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();}}");
    scriptToAdd.appendChild(t);
    baliseHeader.appendChild(scriptToAdd);

    var locationPath = window.location.pathname.split("/");
    if (locationPath[locationPath.length - 2] == "_vahal" && locationPath[locationPath.length - 1] == "index.php"){
        // Positionnement sur la colone de gauche pour y ajouter les éléments (raccourcis et gestion des couleurs)
        x = document.querySelector(".menu");
        if (x !== null) {
            var imgScript = document.createElement("img");
            imgScript.src = "images/interface/jour/pluie/chains.gif";
            x.appendChild(imgScript);
            var divScript = document.createElement("div");
            var checkMsg = document.createElement("div");
            checkMsg.setAttribute('id','ValkHidden');
            divScript.appendChild(checkMsg);

            var localShortcut = localStorage.getItem('EdenyaShortcut');
            if (localShortcut === null) {
                var shortcut = { 'accueil': 'https://www.edenya.net/_vahal/' };
                localStorage.setItem('EdenyaShortcut', JSON.stringify(shortcut));
                localShortcut = localStorage.getItem('EdenyaShortcut');
            }
            var localShortcutParsed = JSON.parse(localShortcut);

            var titre = document.createElement("p");
            var linkToAdd = document.createElement("span");

            linkToAdd.innerHTML = "<a href='#'> Ajouter </a>";
            linkToAdd.setAttribute("onclick", "Valk_Add()");
            titre.innerText = "Raccourcis : ";
            titre.appendChild(linkToAdd);
            divScript.appendChild(titre);
            var menuToAdd = document.createElement("menu");
            menuToAdd.setAttribute("id","menuValk");
            divScript.appendChild(menuToAdd);

            divScript.className = "cadre";
            divScript.style = "width:194";
            x.appendChild(divScript);
            titre = document.createElement("p");
            titre.innerText = "Couleurs utilisées :";
            divScript.appendChild(titre);
            // Refresh des raccourcis mémorisés
            Valk_Refresh();

            var localTips = localStorage.getItem('EdenyaTips');
            if (localTips === null) {
                localTips = {};
                localTips.cadre2 = "Couleur générale titre, panneau PJ,...";
                localTips.ligneA = "Couleur texte hors balises RP";
                localTips.dialogue = "Texte d'un dialogue";
                localTips.narration = "Texte de narration";
                localTips.cri = "Texte crié";
                localTips.hj = "descriptions HJ";
                localTips.BlackDate = "couleur des dates dans les forums";
                localStorage.setItem('EdenyaTips', JSON.stringify(localTips));
                localTips = localStorage.getItem('EdenyaTips');
            }
            var localTipsParsed = JSON.parse(localTips);

            for (item in localColorParsed) {
                var inputColor = document.createElement("input");
                inputColor.setAttribute("id", item);
                inputColor.setAttribute("type", "color");
                inputColor.setAttribute("class", "bouton");
                inputColor.setAttribute("value", localColorParsed[item]);
                inputColor.setAttribute("style", "width:25;padding:0");
                inputColor.setAttribute("onChange", "var z = localStorage.getItem('EdenyaColor');z = JSON.parse(z);z['" + inputColor.getAttribute("id") + "'] = document.getElementById('" + inputColor.getAttribute("id") + "').value; localStorage.setItem('EdenyaColor',JSON.stringify(z));location.href = location.href;");
                inputColor.setAttribute("onMouseOver", "ShowHelpTab('<b>Usage :</b><br>"+localTipsParsed[item]+"')");
                inputColor.setAttribute("onMouseOut", "HideHelp()");
                inputColor.title = localTipsParsed[item];
                divScript.appendChild(inputColor);
            }
            var localPreview = localStorage.getItem('EdenyaPreview');
            if(localPreview === null) {
                localPreview = true;
                localStorage.setItem('EdenyaPreview', localPreview);
            }
            var localPreviewParsed = JSON.parse(localPreview);
            var checkPreview = document.createElement("input");
            checkPreview.setAttribute("type","checkbox");
            checkPreview.checked = localPreviewParsed;
            checkPreview.setAttribute ("onclick", "localStorage.setItem('EdenyaPreview', !JSON.parse(localStorage.getItem('EdenyaPreview')));");
            var spanTmp = document.createElement("span");
            spanTmp.innerText = "Prévisualisation de post : ";
            spanTmp.appendChild(checkPreview);
            spanTmp.setAttribute('style', 'display:block;');
            divScript.appendChild(spanTmp);
        }
        x = document.getElementsByClassName("contenu");
        var zz = x[0].getElementsByClassName("cadre")[0];
        if(zz.width == "80%"){
            zz.style.height = "50px";
        }
    }
    if (locationPath[locationPath.length - 2] == "_vahal" && locationPath[locationPath.length - 1] == "vide.php" && ((document.getElementsByClassName("titre"))[0]).innerText == "Nouveau message" && JSON.parse(localStorage.getItem('EdenyaPreview'))){
        var boutonSubmit = document.getElementsByName('Submit')[0];
        var pParent = boutonSubmit.parentElement;
        var boutonPreview = document.createElement('button');
        boutonPreview.innerText = "Prévisualiser";
        boutonPreview.className = "bouton";
        boutonPreview.setAttribute("type", "button");
        pParent.appendChild(boutonPreview);
        var toAddTextarea = (document.getElementsByName('message')[0]).parentElement.parentElement.parentElement.parentElement.parentElement;
        var lineToDivide = document.createElement('hr');
        toAddTextarea.appendChild(lineToDivide);
        var elementToAdd = document.createElement('div');
        elementToAdd.setAttribute('id','previewText');
        elementToAdd.setAttribute("style","text-align:left;");
        toAddTextarea.appendChild(elementToAdd);
        var line2ToDivide = document.createElement('hr');
        toAddTextarea.appendChild(line2ToDivide);
        toAddTextarea.appendChild(pParent);
        boutonPreview.setAttribute("onclick","(document.getElementsByName('Submit')[0]).disabled = false;var initial_texte = ((document.getElementsByName('message'))[0]).value;var regexpOpen = /\\[(narration|dialogue|cri|hj|ecriture)\\]/g;var regexpClose = /\\[\\/(narration|dialogue|cri|hj|ecriture)\\]/g;var previsu_texte = initial_texte.replace(regexpOpen, '<span class=\\'$1\\'>');previsu_texte = previsu_texte.replace(regexpClose, '</span><!--$1-->');var regexpImg = /\\[img\\]([^\\[]*)\\[\\/img\\]/g;previsu_texte = previsu_texte.replace(regexpImg, '<img src=\\'$1\\' border=\\'0\\'\\/>');previsu_texte = previsu_texte.replace(/\\n/g, '<'+'br/>');document.getElementById('previewText').innerHTML = previsu_texte;");
//        boutonPreview.setAttribute("onclick","(var initial_texte = ((document.getElementsByName('message'))[0]).value;var regexpOpen = /\\[(narration|dialogue|cri|hj|ecriture)\\]/g;var regexpClose = /\\[\\/(narration|dialogue|cri|hj|ecriture)\\]/g;var previsu_texte = initial_texte.replace(regexpOpen, '<span class=\\'$1\\'>');previsu_texte = previsu_texte.replace(regexpClose, '</span><!--$1-->');var regexpImg = /\\[img\\]([^\\[]*)\\[\\/img\\]/g;previsu_texte = previsu_texte.replace(regexpImg, '<img src=\\'$1\\' border=\\'0\\'\\/>');previsu_texte = previsu_texte.replace(/\\n/g, '<'+'br/>');document.getElementById('previewText').innerHTML = previsu_texte;");
    }
})();