Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          pouetBBCodeToolbar
  3. // @description   Add a bbcode toolbar for pouet
  4. // @include http://pouet.net/*
  5. // @exclude http://pouet.net/
  6. // @exclude http://pouet.net/index.php*
  7. // @include http://www.pouet.net/*
  8. // @exclude http://www.pouet.net/
  9. // @exclude http://www.pouet.net/index.php*
  10. // ==/UserScript==
  11. /*
  12.  * 2013.09.19 Tigrou^ind ( tigrou.ind@gmail.com ).
  13.  */
  14.  
  15. !(function ()
  16. {  
  17.    
  18.     insertTags = function (link, start, end)
  19.     {
  20.         var t = link.parentNode.nextSibling;
  21.         var from = t.selectionStart;
  22.         var to = t.selectionEnd;
  23.  
  24.         t.value = t.value.slice(0, t.selectionStart) + start
  25.              + t.value.slice(t.selectionStart, t.selectionEnd)
  26.              + end + t.value.slice(t.selectionEnd);
  27.        
  28.         t.selectionStart = from + start.length;
  29.         t.selectionEnd = to + start.length;
  30.     }    
  31.    
  32.     var textareas = document.querySelectorAll('textarea');
  33.     for( var i=0; i < textareas.length; i++)
  34.     {
  35.         var spanStyle = 'font-weight:bold;display:inline-block;padding:2px 10px;margin:2px;border:1px solid #9FCFFF';
  36.         var t = textareas[i];
  37.         var d = document.createElement('div');
  38.         d.style.padding = '5px';
  39.         d.style.color =  '#9FCFFF';
  40.        
  41.         d.innerHTML = '<span style="'+spanStyle+'" onclick="insertTags(this, \'[url]\', \'[/url]\')">url</span> ' +
  42.                       '<span style="'+spanStyle+'" onclick="insertTags(this, \'[url=\'+prompt(\'URL\')+\']\', \'[/url]\')">url with text</span> ' +
  43.                       '<span style="'+spanStyle+'" onclick="insertTags(this, \'[img]\', \'[/img]\')">img</span> ' +
  44.                       '<span style="'+spanStyle+';margin-left:10px" onclick="insertTags(this, \'[code]\', \'[/code]\')">code</span> ' +
  45.                       '<span style="'+spanStyle+'" onclick="insertTags(this, \'[quote]\', \'[/quote]\')">quote</span> ' +
  46.                       '<span style="'+spanStyle+';margin-left:10px" onclick="insertTags(this, \'[b]\', \'[/b]\')">bold</span> ' +
  47.                       '<span style="'+spanStyle+'" onclick="insertTags(this, \'[i]\', \'[/i]\')">italic</span>';        
  48.        
  49.         t.parentNode.insertBefore(d, t);
  50.     }
  51. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement