// ==UserScript== // @name KAT - Add IMG bbcode // @namespace IMGbbcode // @version 1.01 // @description Allows highlighting url and then clicking or using Ctrl + I to make IMG bbcode // @match http://kat.cr/* // @match https://kat.cr/* // @downloadURL none // ==/UserScript== $(".bbedit-toolbar").append(''); $('.bbedit-img').click(function() { if (window.getSelection) { var ta = $('textarea').get(0); var text = ta.value.substring(ta.selectionStart, ta.selectionEnd); if(/^https?:\/\/|www/i.test(text)) { ta.value = ta.value.substring(0, ta.selectionStart) + '[IMG]' + text + '[/IMG]' + ta.value.substring(ta.selectionEnd, ta.value.length); } else { var url=prompt('Image URL: ',''); var newValue = ta.value.substring(0, ta.selectionStart); if(url!==null && url!=='' && /^https?:\/\/|www/i.test(url)) { newValue += '[IMG]' + url + '[/IMG] '; } else { newValue += '[IMG][/IMG] '; } newValue += text + ta.value.substring(ta.selectionEnd, ta.value.length); ta.value = newValue; } } }); $("textarea").keydown(function(event) { if (event.ctrlKey && event.which == 73) { event.preventDefault(); $('.bbedit-img').trigger("click"); } });