arabuli

bbcode

Mar 12th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @include http://cpp0x.pl/*
  3. // @include https://cpp0x.pl/*
  4. // @include http://*.cpp0x.pl/*
  5. // @include https://*.cpp0x.pl/*
  6. // ==/UserScript==
  7.  
  8. var channel;
  9. var url;
  10. var data;
  11.  
  12. window.addEventListener("load", function() {
  13.     channel = new MessageChannel();
  14.     channel.port1.onmessage = function(event) {
  15.         if(event.data.msg == "tabFocused")
  16.         {
  17.             url = event.data.url;
  18.             //http://cpp0x.pl/forum/temat/edytuj.php
  19.             var reg = /^(.*)cpp0x.pl\/forum\/temat\/edytuj.php(.*)$/i;
  20.             if(reg.test(url))
  21.             {
  22.            
  23.                 var jq = document.createElement('script');
  24.                 jq.setAttribute('type','text/javascript');
  25.                 jq.setAttribute('src','http://code.jquery.com/jquery-1.6.1.min.js');
  26.                 document.getElementsByTagName('head')[0].appendChild(jq);
  27.                
  28.                 var s = document.createElement('script');
  29.                 s.setAttribute('type','text/javascript');
  30.                 s.innerHTML = 'function tag(tag1,tag2){ var textarea = document.getElementsByTagName("textarea")[0]; if(document.selection){ textarea.focus(); var sel = document.selection.createRange(); sel.text = tag1 + sel.text + tag2;} else{ var dl = textarea.value.length; var pocz = textarea.selectionStart; var koniec = textarea.selectionEnd; var scrollTop = textarea.scrollTop; var scrollLeft = textarea.scrollLeft; var sel = textarea.value.substring(pocz, koniec); var rep = tag1 + sel + tag2; textarea.value =  textarea.value.substring(0,pocz) + rep + textarea.value.substring(koniec,dl); textarea.scrollTop = scrollTop; textarea.scrollLeft = scrollLeft; }}';
  31.                 s.innerHTML += "$('#bbcodebuttonsDiv button').css({'text-decoration': 'none'});";
  32.                 s.innerHTML += "$('.bbcodeTip').css({'float': 'right', 'font-weight': 'normal'});"
  33.                 s.innerHTML += "$('#bbcodebuttonsDiv button').mouseenter(function(){ $('.bbcodeTip').html($(this).attr('tip')); });";
  34.                 s.innerHTML += "$('#bbcodebuttonsDiv button').mouseleave(function(){ $('.bbcodeTip').html(''); });";
  35.                 document.getElementsByTagName('head')[0].appendChild(s);
  36.                
  37.            
  38.                 var divTag = document.createElement("div");
  39.                 divTag.id = "bbcodebuttonsDiv";
  40.                 //divTag.setAttribute("align","center");
  41.                 divTag.style.margin = "0px auto";
  42.                 divTag.className = "bbcodebuttonsDivClass";
  43.              
  44.                 divTag.innerHTML = "<button type=\"button\" onclick=\"tag('[h1]','[/h1]')\" tip=\"Nagłówek 1\">H1</button> ";
  45.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[h2]','[/h2]')\" tip=\"Nagłówek 2\">H2</button> ";
  46.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[h3]','[/h3]')\" tip=\"Nagłówek 3\">H3</button> ";
  47.                
  48.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[b]','[/b]')\" tip=\"Pogrubienie\"><b>B</b></button> ";
  49.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[i]','[/i]')\" tip=\"Kursywa\"><i>I</i></button> ";
  50.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[s]','[/s]')\" tip=\"Przekreślenie\"><s>S</s></button> ";
  51.                
  52.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[sup]','[/sup]')\" tip=\"Indeks górny\">sup</button> ";
  53.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[sub]','[/sub]')\" tip=\"Indeks dolny\">sub</button> ";
  54.                
  55.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[a href=&quot;http://&quot; nazwa=&quot;nazwa&quot;]','')\" tip=\"Odnośnik\">Url</button> ";
  56.                
  57.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[cpp]','[/cpp]')\" tip=\"Kod C++\">C++</button> ";
  58.                 divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[cytat]','[/cytat]')\" tip=\"Cytat\">Cytat</button> ";
  59.                
  60.                 divTag.innerHTML += "<select><option>Odsyłacze wew.</option> <option onclick=\"tag('[doc id= name=&quot;nazwa&quot;]','')\">Dokumentacja</option> <option onclick=\"tag('[tut id= name=&quot;nazwa&quot;]','')\">Kurs</option> <option onclick=\"tag('[art id= name=&quot;nazwa&quot;]','')\">Artykuł</option> <option onclick=\"tag('[t id=&quot;id&quot;]','')\">Temat</option></select> ";
  61.                 divTag.innerHTML += "<select><option>Ramki</option> <option onclick=\"tag('[div]','[/div]')\">Div</option><option onclick=\"tag('[div class=&quot;uwaga&quot;]','[/div]')\">Div:uwaga</option> <option onclick=\"tag('[div class=&quot;tip&quot;]','[/div]')\">Div:tip</option></select> ";
  62.                
  63.                 divTag.innerHTML += "<span class=\"bbcodeTip\"></span>";
  64.                 //divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[div]','[/div]')\">Div</button> ";
  65.                 //divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[div class=&quot;uwaga&quot;]','[/div]')\">Div:uwaga</button> ";
  66.                 //divTag.innerHTML += "<button type=\"button\" onclick=\"tag('[div class=&quot;tip&quot;]','[/div]')\">Div:tip</button> ";
  67.                
  68.                 document.getElementsByTagName('th')[1].appendChild(divTag);
  69.             }
  70.                
  71.         }
  72.     };
  73.        
  74.     data = {msg: "popupChannel"}
  75.        
  76.     opera.extension.postMessage(data, [channel.port2]);
  77. }, false);
Advertisement
Add Comment
Please, Sign In to add comment