PCD15

Just for fun :)

ของเมื่อวันที่ 05-05-2015 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name         PCD15
// @namespace    https://kcw.kddi.ne.jp
// @include      https://kcw.kddi.ne.jp/*
// @version      0.1
// @description  Just for fun :)
// @author       Galac
// @match        http://*/*
// @grant        none
// @require      https://greasyfork.org/scripts/9683-rabbit-encrypt/code/Rabbit%20encrypt.js?version=50281

// ==/UserScript==

var passphrase = '';

function encrypt(mes) {
    if (passphrase != '') {
        var encrypted = CryptoJS.Rabbit.encrypt(mes, passphrase);
        return "Pcd15@" + encrypted;
    } else {
        return mes;
    }
}

function decrypt(textEncrypt) {
    if (passphrase != '') {
        try {
            var decrypted = CryptoJS.Rabbit.decrypt(textEncrypt, passphrase);
            return decrypted.toString(CryptoJS.enc.Utf8);
        } catch (e)
        {
            console.log("Error:" + e.message);
            return "Error format!";
        } 

    } else {
        return textEncrypt;
    }
}


function validUrl() { //just accept rooms, users with a filter
    var acceptLinks = ["rid19625982", "rid25126472", "rid32073382", "rid19629353", "rid28415583"]; //array text of url acceptable
    var currentUrl = window.location.href;
    if (acceptLinks.length > 0){
        for (var i = 0; i< acceptLinks.length; i++){
            if (currentUrl.indexOf(acceptLinks[i]) != -1) {
                return true;
            }
        }
        return false;
    }
    else return false;
}

$(function() {
    passphrase = '1213df34dfdfsdfsdfds'; //next version will return from API :)
    $('#_chatText').on('keydown', function(e){
        if (e.which == 13) {
            if (e.altKey) { // alt/option key is down
                if (validUrl()) {
                    if (this.value.indexOf('Pcd15@') ==  -1 ) {
                        var encrT = encrypt(this.value);
                        this.value = encrT;
                        e.preventDefault();
                    }
                }
            }
        }
    });
    $("#_chatContent").on('mouseover', 'div.chatTimeLineMessageArea', function(e){
        if (validUrl()) {
            //Add title
            var pre = $(this).find("pre");
            if (!pre.attr('dataDec')){
                if (pre.text().indexOf('Pcd15@') != -1) {
                    var encrptVal = pre.text().replace('Pcd15@', '');
                    var decryptVal = decrypt(encrptVal);
                    pre.attr('title', decryptVal);
                    pre.attr('dataDec', 1);
                }
            }
        }

    });

});