Benutzer:FNDE/common.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
// mw.loader.load('//de.wikipedia.org/w/index.php?title=Benutzer:FNDE/InstantReply/core.js&action=raw&ctype=text/javascript');

function bar_setup() {

    // Globale Tastenbelegung: bar_set_option([Action],[Key]);

    bar_set_option('toggle', 'SHIFT'); // Dialog öffnen (Num. 0)
    bar_set_option('close', 'ESC'); // Dialog schließen (ESC)
    bar_set_option('immediately', true); // Benutzerdefinierte Tasten sofort (ohne Dialog) auslösen
	
    // Benuzerdefinierte Tasten: bar_add_bar_item([Key],[Description],[DOM-Element] or [http-Adress]);

    bar_add_bar_item('1', 'Artikel', '#ca-view a'); // Artikel aufrufen (Num. 1)
    bar_add_bar_item('2', 'Bearbeiten', '#ca-edit a'); // Artikel bearbeiten (Num. 2)
    bar_add_bar_item('3', 'Versionen', '#ca-history a'); // Versionen anzeigen (Num. 3)
    bar_add_bar_item('4', 'Shortcuts', 'https://de.wikipedia.org/wiki/Benutzer_Diskussion:FNDE/Shortcuts'); // shortcut link
    bar_add_bar_item('5', 'Beiträge', 'https://de.wikipedia.org/wiki/Spezial:Letzte_%C3%84nderungen?hidebyothers=1&hidebots=1&hidecategorization=1&hideWikibase=1&limit=500&days=0.5&urlversion=2'); // own recent changes

    bar_add_delimiter(true); // Trennlinie einfügen

    bar_add_bar_item('_', 'Gesichtet markieren', '#mw-fr-submit-accept'); // Version als gesichtet markieren (Num. 5)
    
    // bar_add_bar_item('5', 'Vandalismus melden', '#vandalen_melden'); // Vandalismusmeldung (Num. 5)
    // bar_add_bar_item('6', 'Ungesichtete Artikel', 'https://de.wikipedia.org/wiki/Spezial:Seiten_mit_ungesichteten_Versionen');
    // bar_add_bar_item('7', 'Ungesichtete Änderungen', '.fr-diff-to-stable a,#mw-fr-reviewnotice a[href$="&diff=cur"]:first'); // Ungesichtete Änd. anzeigen (Num. 7)

    // bar_add_bar_item('4', 'secWatch', 'https://de.wikipedia.org/wiki/Benutzer:FNDE/Beobachtungsliste');
    // bar_add_bar_item('6', 'Nächste Version', '#differences-nextlink');

    bar_add_delimiter(true); // Trennlinie einfügen
    
    // bar_add_bar_item('5', 'Vandalismus melden', '#vandalen_melden'); // Vandalismusmeldung (Num. 5)
    // bar_add_bar_item('8', 'Zufällige Seite', '#n-randompage a');
    // bar_add_bar_item('✖', 'Dialog schließen', '[close_window]');
    
    // bar_add_delimiter(true); // Trennlinie einfügen

    // bar_add_bar_item('−', 'Benutzer', '#pt-userpage a'); // Eigene Benutzerseite aufrufen (Num. 7)
    bar_add_bar_item('⇐', 'secWatch', 'https://de.wikipedia.org/wiki/Benutzer:FNDE/Beobachtungsliste'); // Zufälliger Artikel
    bar_add_bar_item('↵', 'Beobachtungsliste', '#pt-watchlist a'); // Beobachtungsliste aufrufen (Num. 9)
	
    bar_add_delimiter(true); // Trennlinie einfügen
	
    bar_add_bar_item('×', 'Fenster schließen', '[exit_window]'); // Fenster Schließen (Num. Multipl.)
	
    // Design-Parameter: bar_set_option([Prefix],[Color]);
	
    bar_set_option('bg_color', 'rgba(17,17,17,0.95)'); // Hintergrundfarbe (Overlay)
    bar_set_option('box_border_color', '#d12727'); // Farbe der Umrandung (Dialog)
    bar_set_option('box_bg_color', '#291111'); // Hintergrundfarbe (Dialog)
    bar_set_option('line_color', '#d12727'); // Farbe der Umrandung (Trennlinie)
    bar_set_option('text_color', '#ffffff'); // Textfarbe (Bezeichnung)
    bar_set_option('key_color', '#ffffcc'); // Textfarbe (Taste)

}

// ##########################################################################
// ##### Name: WikiBar.js ###################################################
// ##### Version: 0.0.3-beta ################################################
// ##### Letzte Änderung: 14.01.2017 ########################################
// ##### Autor: FNDE [[Benutzer:FNDE/Script/WikiBar]] #######################
// ##########################################################################

