Usuário:EduardoFP7/common.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * Ferramenta de ajustes e traduções em referências (Script de ajustes)
 */
 /* Autor: [[User:Luizdl/Script de ajustes.js|Luizdl]] */
mw.loader.load('//pt.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=Usuário:Luizdl/Script de ajustes.js&action=raw&ctype=text/javascript', 'text/javascript');

/* Script para corrigir formato de referências. */
mw.loader.load( "https://meta.wikimedia.org/w/index.php?title=User:Zhaofeng_Li/Reflinks.js&action=raw&ctype=text/javascript" );

/* Adds a toolbox link to do a copyvio check on the given page. */
mw.loader.using("mediawiki.util", function() {
    mw.util.addPortletLink(
        "p-tb",
        "https://tools.wmflabs.org/copyvios/?lang=" + mw.config.get("wgContentLanguage") + "&project=" + "wikipedia" + "&title=" + encodeURIComponent(mw.config.get("wgPageName")),
        "Copyvio check",
        "t-copyvio-check",
        "Check this page for copyright violations"
    );
});

// ORES
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:He7d3r/Tools/DraftAndArticleQuality.js&action=raw&ctype=text/javascript' );

( function ( mw, $ ) {
	'use strict';

	function validateComments() {
		$( '#wpSave' ).on( 'click', function ( e ) {
			var $textBox = $( '#wpTextbox1' ),
				curText = $textBox.val(),
				signRequired = mw.config.get( 'wgNamespaceNumber' ) % 2 === 1
					|| curText.indexOf( ' (' + 'UTC)' ) !== -1,
				hasSignature = /~{4}(?!<\/nowiki>)/.test( curText ),
				unsignedText = 'Parece que esqueceu de colocar "~~' + '~~" no final da mensagem para assinar o seu comentário. Deseja salvar mesmo assim?';
			if ( signRequired && !hasSignature && !confirm( unsignedText ) ) {
				$textBox.focus();
				e.preventDefault();
				mw.log( 'Não salvar' );
			}
		} );
	}
	if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
		$( validateComments );
	}

}( mediaWiki, jQuery ) );

var userConf = { userRulesVersion: '0.1' };
userConf.userRules = [ {
	name: 'Minhas correções',
	sub: [
		// https://regex101.com/r/CJjYd4/1
		{ name: 'Simplifica ligações internas', find: /\[\[(.+?)\|\1\]\]/g, replace: '[[$1]]' },
		// https://regex101.com/r/32MAsQ/1
		{ name: 'Remove protocolo duplicado', find: /https?:\/\/(https?:\/\/)/g, replace: '$1' }
	]
} ];
window.APC = $.extend( {}, window.APC, userConf );
// [[File:User:He7d3r/Tools/APC.js]] (workaround for [[phab:T35355]])
mw.loader.load( 'https://meta.wikimedia.org/w/index.php?title=User:He7d3r/Tools/APC-Loader.js&action=raw&ctype=text/javascript' );

/**
 * Ferramenta para arquivar propostas de fusão
 */
 /* Autor: [[User:!Silent/archiveMergingProposals.js|!Silent]] */
//mw.loader.load( '//pt.wikipedia.org/w/index.php?title=!Silent/archiveMergingProposals.js&action=raw&ctype=text/javascript' );

/*Destaca as URLs mortas
 * Autor: [[:de:Benutzer:Frog23/Dead Link Finder]]
 */  	 	
mw.loader.load("//tools.wmflabs.org/deadlinkfinder/script.js");

/**
 * Ligações duplicadas
 */
 /* Autor: [[:en:User:Ucucha/duplinks]] */
$( function($) {
    if((mw.config.get('wgNamespaceNumber') !== 0) && (mw.config.get('wgNamespaceNumber') !== 2)) {
        // only check links in mainspace and userspace (for userspace drafts)
        return;
    }
    var portletlink = mw.util.addPortletLink('p-tb', '#', 'Destacar ligações duplicadas', 'ca-findduplicatelinks');
    $(portletlink).click( function(e) {
        e.preventDefault();
        // create a separate div surrounding the lead
        // first get the element immediately surrounding the article text. Unfortunately, MW doesn't seem to provide a non-fragile way for that.
        var content = ".mw-content-ltr";
        $(content).prepend(document.createElement('div'));
        var lead = $(content).children()[0];
        $(lead).attr('id', 'lead');
        $(content).children().each( function() {
            if(this.nodeName.toLowerCase() == 'h2') {
                return false;
            }
            if($(this).attr('id') != 'lead') {
                $(lead).append(this);
            }
            return true;
        });
       
        // detect duplicate links
        mw.util.addCSS(".duplicate-link { border: 1px solid red; }");
        var finddups = function() {
            var href = $(this).attr('href');
            if(href !== undefined && href.indexOf('#') !== 0) {
                if(seen[href]) {
                    $(this).addClass("duplicate-link");
                }
                else {
                    seen[href] = true;
                }
            }
            return true;
        };
        // array to keep track of whether we've seen a link before
        var seen = [];
        mw.util.$content.find('p a').not('#lead *, .infobox *, .navbox *').each(finddups);
        mw.util.$content.find('#lead p a').not('.infobox *, .navbox *').each(finddups);
    });
});