Benutzer:Phorgo/common.js

Aus Stupidedia, der sinnfreien Enzyklopädie!
Wechseln zu: Navigation, Suche

Wichtig: Nach dem Speichern musst Du deinem Browser sagen, dass er die neue Version laden soll: Mozilla/Firefox: Strg-Shift-R, IE: Strg-F5, Safari: Cmd-Shift-R, Konqueror: F5.

// <nowiki>

// Autoblock deaktivieren

if ( mw.config.get( 'wgPageName' ).match( /^Spezial:Sperren(\/.+)?$/ ) !== null ) {
    execute( function() {
        $( '#mw-input-wpAutoBlock:checked' ).trigger( 'click' );
    } );
}

// Editcount

function editcount() {
    var target = decodeURIComponent( $( '#contentSub a:first' ).attr( 'href' ).replace( /^.*Benutzer(in)?(_Diskussion)?:([^\?\&#]+).*$/, '$3' ) );
    api.request( 'action=query&list=users&usprop=editcount&ususers=' + encodeURIComponent( target ), function( data ) {
        document.getElementById( "firstHeading" ).innerHTML += ' (' + data.query.users[0].editcount + ')';
    } );
}

if ( $.inArray( mw.config.get( 'wgCanonicalSpecialPageName' ), ['Contributions', 'DeletedContributions'] ) != -1 ) {
    execute( editcount );
}

// Innerhalb von Spezial:Aktive Benutzer nach der Beitragszahl sortieren

function activeusers_numsort ( a, b ) {
    return a.counter - b.counter;
}

function activeusers_doIt() {
    var bla = $( '#mw-content-text ol li' ).get();
    var blubb = new Array();
    for ( var i = 0; i < bla.length; i++ ) {
        var ghfj = bla[i].innerHTML.indexOf( '[' ) + 1;
        var fngj = bla[i].innerHTML.indexOf( ' ', ghfj );
        var contribsCount = bla[i].innerHTML.slice( ghfj, fngj ).replace( /\./g, '' );
        var fngbjk = { counter: contribsCount, content: bla[i].innerHTML };
        blubb.push( fngbjk );
    }
    blubb.sort( activeusers_numsort );
    blubb.reverse();
    document.getElementById( 'mw-content-text' ).getElementsByTagName( 'ol' )[0].innerHTML = '';
    for ( var i = 0; i < blubb.length; i++ ) {
        document.getElementById( 'mw-content-text' ).getElementsByTagName( 'ol' )[0].innerHTML += '<li>' + blubb[i].content + '</li>';
    }
}

function activeusers_removeGroupies() {
    $.each( $( '#mw-content-text ol li' ), function() {
        var bla = $( this ).html();
        if ( bla.match( /\)<\/span>‏‎ \(/ ) !== null ) {
            $( this ).remove();
        }
    } );
}

function activeusers_removeNormalos() {
    $.each( $( '#mw-content-text ol li' ), function() {
        var bla = $( this ).html();
        if ( bla.match( /\)<\/span>‏‎ \(/ ) === null ) {
            $( this ).remove();
        }
    } );
}

function activeusers_init() {
    $( '#mw-content-text ul' ).wrap( '<ol />' ).replaceWithContent();
    document.getElementById( 'mw-content-text' ).getElementsByTagName( 'fieldset' )[0].innerHTML += ' <input type="button" onclick="activeusers_doIt()" value="Nach Beitragszahl sortieren" /> <input type="button" onclick="activeusers_removeGroupies()" value="Gruppenmitglieder entfernen" /> <input type="button" onclick="activeusers_removeNormalos()" value="Normalos entfernen" />';
    $.each( $( '#mw-content-text ol li' ), function() {
        if ( $( 'a[href$="Stupidedia:Helden_der_Arbeit"]', this ).length > 0 ) {
            $( 'a:first', this ).css( 'color', '#FF4500' ).css( 'font-weight', 'bold' );
        }
        if ( $( 'a[href$="Stupidedia:Funktion%C3%A4re"]', this ).length > 0 ) {
            $( 'a:first', this ).css( 'color', '#800000' ).css( 'font-weight', 'bold' );
        }
        if ( $( 'a[href$="Stupidedia:Diktatoren"]', this ).length > 0 ) {
            $( 'a:first', this ).css( 'color', '#008000' ).css( 'font-weight', 'bold' );
        }
        if ( $( 'a[href$="Stupidedia:Bots"]', this ).length > 0 ) {
            $( 'a:first', this ).css( 'color', '#777777' ).css( 'font-weight', 'bold' );
        }
    } );
}

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Activeusers' ) {
    execute( activeusers_init );
}

// Konsole

openConsole = function() {
    if ( $( '#console' ).length === 0 ) {
        var textarea = $( '<textarea style="-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; width: 700px; height: 300px; background: #FFFFFF; border: none; border-radius: 2px; margin-bottom: 10px;" />' );
        var jsButton = $( '<input type="button" value="JavaScript evaluieren" style="background: #FFFFFF; border: none; border-radius: 2px;" />' ).click( function() {
            $( this ).trigger( 'blur' );
            $.globalEval( textarea.val() );
        } );
        var cssButton = $( '<input type="button" value="CSS evaluieren" style="background: #FFFFFF; border: none; border-radius: 2px;" />' ).click( function() {
            $( this ).trigger( 'blur' );
            addCSS( textarea.val() );
        } );
        var closeButton = $( '<input type="button" value="Schließen" style="background: #FFFFFF; border: none; border-radius: 2px;" />' ).click( function() {
            $( this ).trigger( 'blur' );
            outerDiv.fadeToggle( 'fast' );
        } );
        var innerDiv = $( '<div />' ).append( textarea, '<br />', jsButton, ' ', cssButton, ' ', closeButton );
        var outerDiv = $( '<div id="console" style="display: none; background: #39424B; border-radius: 5px; padding: 10px; z-index: 1000000;" />' ).append( innerDiv ).appendTo( 'body' ).autoCenter().draggable();
    }
    $( '#console' ).fadeToggle( 'fast' );
    $( '#console textarea' ).trigger( 'focus' );
}

// Zeit anzeigen

execute( function() {
    $( '#p-personal ul' ).prepend( '<li id="pt-time">' + time.getText( '$W, $D.$M.$Y, $H:$I:$S:$X' ) + '</li>' );
} );

// Zu Überschrift springen

execute( function() {
    $( '.editsection' ).each( function() {
        var id = $( this ).next().attr( 'id' );
        $( 'a:first', this ).before( '<a href="#' + id + '">Hash</a>', '&nbsp;|&nbsp;' );
    } );
} );

// Redirects sollen nicht weiterleiten

$( 'a.mw-redirect' ).each( function() {
    var link = $( this );
    var url = link.attr( 'href' );
    if ( !url ) {
        return;
    }
    if ( url.indexOf( 'redirect=no' ) !== -1 ) {
        return;
    }
    url = ( url.indexOf( '?' ) === -1 )
        ? url.replace( /([^#]+)(#.*)?/, '$1?redirect=no$2' )
        : url.replace( /([^#]+)(#.*)?/, '$1&redirect=no$2' );
    link.attr( 'href', url );
} );

// diff bzw. oldid anzeigen

execute( function() {
    var diff = mw.util.getParamValue( 'diff' );
    var oldid = mw.util.getParamValue( 'oldid' );
    if ( diff ) {
        var text = 'Diff: ' + diff;
    }
    else if ( oldid ) {
        var text = 'Oldid: ' + oldid;
    }
    else {
        return;
    }
    $( '#p-personal ul' ).prepend( '<li id="pt-revision">' + text + '</li>' );
} );

// <nowiki>

// Stopknopf/Bashknopf
if ( $.inArray( mw.config.get( 'wgNamespaceNumber' ), [0, 102, 104, 106] ) != -1 ) {
    execute( function() {
        // Stop
        mw.util.addPortletLink( 'p-cactions', null, 'Stop!', 'ca-stop', '', '', '' );
        $( '#ca-stop' ).click( function() {
            api.request( 'action=edit&title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&text=' + encodeURIComponent( '{{Stop}}' ) + '&nocreate=true&summary=' + encodeURIComponent( '[[Vorlage:Stop|Stop, zurück zum Anfang!]]' ) + '&token=' + encodeURIComponent( global.editToken ) );
        } );
        // Bash
        mw.util.addPortletLink( 'p-cactions', null, 'Bash!', 'ca-bash', '', '', '' );
        $( '#ca-bash' ).click( function() {
            api.request( 'action=edit&title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&text=' + encodeURIComponent( '{{Bashing}}' ) + '&nocreate=true&summary=' + encodeURIComponent( '[[Vorlage:Bashing|Erzähl mehr von dir!]]' ) + '&token=' + encodeURIComponent( global.editToken ) );
        } );
    } );
}

// Lizenzknopf
if ( mw.config.get( 'wgNamespaceNumber' ) == 6 ) {
    execute( function() {
        mw.util.addPortletLink( 'p-cactions', null, 'Lizenz!', 'ca-license', '', '', '' );
        $( '#ca-license' ).click( function() {
            api.request( 'action=edit&title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&prependtext=' + encodeURIComponent( '{{Lizenz!}}\n' ) + '&nocreate=true&summary=' + encodeURIComponent( '[[Vorlage:Lizenz!|Quelle? Lizenz?]]' ) + '&token=' + encodeURIComponent( global.editToken ) );
        } );
    } );
}

// Exportknopf
if ( mw.config.get( 'wgNamespaceNumber' ) != -1 ) {
    execute( function() {
        mw.util.addPortletLink( 'p-cactions', mw.util.wikiGetlink( 'Spezial:Exportieren/' + mw.config.get( 'wgPageName' ) ), 'Exportieren', 'ca-export', '', '', '' );
    } );
}

// Seite neu parsen
if ( mw.config.get( 'wgNamespaceNumber' ) != -1 ) {
    execute( function() {
        mw.util.addPortletLink( 'p-cactions', null, 'Parsen', 'ca-parse', '', '', '' );
        $( '#ca-parse' ).click( function() {
            api.request( {
                action: 'edit',
                title: mw.config.get( 'wgPageName' ),
                appendtext: '',
                token: global.editToken
            }, function( data ) {
                location.href = mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) );
            } );
        } );
    } );
}

var gGetInfo = new Object();

// Initiieren
gGetInfo.init = function() {
    if ( typeof gGetInfo.showProtection === 'function' ) {
        gGetInfo.showProtection();
    }
}

// Seitenschutzstatus anzeigen
gGetInfo.showProtection = function() {
    // Auf Spezialseiten abbrechen
    if ( mw.config.get( 'wgNamespaceNumber' ) === -1 ) {
        return;
    }
    // Bearbeiten
    if ( global.protection.edit !== '*' && $( '#ca-edit a' ).length !== 0 ) {
        $( '#ca-edit a' ).get()[0].innerHTML += ' (' + global.protection.edit + ')';
    }
    // Verschieben
    if ( global.protection.move !== '*' && $( '#ca-move a' ).length !== 0 ) {
        $( '#ca-move a' ).get()[0].innerHTML += ' (' + global.protection.move + ')';
    }
    // Erstellen
    if ( global.protection.create !== '*' && $( '#ca-edit a' ).length !== 0 ) {
        $( '#ca-edit a' ).get()[0].innerHTML += ' (' + global.protection.create + ')';
    }
    // Hochladen
    if ( global.protection.upload !== '*' && $( '#mw-imagepage-reupload-link a' ).length !== 0 ) {
        $( '#mw-imagepage-reupload-link a' ).get()[0].innerHTML += ' (' + global.protection.upload + ')';
    }
    // Auszeichnen
    if ( global.protection.award !== '*' && $( '#ca-award a' ).length !== 0 ) {
        $( '#ca-award a' ).get()[0].innerHTML += ' (' + global.protection.award + ')';
    }
}

execute( gGetInfo.init );

window.gGetInfo = gGetInfo;

setHook( 'BeforeGadgetExecution', function() {
    gRC.modules.actions.prototype.welcome = {
        title: 'Benutzer begrüßen',
        text: 'Benutzer begrüßen',
        func: function() {
            if ( mw.config.get( 'wgUserName' ) !== 'Phorgo' ) {
                return;
            }
            var change = $.parseJSON( $( this ).attr( 'data-json' ) );
            if ( change.anon !== undefined ) {
                return;
            }
            api.request( {
                action: 'edit',
                title: 'Benutzer Diskussion:' + change.user,
                text: '{{W|Phorgo}}\n* PS: Viel Spaß hier! Falls du Fragen hast, frag: [{{subst:SERVER}}/stupi/Benutzer_Diskussion:Phorgo?posting=1 *klick*]' + global.signature,
                bot: true,
                notminor: true,
                createonly: true,
                summary: 'Moin',
                token: global.editToken
            }, function( data ) {
                if ( data.watch !== undefined ) {
                    gRC.modules.actions.prototype.setResult( change, 'Jo, Nachricht is raus!' );
                    gRC.refresh();
                }
                else {
                    gRC.modules.actions.prototype.setResult( change, data );
                }
            } );
        }
    };

    gRC.modules.actions.prototype.sat = {
        title: 'Öffnet das Werkzeugkastenmodul „Standard & Troll’s“ in einem neuen Fenster und bereitet die Operation vor.',
        text: 'Standard & Troll’s',
        func: function() {
            var change = $.parseJSON( $( this ).attr( 'data-json' ) );
            window.open( mw.util.wikiGetlink( 'Benutzer:Phorgo/Werkzeugkasten' ) + '?troll=' + encodeURIComponent( change.user ) + '#fragment-sat', '_blank' );
        }
    };
} );

window.gSearchHistory = new Object();

window.gSearchHistory.init = function() {
    mw.util.addPortletLink( 'p-cactions', null, 'Versionsgeschichte durchsuchen', 'ca-searchHistory' );
    $( '#ca-searchHistory' ).click( function() {
        var expr = prompt( 'Ausdruck?' );
        var flags = prompt( 'Flags?' );
        if ( expr !== null && flags !== null ) {
            gSearchHistory.regex = new RegExp( expr, flags );
            $( '#gSearchHistory-div' ).remove();
            $( '#mw-history-searchform' ).before( '<div id="gSearchHistory-div"><b>Versionen, auf die der reguläre Ausdruck <code>' + mw.html.escape( gSearchHistory.regex.toString() ) + '</code> passt:</b><ul style="font-family: Courier, monospace;"></ul><img src="http://www.stupidedia.org/images/d/de/Ajax-loader.gif" /></div>' );
            gSearchHistory.search();
        }
    } );
}

window.gSearchHistory.search = function( from ) {
    var obj = {
        action: 'query',
        prop: 'revisions',
        titles: mw.config.get( 'wgPageName' ),
        rvprop: 'content|ids|timestamp',
        rvlimit: 20,
        indexpageids: true
    }
    if ( from !== undefined ) {
        obj.rvcontinue = from;
    }
    api.request( obj, gSearchHistory.receive );
}

window.gSearchHistory.receive = function( data ) {
    var revisions = data.query.pages[data.query.pageids[0]].revisions;
    var content = '';
    $.each( revisions, function() {
        if ( this['*'].match( gSearchHistory.regex ) !== null ) {
            content += '<li><a href="/stupi?oldid=' + this.revid + '">' + this.timestamp + '</a> (diff: <a href="/stupi?oldid=' + this.revid + '&diff=prev">prev</a> | <a href="/stupi?oldid=' + this.revid + '&diff=cur">cur</a> | <a href="/stupi?oldid=' + this.revid + '&diff=next">next</a>)</li>';
        }
    } );
    $( '#gSearchHistory-div ul' ).append( content );
    if ( data['query-continue'] !== undefined ) {
        gSearchHistory.search( data['query-continue'].revisions.rvcontinue );
    }
    else {
        $( '#gSearchHistory-div img' ).remove();
    }
}

if ( mw.config.get( 'wgArticleId' ) !== 0 && mw.config.get( 'wgAction' ) === 'history' ) {
    execute( window.gSearchHistory.init );
}

Linktipps: Faditiva und 3DPresso