function bar_set_option(action, value) {

    switch (action) {

        case 'toggle':
            bar_config.toggle = bar_charcode[value];
            break;

        case 'close':
            bar_config.close = bar_charcode[value];
            break;

        case 'immediately':
            bar_config.immediately = value;
            break;

        case 'bg_color':
            bar_config.bg_color = value;
            break;

        case 'text_color':
            bar_config.text_color = value;
            break;

        case 'key_color':
            bar_config.key_color = value;
            break;

        case 'box_bg_color':
            bar_config.box_bg_color = value;
            break;

        case 'box_border_color':
            bar_config.box_border_color = value;
            break;

        case 'line_color':
            bar_config.line_color = value;
            break;

    }

}

function bar_add_bar_item(key, action, condition) {

    bar_item = new Object();

    bar_item.key = key;
    bar_item.action = action;
    bar_item.condition = condition;

    bar_settings[bar_settings_array] = bar_item;
    bar_settings_array = bar_settings_array + 1;

}

function bar_add_delimiter(bool) {

    if (bool === true) {

        bar_item = new Object();
        bar_item.delimiter = true;

        bar_settings[bar_settings_array] = bar_item;
        bar_settings_array = bar_settings_array + 1;

    }

}

function bar_append_overlay() {

    $('body').append('<style>.custom_wiki_div_mode { display: inline; padding: 3px; padding-right: 6px; background-color: transparent !important; } .custom_wiki_highlight * { color: #000 !important; }' +
        '.custom_wiki_highlight { background-color: #f0e001 !important; color: #000 !important; } .custom_wiki_line { position: relative; left: -20px; border-top: 1px solid ' + bar_config.line_color + '; opacity: 0.3; width: 210px;' +
        'margin-top: 8px; padding-bottom: 10px; background: transparent !important; } #custom_wiki_inline { border-radius: 7px; z-index: 999; background-color: ' + bar_config.box_bg_color + ' !important; opacity: 1; padding: 20px;' +
        'border: 2px solid ' + bar_config.box_border_color + '; } #custom_wiki_toolbar { display: none;z-index: 100; font-size: 16pt; position: fixed; top: 0px; left: 0px; background-color: ' + bar_config.bg_color + ' !important; color: ' + bar_config.text_color + ' !important;' +
        'width: 100%; height: 100%; padding: 150px; padding-left: 35%; line-height: 40px; } #custom_wiki_inline .custom_wiki_hoch { position: relative; top: -1px; padding-right: 2px; padding-left: 2px; } #custom_wiki_inline b { color: ' + bar_config.key_color + '; }</style>');

    $('body').append('<div id="custom_wiki_toolbar"><div id="custom_wiki_inline"></div></div>');

    $('#custom_wiki_toolbar').hide();

    bar_append_bar_items();

}

function bar_append_action(value, index, type) {

    $('#custom_wiki_inline').append('<div id="custom_wiki_op_' + index + '" class="custom_wiki_div_mode"><span class="custom_wiki_hoch">(</span><b>' + value.key + '</b><span class="custom_wiki_hoch">)</span> ' + value.action + '</div><br>');

    $(document).keydown(function(event) {

        if (event.keyCode == bar_charcode[value.key] && (bar_toggle_status === true || (bar_config.immediately == true && !$(".ext-discussiontools-ui-replyWidget-headerWrapper").length && !$("textarea,input").is(":focus")))) {

            $("#custom_wiki_op_" + index).addClass("custom_wiki_highlight");

            if (type == 1) {

                $(value.condition)[0].click();
				
                if ($(value.condition).prop('tagName') != 'A' || $(value.condition).attr('href') == '#') {

                    $('html, body').animate({
                        scrollTop: $(value.condition).offset().top - 300
                    }, 150);
					
                    bar_close_overlay();

                }

            } else if (type == 2) {
                window.location.href = value.condition;
            } else if (type == 3) {

                switch (value.condition) {
                    case '[close_window]':
                    bar_close_overlay();
                        break;
                    case '[exit_window]':
                    window.close();
                        break;
                }

            }

            if (bar_config.immediately == false) {
                bar_toggle_status = false;
            } else {
                bar_config.immediately = false;
                setTimeout(function() {
                    bar_config.immediately = true;
                }, 150);

            }

        }

    });

}

Object.size = function(obj) {
    var size = 0,key;
    for (key in obj) {
        
		if (obj.hasOwnProperty(key)) size++;
		
    }
    return size;
};

function bar_close_overlay() {

    bar_toggle_status = false;
	
    $("#custom_wiki_toolbar").fadeOut(100, function() {
		
    $("#custom_wiki_inline div").removeClass('custom_wiki_highlight');
	
    });

}

