Sorry, nechce se mi to někam plácatOprav si tam "r a w", smaž mezery :-)
// ==UserScript==
// @name Formatting_Panel
// @namespace http://molhanec.net/lopuch/?n=Main.JohnyG
// @description Prida k textovemu poli tlacitka pro formatovani textu
// @include http://*lopuch.cz/*
// @include http://*lapiduch.cz/*
// @include http://*nyx.cz/*
// @include http://*okoun.cz/*
// @exclude *billboard*
// ==/UserScript==
// inspiration: http://www.thecodebehind.com/code/javascript/examples/javascript-textarea-buttons-bold-italic.aspx
//BLOK NASTAVENI
//
//pokud neni uvedeno jinak, mohou promenne nabyvat hodnot 0 a 1, kdy 0 znamena vypnuto a 1 zapnuto
var wantb = 1; //zapne ci vypne tlacitko B - tucne
var wanti = 1; //tlacitko I - kurzivou
var wantu = 1; //tlacitko U - podrzene
var wantst = 1; //tlacitko ST - skrtle
var wanturl = 1; //tlacitko URL - odkaz
var wantimg = 1; //tlacitko IMG - obrazek
var wantfont = 1; //tlacitko FONT - barva a velikost pisma
var wantspoil = 1; //tlacitko SPOIL - bile spoilery ohranicene hvezdickami
var wantbr = 1; //tlacitko BR - odstavec
var wantcode = 1; //tlacitko CODE - zdrojove kody, atp.
var wantgoto = 1; //tlacitko JDI NA: - prechod na libovolny post v klubu
var wantfilter = 1; //tlacitko FILTR - hledani podle pole pro zadavani textu
var wantnofilter = 1; //tlacitko NEFILTROVAT - zruseni vsech filtru bez nutnosti cistit pole
var wantresize = 1; //zapne ci vypne zmenu velikosti pole pro zadavani textu prispevku, nasledujici dve volby maji vliv pouze kdyz je tato zapnuta
var addwidth = 40; //zde nastavite konkretni navyseni SIRKY editacniho pole (tedy 0 nezmeni sirku, 10 ji navysi o 10 znaku, -10 ji o deset zmensi)
var addheight = 7; //konkretni navyseni VYSKY editacniho pole
//konec nastaveni
var textarea;
var aftertextarea;
var adresa = location.href;
var domena = document.domain;
var loporlap = false;
function link(event) {
try {
var url = prompt('Zadejte adresu odkazu: ', '');
if (url) {
if (textarea.selectionStart < textarea.selectionEnd) {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<a href="' + url + '">' + selection + '</a>' + posttext;
} else {
var str = prompt('Zadejte text odkazu: ', '');
textarea.value = textarea.value + '<a href="' + url + '">' + str + '</a>';
}
}
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function img(event) {
try {
if (textarea.selectionStart < textarea.selectionEnd) {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<img src="' + selection + '" />' + posttext;
} else {
var str = prompt('Zadejte cestu k obrazku: ', '');
if (str) textarea.value = textarea.value + '<img src="' + str + '" />';
}
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function font(event) {
try {
var color = prompt('Zadejte barvu textu: ', '');
var size = prompt('Zadejte velikost fontu: ', '');
if (color || size) {
if (textarea.selectionStart < textarea.selectionEnd) {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
var string_to_write;
string_to_write = '<font';
if (color) { string_to_write = string_to_write +' color="' + color + '"'; }
if (size) { string_to_write = string_to_write +' size="' + size +'"'; }
string_to_write = string_to_write +'>' + selection + '</font>';
textarea.value = pretext + string_to_write + posttext;
} else {
var str = prompt('Zadejte text: ', '');
var string_to_write;
string_to_write = '<font';
if (color) { string_to_write = string_to_write +' color="' + color + '"'; }
if (size) { string_to_write = string_to_write +' size="' + size +'"'; }
string_to_write = string_to_write +'>' + str + '</font>';
textarea.value = textarea.value + string_to_write;
}
}
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function spoil(event) {
try {
if (textarea.selectionStart < textarea.selectionEnd) {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '*<font color="white">' + selection + '</font>*' + posttext;
} else {
var str = prompt('Zadejte text: ', '');
var string_to_write;
textarea.value = textarea.value + '*<font color="white">' + str + '</font>*';
}
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function bold(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<b>' + selection + '</b>' + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function italic(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<i>' + selection + '</i>' + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function strike(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<strike>' + selection + '</strike>' + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function underline(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<u>' + selection + '</u>' + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function br(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '<br>' + selection + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function code(event) {
try {
var pretext = textarea.value.substring(0, textarea.selectionStart);
var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
textarea.value = pretext + '< r a w >' + selection + '</ r a w>' + posttext;
textarea.focus();
event.preventDefault();
}
catch(exception) {
alert(exception.message);
}
}
function gotopost(event) {
var konec = adresa.indexOf("&");
var cislo = document.getElementById('jdi_na_id').value;
if (konec >= 0) adresa = adresa.substring(0,konec);
adresa = adresa + "&to=" + cislo;
if (cislo!='') window.open(adresa,"_top");
event.preventDefault();
}
function filter(event) {
var zadani = textarea.value;
var autor = '';
var text = '';
if (zadani[0]=='@') {
var mezera = zadani.indexOf(' ');
if (mezera>=0) {
autor = zadani.substring(1,mezera);
text = zadani.substring(mezera+1,zadani.length);
}
else {autor = zadani.substring(1,zadani.length);}
}
else {text = zadani;}
if (zadani!='')
{
var istext = adresa.indexOf("&searchtext=");
if (istext >= 0) adresa = adresa.substring(0,istext);
var isauthor = adresa.indexOf("&author=");
if (isauthor >= 0) adresa = adresa.substring(0,isauthor);
if (text!='') {adresa = adresa + "&searchtext=" + text;}
if (autor!='') {adresa = adresa + "&author=" + autor;}
window.open(adresa,"_top");
}
event.preventDefault();
}
function nofilter(event) {
var istext = adresa.indexOf("&searchtext=");
if (istext >= 0) adresa = adresa.substring(0,istext);
var isauthor = adresa.indexOf("&author=");
if (isauthor >= 0) adresa = adresa.substring(0,isauthor);
adresa = adresa + "&searchtext=&author=";
window.open(adresa,"_top");
event.preventDefault();
}
function mouseover(event){
if (domena != "nyx.cz") {
this.style.border = "1px solid #808080";
this.style.backgroundColor = "#E0E0E0";
} else {
this.style.border = "1px solid black";
this.style.backgroundColor = "darkgray";
}
event.preventDefault();
}
function mouseout(event){
if (domena != "nyx.cz") {
this.style.border = "1px solid #A7A6AA";
this.style.backgroundColor = "white";
} else {
this.style.border = "1px solid #808080";
this.style.backgroundColor = "#E0E0E0";
}
event.preventDefault();
}
function create_button(text, listener) {
var button = document.createElement('button');
var txt = document.createTextNode(text);
button.style.font = "10pt Arial";
if (domena != "nyx.cz") {
button.style.border = "1px solid #A7A6AA";
button.style.backgroundColor = "white";
} else {
button.style.border = "1px solid #808080";
button.style.backgroundColor = "#E0E0E0";
}
button.style.cursor = "pointer";
button.style.marginBottom = "2px";
button.style.marginRight = "2px";
switch (text) {
case 'B': button.style.fontWeight = "bold";
break;
case 'I': button.style.fontStyle = "italic";
break;
case 'U': button.style.textDecoration = "underline";
break;
case 'ST': button.style.textDecoration = "line-through";
break;
}
button.insertBefore(txt, null);
button.addEventListener("mouseover", mouseover, false);
button.addEventListener("mouseout", mouseout, false);
button.addEventListener("click", listener, false);
return button;
}
function create_id_input(listener) {
var input = document.createElement('input');
input.setAttribute('id','jdi_na_id');
input.setAttribute('size','8');
input.style.border = "1px solid #A7A6AA";
input.style.backgroundColor = "white";
input.style.height = "20px";
if (navigator.userAgent.indexOf("Gecko") >= 0) input.style.marginBottom = "2px";
input.addEventListener("keydown", function(event)
{
if (!event.altKey && !event.ctrlKey &&!event.shiftKey && event.keyCode==13) listener(event);
}, false);
return input;
}
try {
var textareas = document.getElementsByTagName("textarea");
if ((domena == "www.lopuch.cz") || (domena == "lopuch.cz") || (domena == "www.lapiduch.cz")) loporlap = true;
if (textareas.length) {
if (domena != "nyx.cz") textarea = textareas.item(0);
else textarea = document.getElementById("message_box");
if (loporlap) aftertextarea = textarea.nextSibling;
textarea_parent = textarea.parentNode;
if (wantb) { textarea_parent.insertBefore(create_button('B', bold), textarea); }
if (wanti) { textarea_parent.insertBefore(create_button('I', italic), textarea); }
if (wantu) { textarea_parent.insertBefore(create_button('U', underline), textarea); }
if (wantst) { textarea_parent.insertBefore(create_button('ST', strike), textarea); }
if (wantbr) { textarea_parent.insertBefore(create_button('BR', br), textarea); }
textarea_parent.insertBefore(document.createTextNode('\xA0\xA0\xA0'), textarea);
if (wanturl) { textarea_parent.insertBefore(create_button('URL', link), textarea); }
if (wantimg) { textarea_parent.insertBefore(create_button('IMG', img), textarea); }
if (wantfont) { textarea_parent.insertBefore(create_button('FONT', font), textarea); }
if (wantspoil) { textarea_parent.insertBefore(create_button('SPOIL', spoil), textarea); }
textarea_parent.insertBefore(document.createTextNode('\xA0\xA0\xA0'), textarea);
if (wantcode) { textarea_parent.insertBefore(create_button('CODE', code), textarea); }
if (loporlap) {
if ((adresa.indexOf("klub.php")>=0) && (wantgoto)) {
textarea_parent.insertBefore(document.createTextNode('\xA0\xA0-\xA0\xA0'), textarea);
textarea_parent.insertBefore(create_button('JDI NA: ', gotopost), textarea);
textarea_parent.insertBefore(create_id_input(gotopost), textarea);
}
}
textarea_parent.insertBefore(document.createElement('br'), textarea);
if (loporlap) {
if ((wantfilter) || (wantnofilter)) {
textarea_parent.insertBefore(document.createElement('br'), aftertextarea);
}
if ((adresa.indexOf("klub.php")>=0) && (wantfilter)) {
textarea_parent.insertBefore(create_button('FILTR', filter), aftertextarea);
}
if ((adresa.indexOf("klub.php")>=0) && (wantnofilter)) {
textarea_parent.insertBefore(create_button('NEFILTROVAT', nofilter), aftertextarea);
}
}
if (wantresize) {
textarea.rows = textarea.rows + addheight;
textarea.cols = textarea.cols + addwidth;
}
}
}
catch(exception) {
alert(exception.message);
}
|