User:Dorumin/wikia.js

// IC's vestige if ( wgNamespaceNumber === 1200 ) { $('', {       id: 'ImageWarn',        style: 'cursor:pointer;',    }).html('Image Warning') .prependTo('.toolbar .tools') .click(function {       $('#wall-new-message #WallMessageBody').focus;        files = prompt('File names (separate with ", " (space comma space))');        if (!files) return;        files = files.split(' , ');        title = prompt('title', 'Uncategorized Images');        if (!title) return;        blockDuration = prompt('block duration (leave blank if just warning)');        blockReason = prompt('Block reason', 'failing to comply with image policy.');        if ( blockDuration !==  && blockDuration !== null && blockReason !==  && blockReason !== null) {            var usrToBlock = wgPageName.split('Message_Wall:')[1],            token = mw.user.tokens.get("editToken"),            Api = new mw.Api;            Api.post({ action: 'block', user: usrToBlock, expiry: blockDuration, nocreate: 0, autoblock: 0, reason: blockReason, bot: true, token: token })           .done(function(d) { if (!d.error) { console.log(usrToBlock + ' has been blocked successfully! Length: ' + blockDuration); } else { alert('Failed to block ' + usrToBlock + ': ' + d.error.code); }           });        }        console.log('almost there');        $('#wall-new-message #WallMessageTitle').val(title);        var strb = (blockDuration) ? '|b=' + blockDuration + '}}' : '}}';        $('#wall-new-message #WallMessageBody').val('{{UC|' + files.join('|') + strb);        $('#WallMessageSubmit').click;    }); }

// Removing fixed images on click $(".fixed-image-template").click(function {    $(this).hide(500, function  { $(this).remove; }); });

// Removing ?t piece in DPLForum link instances if ( $('.forumlist').length ) { $('.forum_new').each(function {        var links = $('.forum_new');        links.each(function  { var nwtrgt = $(this).attr('href').split('?t')[0]; $(this).attr('href', nwtrgt); });   }); }

// Block links $(window).load(function {   if ( $('#UserProfileMasthead').length ) {        $('.tag-container').after('Block');    }    // Threads    if ( wgNamespaceNumber != 1201 ) return;    for (var i in $('.msg-toolbar')) {        var usr = $('.msg-toolbar:eq(' + i + ')').parent.find('.edited-by a').text;        $('.msg-toolbar:eq(' + i + ')').find('.WikiaMenuElement li').last.before('Block');    } });

// Automatic addition of User files if (wgPageName == 'Special:Upload' || wgPageName == 'Special:MultipleUpload') { $('#wpUploadDescription').val(''); } if (wgAction !== 'edit' && window.location.href.match("/?veaction=edit$") === null) { setInterval(function {   if ($('#ImageUploadLicense').length) {      $('#ImageUploadLicense > option:first-of-type').val('Userfiles');    }  }, 2000); } else if ( wgNamespaceNumber === 1201 ) { setInterval(function {   if ($('#ImageUploadLicense').length) {      $('#ImageUploadLicense > option:first-of-type').val('Userfiles');    }  }, 2000); } if (wgPageName == 'Special:Images') { executed = false; setInterval(function {   if (!executed) {      if ($('textarea[name="wpUploadDescription"]').length) {        executed = true;        $('textarea[name="wpUploadDescription"]').val('');      }    }  }, 2000); }

// Update avatars window.avatars = {}; function getURL(user) { $.get("/wiki/Special:Contributions/" + user + "?useskin=oasis", function(data) {       window.avatars[user] = //ig.exec(data)[1] + '';    }); }

// Moderators & Site Administrators if ( wgPageName == "Steven_Universe_Wiki:Moderators" || wgPageName == "Steven_Universe_Wiki:Site_Administrators" ) { $(window).load(function {       $('.wikinav2 .WikiaPageHeader').css('padding-right', '0');        $('#WikiaPageHeader .comments').after( 'Update avatars ' );       $('#update-avatars').click(function { $(this).replaceWith(''); var usrs = []; var matches; var PC; var pageNewContent; $('.staff-usr-template').each(function {               usrs.push($(this).text.trim);            }); var API = new mw.Api; API.get({               action: 'query',                prop: 'revisions',                rvprop: 'content',                titles: wgPageName            }).done(function(data) {                for (var i in data.query.pages) {                    PC = data.query.pages[i].revisions[0]['*'];                    page = data.query.pages[Object.keys(data.query.pages)[0]];        		}                matches = PC.match(/\|(\s+|)link(\s+|)=(\s+|).+/gi);                pageNewContent = PC;                for (var i in matches) {                    matches[i] = matches[i].split('=')[1].trim;                }                for (var i in usrs) {                    if (usrs[i] !== '') {                        getURL(usrs[i]);                    }                }                setTimeout(function { for (var i in usrs) { if (usrs[i] !== '') { usrs[i] = window.avatars[usrs[i]]; usrs[i] = usrs[i].replace('static', 'images1') + '/scale-to-width-down/' + matches[i].split('/scale-to-width-down/')[1]; }                   }                    for (var i in usrs) { if (usrs[i] !== '') { pageNewContent = pageNewContent.replace(matches[i], usrs[i]); }                   }                    if ( PC != pageNewContent ) { var config = { 'minor': 'yes', 'bot': 'yes', 'summary': 'Updating user avatars. (automatic)', 'action': 'edit', 'title': wgPageName, 'token': mw.user.tokens.get('editToken'), 'text': pageNewContent };                       $.ajax({                            url: mw.util.wikiScript('api'),                            data: config,                            dataType: 'json',                            type: 'POST',                            success: function(d) {                                if (!d.error) {                                    new BannerNotification('Avatars successfully updated!', 'confirm').show;                                    $('#progress-img').replaceWith(' Success! ');                               } else {                                    new BannerNotification('Failed while updating avatars: ' + d.error.code, 'error').show;                                    $('#progress-img').replaceWith(' Fail. ');                               }                            },                            error: function {                                new BannerNotification('User avatars have been successfully updated!', 'confirm').show;                                $('#progress-img').replaceWith(' Updated ');                            }                        }); } else { new BannerNotification('No avatars to update.', 'error').show; $('#progress-img').replaceWith(' No new avatars '); }               }, 15000);            });        });    }); }