$.fn.hasAttr = function(name) {
	
    return this.attr(name) !== undefined;
	
};

function bar_append_bar_items() {

    var loop = 1;
    var bar_settings_size = Object.size(bar_settings);
	var is_delimiter = false;

    $.each(bar_settings, function(index, value) {

        if (value.delimiter === undefined) {

            if (value.condition.indexOf("http://") == -1 && value.condition.indexOf("https://") == -1) {

                if ($(value.condition).length && !$(value.condition).hasAttr('disabled')) {

                    bar_append_action(value, index, 1);
                    loop = loop + 1;
					is_delimiter = false;

                } else if (value.condition.charAt(0) == '[' && value.condition.charAt(value.condition.length - 1) == ']') {

                    bar_append_action(value, index, 3);
                    loop = loop + 1;
					is_delimiter = false;

                }

            } else {

                bar_append_action(value, index, 2);
                loop = loop + 1;
				is_delimiter = false;

            }

        } else {
			
            if (loop != bar_settings_size && loop != 1 && is_delimiter==false) {
				
                $('#custom_wiki_inline').append('<div class="custom_wiki_line"></div>');
				is_delimiter = true;
				
            }
			
            loop = loop + 1;
        }

    });

}

function bar_keybind_global() {

    $(document).keydown(function(event) {

        if (event.keyCode == bar_config.close) {
            bar_close_overlay();
        }

        if (event.keyCode == bar_config.toggle && !$(".ext-discussiontools-ui-replyWidget-headerWrapper").length && !$("textarea,input").is(":focus")) {

            if ($('#custom_wiki_toolbar').is(':visible')) {
                bar_toggle_status = false;
            } else {
                bar_toggle_status = true;
            }

            $("#custom_wiki_toolbar").fadeToggle(100);

        }

    });

}

var bar_settings = new Object();
var bar_config = new Object();
var bar_toggle_status = false;
var bar_settings_array = 0;
var bar_item;

var bar_charcode = new Object({

    '0': 48,
    '1': 49,
    '2': 50,
    '3': 51,
    '4': 52,
    '5': 53,
    '6': 54,
    '7': 55,
    '8': 56,
    '9': 57,
    'F1': 112,
    'F2': 113,
    'F3': 114,
    'F4': 115,
    'F5': 116,
    'F6': 117,
    'F7': 118,
    'F8': 119,
    'F9': 120,
    'F10': 121,
    'F11': 122,
    'F12': 123,
    '&#10006;': 106, // multiply
    '&times;': 106, // multiply
    '&plus;': 107, // plus
    '&minus;': 109, // minus
    '&#247;': 111, // divide
    ',': 110, // null comma
    'DEL': 46, // delete
    'INS': 45, // insert
    '&#8593;': 38, // arrow up
    '&#8595;': 40, // arrow down
    '&#8592;': 37, // arrow left
    '&#8594;': 39, // arrow right
    'END': 35, // end page
    'HOME': 34, // top page
    '_': 32, // blank
    'ESC': 27, // escape
    '&#8656;': 8, // backspace
    'ALT': 18,
    'SHIFT': 16,
    'ENTER': 13,
    '&crarr;': 13,
    'TAB': 9

});

function thanks() {
	
	console.log('thanks() loaded');
	
    $('.mw-thanks-thank-link').addClass('mw-thanks-thank-link-repl');
    $('.mw-thanks-thank-link').removeClass('mw-thanks-thank-link');

    $('.mw-thanks-thank-link-repl').click(function(event) {

        $par = $(this);

        $par.css({
            'color': 'gray',
            'text-decoration': 'none',
            'pointer-events': 'none'
        })

        $par.text('...');

        event.preventDefault();
        $par.off();

        // Send the API request.
        (new mw.Api()).postWithToken('csrf', {
                action: 'thank',
                rev: $par.data('revision-id'),
            })
            .then(

                // Success
                function(data) {

                    // write cookie
                    mw.thanks.thanked.push($par);

                    // append message after link
                    $('<span style="color:green;">erfolgreich</span>').insertAfter($par);

                    // remove link
                    $par.remove();

                },

                // Fail
                function(errorCode) {

                    // append message after link
                    $('<span style="color:red;">Fehler: ' + errorCode + '</span>').insertAfter($par);

                    // remove link
                    $par.remove();

                }
            );

    });
	
}

$(window).ready(function() {

    if (typeof bar_setup == 'function') {

        bar_setup();

    } else {
	
        alert('WikiBar: Setup() not found!');
		
    }

    bar_append_overlay();
    bar_keybind_global();
    
    /* one click thanks */

mw.loader.load('https://meta.wikimedia.org/w/index.php?title=User:FNDE/thanks.js&action=raw&ctype=text/javascript');

    /* end */

});