HighlightChatLimit

Script for Dreadcast. Features : Light up text input chat when limit's reached and do some funky stuff around it.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name HighlightChatLimit
// @namespace InGame
// @author Ladoria
// @date 20/03/2014
// @version 1.4
// @description Script for Dreadcast. Features : Light up text input chat when limit's reached and do some funky stuff around it.
// @license WTF Public License; http://en.wikipedia.org/wiki/WTF_Public_License
// @include http://www.dreadcast.net/Main
// @compat Chrome
// ==/UserScript==

var fullySecond = false; // true if text already at size limit

// Params [FR]
var fastCompletion = false; // [Âme de beta testeur? (Ahah) Testes les points de suspension. Remplacer 'false' par 'true'], true to enable auto replacing cuted work by '...'
var alertLenght = 20 // [Nombre de caractère restant pour lever l'alerte]
var alertColor = 'orange'; // [Couleur de l'effet pour l'approche de la limite]
var limitColor = 'red'; // [Couleur de l'effet à l'atteinte de la limite]

var animateChatInput = function(e) {
	var textChatLimit = 140;
	var endingPattern = /[\Sa-zA-Z0-9]*[\s|\.]*$/gi; // find a word or spaces or '...'
	
	// limit reached
	if ($("#chatForm .text_chat").val().length >= textChatLimit) {
	
		// add '...' command -> reduce text while it's too large
		if(fastCompletion && fullySecond) {
			do {
				$("#chatForm .text_chat").val($("#chatForm .text_chat").val().replace(endingPattern, '') + '...');
			}
			while ($("#chatForm .text_chat").val().length > textChatLimit);
			
			alertHighlight();
			
			fullySecond = false;
			return;
		}
		
		limitHighlight();
		
		fullySecond = true;
		return;
	}
	
	// approach limit
	if ($("#chatForm .text_chat").val().length >= textChatLimit - alertLenght) {
        alertHighlight();
		return;
	}
	
	// far away from limit
	originalHighlight();
}

function limitHighlight() {
	var nsc1 = '0px 0px 3px 2px ';

	$("#chatForm").css('border-color',limitColor);
	$("#chatForm .text_mode").css('border-color',limitColor);
	$("#chatForm .text_valider").css('background-color',limitColor);
	
	$("#chatForm").css('box-shadow',nsc1 + limitColor);
}

function alertHighlight() {
	var nsc2 = '0px 0px 3px 2px ';

	$("#chatForm").css('border-color',alertColor);
	$("#chatForm .text_mode").css('border-color',alertColor);
	$("#chatForm .text_valider").css('background-color',alertColor);
	
	$("#chatForm").css('box-shadow',nsc2 + alertColor);
}

var c1 = $("#chatForm").css('border-color');
var c2 = $("#chatForm .text_mode").css('border-color');
var c3 = $("#chatForm .text_valider").css('background-color');
var c4 = $("#chatForm").css('box-shadow');

function originalHighlight() {
	$("#chatForm").css('border-color',c1);
	$("#chatForm .text_mode").css('border-color',c2);
	$("#chatForm .text_valider").css('background-color',c3);
	
	$("#chatForm").css('box-shadow',c4);
}

document.addEventListener('keyup', animateChatInput, false);