Greasy Fork 还支持 简体中文。

KAT - Add IMG bbcode

Allows highlighting url and then clicking or using Ctrl + I to make IMG bbcode

Stan na 26-07-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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/*
// ==/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('<span class="bbedit-img" title="Use URL" style="background: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAAD9SURBVDhP7ZChskVQFIbvo4iiIAiCKHgAQfAAgiAIZkRBFAVBFERBEAQPIYiCIAqC+7l75ow5o5gTz/3Tv9b+vzVrr5/jA/3DD/UxvCyL7/uYYRhM05ym6e/pVJZlrusKT8zzPMMwLMtq25bOCZOmhSmKQlVVEmf2OLZt03VdkiT8uq6yLNd1ve/7PM9VVdF8h6MoIgRGmed5mqYCTpIkjmPMVe8wiTAMMZSaprGqgFm+aRqM4ziExaAbeBxHsL7vbdumKWCOwiIY9MrfwBhKRVG6rsMLmFvyHX5+zd/DZVkSxSABI145p5gbBAGdE34kTs3BhX8MX/V98HH8ApmOKX9Nyo+KAAAAAElFTkSuQmCC\')"></span>');

$('.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");
    }
});