// ==UserScript== // @name nicer // @author Shaddow // @namespace http://www.newds.cz/ // @description textarea nicer v2 // @include http://www.newds.cz/* // @exclude http://www.newds.cz/main.php?goto=book* // @exclude http://www.newds.cz/main.php?goto=settings* // @exclude http://www.newds.cz/main.php?goto=friend* // @exclude http://www.newds.cz/main.php?goto=category* // @exclude http://www.newds.cz/main.php?goto=new* // @exclude http://www.newds.cz/main.php?goto=stat* // @exclude http://www.newds.cz/main.php?goto=search* // @exclude http://www.newds.cz/main.php?goto=live* // @exclude http://www.newds.cz/main.php?goto=online* // @exclude http://www.newds.cz/main.php?goto=games* // @exclude http://www.newds.cz/main.php?goto=help* // @exclude http://www.newds.cz/main.php?goto=stat* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js // ==/UserScript== (function($){$.fn.nicer=function(){function oznackovat(textarea_name,tagOpen,tagClose,sampleText){var txtarea=document.getElementById(textarea_name);if(tagOpen=='\"'){var url=prompt('Vlozte prosim adresu odkazu','http://');if(url!=null)tagClose="\":["+url+"]"}var was_space=0;if(document.selection&&!is_gecko){var theSelection=document.selection.createRange().text;if(!theSelection)theSelection=sampleText;txtarea.focus();if(theSelection.charAt(theSelection.length-1)==" "){theSelection=theSelection.substring(0,theSelection.length-1);was_space=1}if(theSelection.charAt(0)==" "){theSelection=theSelection.substring(1,theSelection.length);if(was_space==1)was_space=3;else was_space=2}if(was_space==1)document.selection.createRange().text=tagOpen+theSelection+tagClose+" ";else if(was_space==2)document.selection.createRange().text=" "+tagOpen+theSelection+tagClose;else if(was_space==3)document.selection.createRange().text=" "+tagOpen+theSelection+tagClose+" ";else document.selection.createRange().text=tagOpen+theSelection+tagClose}else if(txtarea.selectionStart||txtarea.selectionStart=='0'){var replaced=false;var startPos=txtarea.selectionStart;var endPos=txtarea.selectionEnd;if(endPos-startPos)replaced=true;var scrollTop=txtarea.scrollTop;var myText=(txtarea.value).substring(startPos,endPos);if(!myText)myText=sampleText;if(myText.charAt(myText.length-1)==" "){was_space=1}if(myText.charAt(0)==" "){if(was_space==1)was_space=3;else was_space=2}if(was_space==1)subst=tagOpen+myText.substring(0,(myText.length-1))+tagClose+" ";else if(was_space==2)subst=" "+tagOpen+myText.substring(1,myText.length)+tagClose;else if(was_space==3)subst=" "+tagOpen+myText.substring(1,myText.length-1)+tagClose+" ";else subst=tagOpen+myText+tagClose;txtarea.value=txtarea.value.substring(0,startPos)+subst+txtarea.value.substring(endPos,txtarea.value.length);txtarea.focus();if(replaced){var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);txtarea.selectionStart=cPos;txtarea.selectionEnd=cPos}else{txtarea.selectionStart=startPos+tagOpen.length;txtarea.selectionEnd=startPos+tagOpen.length+myText.length}txtarea.scrollTop=scrollTop}if(txtarea.createTextRange)txtarea.caretPos=document.selection.createRange().duplicate()}function trim(str){return str.replace(/^\s*|\s*$/g,"").replace(/\s+/," ")}function linker(){var gm_url=$('#gm_linker_url').val();if(gm_url){gm_url=(gm_url.match('^http://')?gm_url:'http://'+gm_url);if(gm_url.match(/(jpg|png|gif|bmp|jpeg)$/i)){$('#msg').val(($('#msg').val()?$('#msg').val()+'\n':'')+'img:'+gm_url);$('#gm_linker_url').val('');$('#gm_linker').hide();$('#msg')[0].focus()}else{$('#gm_linker_url').val('pripajam');GM_xmlhttpRequest({method:"GET",url:"http://newds.shaddow.sk/greasemonkey/linker/parse.php?url="+encodeURIComponent(gm_url),onload:function(xhr){console.log(xhr);var response=eval("("+xhr.responseText+")");$.each(response.page,function(i,item){if(item.t!=null){$('#msg').val(($('#msg').val()?$('#msg').val()+'\n\n':'')+''+trim(item.t)+'\n'+(gm_url.match('^http://www.youtube.com')?'\nyoutube:'+gm_url.replace(/^[^v]+v.(.{11}).*/,"$1"):gm_url+(item.d?'\n\n'+item.d:'')));$('#gm_linker_url').val('');$('#gm_linker').hide();$('#msg')[0].focus()}else $('#gm_linker_url').val(gm_url)})},onerror:function(){return false}})}}}return this.each(function(){obj=$(this);var pos=obj.position();$('body').prepend('
');obj.attr('id','msg').css({'width':$('textarea').width()-22+'px','min-height':'110px','margin-left':'22px'});$('#nicer').css({'position':'absolute','top':pos.top+'px','left':pos.left+'px','width':'22px','height':$('textarea').outerHeight()+'px','background-color':'#DDDDDD'}).append('').append('').append('').append('').append('');$('').hide().appendTo('#pis').append(' ');$('#nicer a').css({'display':'block','width':'16px','height':'16px','float':'left','padding':'1px','margin':'2px','-moz-border-radius':'3px'}).hover(function(){$(this).css({'background':'#EBEBEB','outline':'1px solid #999999'})},function(){$(this).css({'background':'none','outline':'none'})});$('#nicer a img').css({'vertical-align':'text-top'});$('#nicer a').click(function(){if($(this).children('img').attr('title')=="bold")oznackovat('msg','','','text');else if($(this).children('img').attr('title')=="italic")oznackovat('msg','','','text');else if($(this).children('img').attr('title')=="underline")oznackovat('msg','','','text');else if($(this).children('img').attr('title')=="pre")oznackovat('msg','','','kod');else if($(this).children('img').attr('title')=="odkaz"){$('#gm_linker').toggle();$('#gm_linker_url')[0].focus()}return false});$('#gm_linker_send').click(function(){linker();return false});$('#gm_linker_url').keypress(function(e){if(e.which==13){linker();return false}});$(window).resize(function(){pos=obj.position();$('#nicer').css({'top':pos.top+'px','left':pos.left+'px'})})})}})(jQuery);$('textarea').nicer();$('#msg')[0].focus();