// ==UserScript== // @name KAT - Add IMG bbcode // @namespace IMGbbcode // @version 1.02 // @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== // Enabled - 1 - No highlighting / invalid highlight prompts the user to enter the URL - Default // Disabled - 0 - No highlighting / invalid highlight just adds [IMG][/IMG] var promptUser = 1; $(".bbedit-toolbar").append(''); $('.bbedit-img').click(function() { if (window.getSelection) { var ta = $('textarea').get(0); var start = ta.selectionStart; var end = ta.selectionEnd; var text = ta.value.substring(start, end); if(/^https?:\/\/|www/i.test(text)) { ta.value = ta.value.substring(0, start) + '[IMG]' + text + '[/IMG]' + ta.value.substring(end, ta.value.length); } else { var newValue = ta.value.substring(0, start); if (promptUser == 1) { var url=prompt('Image URL: ',''); if(url!==null && url!=='' && /^https?:\/\/|www/i.test(url)) { newValue += '[IMG]' + url + '[/IMG] '; } else { newValue += '[IMG][/IMG] '; } } else { newValue += '[IMG][/IMG] '; } newValue += text + ta.value.substring(end, ta.value.length); ta.value = newValue; if (promptUser == 0 && ta.setSelectionRange) ta.setSelectionRange(start + 5, start + 5); } } }); $("textarea").keydown(function(event) { if (event.ctrlKey && event.which == 73) { event.preventDefault(); $('.bbedit-img').trigger("click"); } });