// MediaWiki:Emoticons var usrs = []; var matches = []; var PC; var pageNewContent; if ( wgPageName == 'MediaWiki:Emoticons' ) { $(window).load(function {       $('.wikinav2 .WikiaPageHeader').css('padding-right', '0');        $('#WikiaPageHeader .comments').after( 'Update avatars ' );       $('#update-avatars').click(function { $(this).replaceWith(''); var API = new mw.Api; API.get({               action: 'query',                prop: 'revisions',                rvprop: 'content',                titles: wgPageName            }).done(function(data) {                for (var i in data.query.pages) {                    PC = data.query.pages[i].revisions[0]['*'];                    page = data.query.pages[Object.keys(data.query.pages)[0]];                }                usernames = PC.match(/\n\*.+/g);                for (var i in usernames) {                    usrs.push(usernames[i].replace(/(\n\*.+)/g, ));                    matches.push(usernames[i].replace(/\n\*/, ));                }                pageNewContent = PC;                for (var i in usrs) {                    getURL(usrs[i]);                }                setTimeout(function { for (var i in usrs) { usrs[i] = window.avatars[usrs[i]]; usrs[i] = usrs[i].replace('static', 'images1') + '/scale-to-width-down/' + matches[i].split('/scale-to-width-down/')[1]; }                   for (var i in usrs) { pageNewContent = pageNewContent.replace(matches[i], usrs[i]); }                   if ( PC != pageNewContent ) { var config = { 'minor': 'yes', 'bot': 'yes', 'summary': 'Updating user avatars. (automatic)', 'action': 'edit', 'title': wgPageName, 'token': mw.user.tokens.get('editToken'), 'text': pageNewContent };                       $.ajax({                            url: mw.util.wikiScript('api'),                            data: config,                            dataType: 'json',                            type: 'POST',                            success: function(d) {                                if (!d.error) {                                    new BannerNotification('Avatars successfully updated!', 'confirm').show;                                    $('#progress-img').replaceWith(' Success! ');                               } else {                                    new BannerNotification('Failed while updating avatars: ' + d.error.code, 'error').show;                                    $('#progress-img').replaceWith(' Fail. ');                               }                            },                            error: function {                                new BannerNotification('User avatars have been successfully updated!', 'confirm').show;                                $('#progress-img').replaceWith(' Updated ');                            }                        }); } else { new BannerNotification('No avatars to update.', 'error').show; $('#progress-img').replaceWith(' No new avatars '); }               }, 15000);            });        });    }); }

// DPL $(window).load(function {   if ( wgPageName != 'User:Dorumin/DPL' ) return;    $('.wikinav2 .WikiaPageHeader').css('padding-right', '0');    $('#WikiaPageHeader .comments').after( 'Image stuff ' );   $('#image-cleanup').click(function { var API = new mw.Api; $('.forumlist tr a').each(function {           var $this = $(this);            API.get({ prop: 'revisions', titles: $this.text }).done(function(d) { if ( Number(d.query.pages[Object.keys(d.query.pages)[0]].revisions[0].timestamp.replace(/\D/g, '').slice(8, 10)) < ( ( (new Date.getUTCHours - 1) < 0 ) ? 23 : new Date.getUTCHours - 1 ) ) { $.get($this.attr('href'), function(dat) {                       if (/class="page-listings"/.test(dat)) return;                        var title = 'File:' + dat.match(/ \s* (.*)<\/h1>\s*<\/div>/)[1].trim;                        var token = mw.user.tokens.get('editToken');                        var url = wgServer + wgScriptPath + '/api.php?action=delete&title=' + window.encodeURIComponent(title) + '&reason=Housekeeping&format=json&token=' + window.encodeURIComponent(token);                        $.post(url, function(data) { if (data.error) { new BannerNotification('Error while deleting ' + title + ': ' + data.error.info + '\n', 'error').show; } else { new BannerNotification(title + ' was deleted successfully.', 'confirm').show; }                       });                    });                }            });        });    }); });