// ==UserScript== // @name KAT - Add IMG bbcode // @namespace IMGbbcode // @version 1.03 // @description Allows highlighting url and then clicking or using Ctrl + I to make IMG bbcode // @require https://greasyfork.org/scripts/6250-waitforkeyelements/code/waitForKeyElements.js?version=23756 // @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; function addIMG(jNode) { $(jNode).append(''); $('.bbedit-img').unbind("click"); $('.bbedit-img').bind("click", imgClick); $("textarea").unbind("keydown"); $("textarea").bind("keydown", taKeyDown); } function imgClick() { if (window.getSelection) { var ta = $(this).parent().parent().children("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); } } } function taKeyDown (event) { if (event.ctrlKey && event.which == 73) { event.preventDefault(); $(this).parent().find(".bbedit-img").trigger("click"); } } waitForKeyElements (".bbedit-toolbar", addIMG);