MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus VoWi
Zur Navigation springen Zur Suche springen
(update paths)
Zeile 56: Zeile 56:
 
}
 
}
  
if (document.location.pathname == "/wiki/Startseite/TU_Wien/Informatik"){
+
if (document.location.pathname == "/wiki/TU_Wien/Informatik"){
 
     var bubble = document.getElementById('mascot-says-bubble');
 
     var bubble = document.getElementById('mascot-says-bubble');
 
     var img = document.createElement('img');
 
     var img = document.createElement('img');
Zeile 65: Zeile 65:
 
     img.onload = encourageContributions;
 
     img.onload = encourageContributions;
 
     img.src = 'https://mattermost.fsinf.at/api/v4/teams/sswtb6oqciyyfmkibh6mjz479w/image';
 
     img.src = 'https://mattermost.fsinf.at/api/v4/teams/sswtb6oqciyyfmkibh6mjz479w/image';
} else if (document.location.pathname == '/wiki/Startseite_Uni_Wien'){
+
} else if (document.location.pathname == '/wiki/Uni_Wien/Sprachwissenschaft'){
 
     var bubble = document.getElementById('mascot-says-bubble');
 
     var bubble = document.getElementById('mascot-says-bubble');
 
     encourageContributions();
 
     encourageContributions();
 
}
 
}

Version vom 15. August 2019, 15:40 Uhr

/* Das folgende JavaScript wird für alle Benutzer geladen. */

/* Downloadlinks für <pre data-filename=Foo.txt> */
var downloadable = $('*[data-filename]');
if (downloadable.length == 1) {
    var link = $('<a>Download</a>');
    link.attr('href', 'data:text/plain;base64,' + btoa(
        // hack to get UTF-8 encoding
        unescape(encodeURIComponent(downloadable[0].textContent))
    ));
    link.attr('download', $(downloadable[0]).attr('data-filename'))
    $(downloadable[0]).prepend(link);
} else if (downloadable.length > 1) {

    var btn = $('<a>Download ZIP</a>');
    btn.click(function() {
        $.getScript('https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js', function(data, textStatus, jqxhr) {
            $.getScript('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.0/jszip.js', function() {
                var zip = new JSZip();
                var dirname = wgPageName.split('/').pop();
                downloadable.each(function() {
                    zip.file(dirname + '/' + $(this).attr('data-filename'), this.textContent);
                });
                zip.generateAsync({
                        type: "blob"
                    })
                    .then(function(content) {
                        saveAs(content, dirname + ".zip");
                    });
            });
        });
    });
    $('#mw-content-text').prepend(btn);
}

function encourageContributions(){
    var username = mw.config.get('wgUserName');
    if (username){
        var month = new Date().getMonth(); // JavaScript months start with 0
        var semesterStart = new Date(new Date().getFullYear() - (month < 2), month < 9 ? 2 : 9);
        var api = new mw.Api();
        api.get( {
            action: 'query',
            list: 'usercontribs',
            ucuser: username,
            uclimit: 1,
            ucend: semesterStart.toISOString()
        }).done( function ( data ) {
            if (data.query.usercontribs.length > 0){
                bubble.innerHTML = 'Danke für deine Beiträge! Weiter so!';
            } else {
                bubble.innerHTML = 'Hast du dieses Semester schon etwas beigetragen?';
            }
        });
    }
}

if (document.location.pathname == "/wiki/TU_Wien/Informatik"){
    var bubble = document.getElementById('mascot-says-bubble');
    var img = document.createElement('img');
    img.width=0;
    img.onerror = function (){
        bubble.innerHTML = 'Bist du schon auf <a href="https://fsinf.at/mattermost">Mattermost</a>?';
    }
    img.onload = encourageContributions;
    img.src = 'https://mattermost.fsinf.at/api/v4/teams/sswtb6oqciyyfmkibh6mjz479w/image';
} else if (document.location.pathname == '/wiki/Uni_Wien/Sprachwissenschaft'){
    var bubble = document.getElementById('mascot-says-bubble');
    encourageContributions();
}