User:StrawberryMaster/global.js

/* Indicates closed and highlighted threads. * Something I found on the threads.  */ $(function {   if (mw.config.get('wgNamespaceNumber') !== 2000) {        return;    }    $('.ThreadList .thread').each(function { var $this = $(this); // With many thanks to w:User:Cqm! $.get(mw.util.wikiScript('wikia'), {           controller: 'Forum',            method: 'brickHeader',            id: $this.data('id'),            format: 'json'        }, function(data) {            if (data.isClosed) {                $this                    .addClass('closed')                    .find('h4 > a').append(' (closed) ');            }            if (data.isNotifyeveryone) {                $this                    .addClass('highlighted')                    .find('h4 > a').append(' (highlighted) ');            }        }); }); });

/* FastDelete script configuration. * See w:c:dev:FastDelete for info & attribution. */ var fdButtons = []; fdButtons[fdButtons.length] = { 'summary': 'spam', 'label': 'S' };

fdButtons[fdButtons.length] = { 'summary': 'vandalism', 'label': 'V' };

fdButtons[fdButtons.length] = { 'summary': 'Housekeeping', 'label': 'HK' }; fdButtons[fdButtons.length] = { 'summary': 'Cleanup', 'label': 'C' }; fdButtons[fdButtons.length] = { 'summary': 'Unused', 'label': 'U' };

fdButtons[fdButtons.length] = { 'summary': 'Unofficial/not-needed/irrelevant', 'label': 'UNI' };

fdButtons[fdButtons.length] = { 'summary': 'Other reason', 'label': 'Other' };

// More flexible AjaxUndo jQuery(document).ready(function($) {   "use strict";

function createUndoLink(diffUndoUrl) { var $ajaxUndoLink = $('').text('AJAX Undo').attr('href', '#').click(function {           var $ajaxUndoLinkob = $(this),                undoIdRegex = /&undo=([^&]*)/,                undoId = undoIdRegex.exec(diffUndoUrl)[1],                editToken,                etUrl = wgServer + wgScriptPath + '/api.php?action=query&prop=info|revisions&intoken=edit&titles=' + encodeURIComponent(wgPageName) + '&format=json',                usrUnd = $('#mw-diff-ntitle2 .mw-userlink').html,                smry = prompt('Undo summary', 'Undo revision ' + undoId + ' by ' + usrUnd + ' (talk)');                if (smry === null) return;                else if (!smry) smry = 'Undo revision ' + undoId + ' by ' + usrUnd + ' (talk)';            $ajaxUndoLinkob.html(' ');           $.getJSON(etUrl, function(data) { editToken = data.query.pages[wgArticleId].edittoken; $.ajax({                   url: wgScriptPath + '/api.php?',                    data: 'action=edit&format=json&title=' + encodeURIComponent(wgPageName) + '&undo=' + encodeURIComponent(undoId) + '&bot=1&summary=' + encodeURIComponent(smry) + '&token=' + encodeURIComponent(editToken),                    dataType: 'json',                    type: 'POST',                    success: function(data) {                        if (data.edit && data.edit.result === 'Success') {                            $ajaxUndoLinkob.text('(undone)');                        } else if (data.error && data.error.code === 'undofailure') {                            $ajaxUndoLinkob.text('(error)');                            alert(data.error.info);                        } else {                            $ajaxUndoLinkob.text('(error)');                            alert('Error: Unknown result from API.'); }                   },                    error: function { $ajaxUndoLinkob.text('(error)'); }               });            });        });        return $ajaxUndoLink;    }

if ($('.mw-history-undo > a').length && wgAction === 'history') { $('.mw-history-undo > a').each(function {           var diffUndoUrl = $(this).attr('href'),                $ajaxUndoLink = createUndoLink(diffUndoUrl);            $(this).replaceWith($ajaxUndoLink);        }); } else if ($('table.diff').length && typeof $.getUrlVar('diff') !== 'undefined') { var $diffUndoLink = $('table.diff').find('.diff-ntitle > #mw-diff-ntitle1 a:last'), diffUndoUrl = $diffUndoLink.attr('href'), $ajaxDiffUndoLink = createUndoLink(diffUndoUrl); $diffUndoLink.replaceWith($ajaxDiffUndoLink); } });

// anti-spam +	$('head').append('#WikiaPage .Chat .message { word-wrap: break-word; } ');

// Ajax Block settings AjaxBlock = { blockReasons: { 'Vandalism': 'Vandalism', 'Spam': 'Spam', 'Repeated policy violations': 'Repeated violations', 'Sockpuppetry/ban evasion': 'Sockpuppetry', 'Removing content/blanking pages': 'Page blanking', 'Inserting false information or nonsense': 'Gibberish', 'Intimidating behaviour/harassment/trolling': 'Troll/harassment', 'Unacceptable username, avatar, or global masthead': 'Name/avatar', 'Under the legal age': 'COPPA', 'Failing to comply with the file policy.': 'File Policy' },   check: { creation: true, talk: true, autoBlock: true, override: true } };

/* Auto updating recent changes opt-in. * Something I found on Dorumin's global.js.  * See w:c:dev:AjaxRC for info & attribution. */ window.ajaxPages = ["Blog:Recent_posts", "Special:RecentChanges", "Special:WikiActivity", "Special:Chat", "Special:Watchlist", "Special:Log", "Special:Log/upload", "Special:Contributions"]; window.ajaxIndicator = 'http://vignette2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif'; window.ajaxRefresh = 30000; window.AjaxRCRefreshText = 'Auto-refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page';

/* Create userpage script. * See w:c:dev:QuickCreateUserPage for info & attribution. */

var qtUserPageTemplate = ''; var qtEnableUserPageOverwrite = true;

/* Vector skin configuration. * See w:c:dev:Pseudo-Vector JS for info & attribution. */ window.pseudoVector = { loadCss: true, addReadTab: true, addContributionsTab: true, disableWatchIcon: false, newDiffStyle: true };

/* Removes backlinks from pages. * See w:c:dev:Linksweeper for info & attirbution. */ window.linkSweepConfirmation = true; window.LinkSweeperDelay = 1000;

/* Places "QuickToolsv2" button on the "My Tools" section. * Something I found on Zmario's global.js.  * See w:c:dev:QuickToolsv2 for info & attribution. */ var QuickToolsAdvancedtop = false;

/* Import JavaScript and Stylesheet articles from any wiki. * See  for info & attribution. */

importArticles({	type: 'script',	articles: [           // ...            'u:dev:MediaWiki:AjaxRC/code.js',            'u:dev:MediaWiki:AjaxBatchDelete/code.2.js',            'u:dev:MediaWiki:AjaxBatchUndelete.js',            'u:dev:MediaWiki:AjaxBlock/code.js',            'u:dev:MediaWiki:AjaxPatrol/code.js',            'u:dev:MediaWiki:ArchiveTool/code.js',            'u:dev:MediaWiki:DisplayClock/code.js',            'u:dev:MediaWiki:FastDelete/beta.js',            'u:dev:MediaWiki:Linksweeper/code.js',            'u:dev:MediaWiki:MassBlock/code.js',            'u:dev:MediaWiki:MassCategorization/code.js',            'u:dev:MediaWiki:MassProtect/code.js',            'u:dev:MediaWiki:MassRename/code.js',            'u:dev:MediaWiki:MassUserRights/code.js',            'u:dev:MediaWiki:Pseudo-Vector.js',            'u:dev:MediaWiki:QuickCreateUserPage/code.js',            'u:dev:Mediawiki:QuickToolsv2/code.js', 'u:dev:MediaWiki:WHAM/code.2.js', // ...	] });

( function ( $, mw, importArticles ) {   'use strict';    var self = {        /**         * @desc Loads functions conditionally         */        init: function  {            var config = mw.config.get( [ 'wgCanonicalSpecialPageName', 'wgNamespaceNumber', 'wgTitle' ] );           self.imports;            if ( $( '#UserProfileMasthead' ).length ) {                self.mastheadEditcount;            }            if ( config.wgCanonicalSpecialPageName === 'Movepage' && ( /File/ ).test( config.wgTitle ) ) {               self.uncheckFileRedirects;            }            if ( config.wgNamespaceNumber === 6 && !$( '#file > a' ).length ) {                self.removeAutoplay;            }            if ( $( '[src*="youtube.com"]' ).length ) {                self.switchAutoplay;            }        },        /**         * @desc Defines variables for imported scripts and import said scripts         *         * @author Cqm         */        imports: function  {            var fdButtons = [],                scripts = [],                config = mw.config.get( [ 'wgAction', 'wgCityId', 'wgCanonicalSpecialPageName', 'wgNamespaceNumber' ] );            /**             * Setup globals vars here             */            // fastdelete buttons            fdButtons[ fdButtons.length ] = { summary: 'Housekeeping', label: 'HK' };            // for rswiki only if ( config.wgCityId === '304' ) { fdButtons[ fdButtons.length ] = { summary: 'Successful RfD', label: 'RfD' }; }           // add as global window.fdButtons = fdButtons; /**            * Create an array of scripts to be imported conditionally * See imported pages for documentation * @todo Find a way to turn these on/off from console or something */           // always load these scripts.push(               // CSS testing input                // 'u:dev:PortableCSSPad/code.js',                // Customisable On The Wiki tab                // 'u:dev:Wikimarks/code.js',                // Fix search for Special pages                // 'u:rs:User:Cqm/specialsearchfix.js'            ); if ( config.wgAction === 'view' ) { scripts.push(                   // Icon to link to header tags                    // 'u:dev:HeaderLinks/code.js'                ); if ( $( '#ca-delete' ).length ) { // Fast Delete buttons // scripts.push( 'u:dev:FastDelete/code.js' ); // scripts.push( 'u:dev:FastDelete/beta.js' ); }               if ( config.wgNamespaceNumber === 6 ) { scripts.push(                       // Changes file pages back to original styling                        // @todo fix this up at some point                        // 'u:rs:User:Cqm/oldfilepages.js'                    ); }               if ( [ 'Allpages', 'Prefixindex' ].indexOf( config.wgCanonicalSpecialPageName ) > 1 ) { scripts.push(                       // Adds a hide redirect button to AllPages & PrefixIndex                        // 'u:dev:AllPagesHideRedirect/code.js'                    ); }               if ( config.wgAction === 'history' || $( '#mw-history-searchform' ).length ) { scripts.push(                       // Add an undo link to page diffs and histories                        // 'u:dev:AjaxUndo/code.js'                    ); }           }            /**             * Import the filled arrays */           importArticles( { type: 'script', articles: scripts } ); },       /**         * @desc Adds a link to Special:Editcount on the user profile masthead *        * @author Matthew2602  * @author Cqm */       mastheadEditcount: function  { var config = mw.config.get( [                   'wgCanonicalNamespace',                    'wgTitle'                ] ), user = config.wgTitle, link; if ( config.wgCanonicalNamespace === 'Special' ) { user = user.split( '/' )[1]; }           link = $( '' ) .attr( {                   href: '/wiki/Special:Editcount/' + user,                    title: 'Special:Editcount'                } ) .text(                   $( '#UserProfileMasthead .tally em' ).text                ); $( '#UserProfileMasthead .tally em' ).html( link ); },       /**         * @desc Uncheck file redirects on Special:MovePage *        * File redirects are normally bad because they will create false positives on Special:WantedFiles * In very rare cases it's reasonable to have them, but those are so rare it's better to have this as        * the default behaviour. *        * @author Cqm */       uncheckFileRedirects: function  { $( '#wpLeaveRedirect' ).removeAttr( 'checked' ); },       /**         * @desc Set the type attribute of input elements to type="text" (which it defaults to anyway) *      Used to undo styling in touchScreen.scss which indiscriminately makes every input *      element larger than I need. */       setInputType: function  { $( 'input' ).each( function {                if ( !this.type ) {                    this.type = 'text';                }            } ); },       /**         * @desc For preventing autoplay on embedded youtube videos *      which are normally embedded through templates and MediaWiki pages *        * @example  * @example  *        * @author Bobogoobo  * @author Cqm */       switchAutoplay: function  { $( '[src*="youtube.com"]' ).each( function {                var $this = $( this ),                    source = $this.attr( 'src' );                if ( source.indexOf( 'autoplay=' ) > -1 ) {                    $this.attr( 'src', source.replace( 'autoplay=1',  ).replace( 'autoplay=0',  ) );                }                // for embedded flash files                // which are so annoying they get their own console message                if ( $this.prop( 'tagName' ) === 'EMBED' ) {                    console.log( 'kill embed with fiyah' );                    $this.remove;                }            } ); },       /**         * @desc For preventing autoplay for embedded youtube videos on file pages *        * @author Cqm */       removeAutoplay: function  { var loading; // used in setInterval function iframeLoad { if ( $( '#file iframe[src*="youtube.com"]' ).length ) { self.switchAutoplay; window.clearInterval( loading ); }           }            // @todo use mutation observers for this instead loading = window.setInterval( iframeLoad, 500 ); }   };    $( self.init ); }( this.jQuery, this.mediaWiki, this.importArticles ) );