(Mise-à-jour) |
(Import du code concernant les traductions) |
||
Ligne 75 : | Ligne 75 : | ||
} ) |
} ) |
||
+ | // Translation progress |
||
+ | var pageName = mw.config.get( 'wgPageName' ); |
||
+ | fetch( "https://bindingofisaacrebirth-fr.gamepedia.com/api.php?format=json&action=cargoquery&tables=maintenance&fields=origine,revision&where=_pageName='" + pageName + "'&limit=1" ) |
||
+ | .then( function( r ) { return r.json(); } ) |
||
⚫ | |||
+ | if ( r.cargoquery.length ) { |
||
+ | var fr = r.cargoquery[0].title; |
||
+ | var revision = fr.revision; |
||
+ | var origine = fr.origine; |
||
+ | fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&pageids=" + origine ) |
||
+ | .then( function( r2 ) { return r2.json(); } ) |
||
⚫ | |||
+ | var lastRevision = r2.query.pages[origine].revisions[0].revid; |
||
+ | if ( lastRevision == revision ) { |
||
+ | $( 'body.action-view #firstHeading' ) |
||
+ | .prepend( '<div style="width: 15px; height: 15px; float: right; background: green"></div>' ); |
||
+ | $( 'body.action-edit #mw-translation-editnotice' ) |
||
+ | .css( 'background', 'green' ) |
||
+ | .html( '<b>Cette page est à jour.</b><br>Elle est une traduction de la révision <code>' + lastRevision + '</code> de la page <a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + origine + '">' + r2.query.pages[origine].title + '</a>.' ); |
||
⚫ | |||
+ | $( 'body.action-view #firstHeading' ) |
||
+ | .prepend( '<a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '"><div style="width: 15px; height: 15px; float: right; background: darkred"></div></a>' ); |
||
+ | $( 'body.action-edit #mw-translation-editnotice' ) |
||
+ | .css( 'background', 'darkred' ) |
||
+ | .html( '<b>Cette page n’est pas à jour.</b><br>Vous pouvez aider en <a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '">la mettant à jour</a>, puis en remplaçant <code>{{révision | ' + revision + ' | ' + origine + ' }}</code> par <code>{{révision | ' + lastRevision + ' | ' + origine + ' }}</code> en haut de la page.' ); |
||
⚫ | |||
⚫ | |||
+ | } else |
||
+ | $( 'body.action-edit #mw-translation-editnotice' ) |
||
+ | .append( '<br><br>Entrer le nom d’une page pour obtenir le texte correspondant à la dernière révision.<br><div class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-textInputWidget oo-ui-textInputWidget-type-text oo-ui-labelElement" style="width: 40%; display: inline-block"><input type="text" id="mw-translation-editnotice-search" class="oo-ui-inputWidget-input"></div><a class="mw-ui-button button" style="min-width: 30px; margin-right: 0.5em" onclick="translationSearch()"><b>></b></a><br><code>{{révision | <span id="mw-translation-editnotice-revision"></span> | <span id="mw-translation-editnotice-origine"></span> }}</code>' ); |
||
+ | } ); |
||
⚫ | |||
+ | var pageName = $( '#mw-translation-editnotice-search' ).val(); |
||
+ | fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&titles=" + pageName ) |
||
+ | .then( function( r ) { return r.json(); } ) |
||
⚫ | |||
+ | var pages = r.query.pages; |
||
+ | var p; |
||
+ | for ( p in pages ) |
||
+ | break; |
||
+ | if ( p === "-1" ) |
||
+ | $( '#mw-translation-editnotice-revision, #mw-translation-editnotice-origine' ).html( '' ); |
||
+ | else { |
||
+ | var page = pages[p]; |
||
+ | $( '#mw-translation-editnotice-revision' ).html( page.revisions[0].revid ); |
||
+ | $( '#mw-translation-editnotice-origine' ).html( page.pageid ); |
||
+ | } |
||
+ | } ); |
||
⚫ | |||
+ | // Outdated pages list |
||
− | /* Wiki tests */ |
||
+ | var $list = $( '#mw-translation-list' ); |
||
⚫ | |||
+ | if ( $list.length ) |
||
− | console.log( "wt - start" ); |
||
+ | fetch( "https://bindingofisaacrebirth-fr.gamepedia.com/api.php?format=json&action=cargoquery&tables=maintenance&fields=_pageName=page,origine,revision&limit=500" ) |
||
− | |||
+ | .then( function( r ) { return r.json(); } ) |
||
− | if ( $( 'h1' ).has( '[id^="$"]' ).length ) { |
||
+ | .then( function( r ) { |
||
− | console.log( "wt - headers found" ); |
||
+ | var pages = r.cargoquery; |
||
− | |||
+ | for ( var p in pages ) |
||
− | // Remove invalid headers |
||
+ | li( pages[p].title ); |
||
− | $( 'h1' ).has( '[id^="$"][id!="$flash"][id!="$rebirth"]' ).each( function () { |
||
− | console.log( "wt - invalid header detected: " + $( this ).attr( 'id' ) ); |
||
− | $( '#mw-parser-output' ).append( '<p color="red">Error: Invalid section name ("' + $( this ).attr( 'id' ) + '")</p>' ); |
||
} ); |
} ); |
||
− | console.log( "wt - invalid headers detection finished" ); |
||
+ | function li( page ) { |
||
− | // Hide headers and move content |
||
+ | var title = page.page; |
||
− | $( 'h1' ).has( '[id="$flash"]' ) |
||
+ | var revision = page.revision; |
||
− | .hide() |
||
+ | var origine = page.origine; |
||
− | .after( '<div id="$flash-content"></div>' ) |
||
+ | if ( origine !== "0" ) |
||
− | .nextUntil( 'h1' ) |
||
+ | fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&pageids=" + origine ) |
||
⚫ | |||
+ | .then( function( r ) { return r.json(); } ) |
||
− | $( '[id="$flash-content"]' ).append( this ); |
||
+ | .then( function( r ) { |
||
− | console.log( "wt - flash block added" ); |
||
+ | var lastRevision = r.query.pages[origine].revisions[0].revid; |
||
− | } ); |
||
+ | $list.append( '<li><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?title=' + title + '">' + title + '</a> : <a href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '"><code>' + revision + '</code> -> <code>' + lastRevision + '</code></a>' ); |
||
− | $( 'h1' ).has( '[id="$rebirth"]' ) |
||
− | .hide() |
||
− | .after( '<div id="$rebirth-content"></div>' ) |
||
− | .nextUntil( 'h1' ) |
||
⚫ | |||
− | $( '[id="$rebirth-content"]' ).append( this ); |
||
− | console.log( "wt - rebirth block added" ); |
||
} ); |
} ); |
||
− | console.log( "wt - content moved" ); |
||
− | |||
− | var header_to_display, header_to_hide; |
||
− | if ( window.location.hash === '#$flash' ) { |
||
− | header_to_display = 'flash'; |
||
− | header_to_hide = 'rebirth'; |
||
⚫ | |||
− | header_to_display = 'rebirth'; |
||
− | header_to_hide = 'flash'; |
||
⚫ | |||
− | |||
− | // Hide the header's content |
||
− | $( '[id="$' + header_to_hide + '-content"]' ).hide(); |
||
− | $( 'body' ).addClass( 'mw-' + header_to_display ); |
||
− | console.log( "wt - " + header_to_hide + "'s header hidden" ); |
||
− | |||
− | // Add the button |
||
− | $( '#firstHeading' ).append( '<button onclick="switch_game()" id="mw-switchGameButton" class="mw-switchGameButton">Switch game</button>' ); |
||
− | console.log( "wt - button added" ); |
||
− | |||
− | $( 'h1' ).has( '[id="$flash"]' ).remove(); |
||
− | $( 'h1' ).has( '[id="$rebirth"]' ).remove(); |
||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | $( '[id^="$"]' ).toggle(); |
||
− | $( 'body' ).toggleClass( 'mw-flash mw-rebirth' ); |
||
− | console.log( "wt - games switched" ); |
||
} |
} |
Version du 9 septembre 2019 à 04:35
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
$( function () {
var purge_href = $( '#ca-cargo-purge > a' ).attr( 'href' );
$( '#ca-cargo-purge' ).remove();
$( '#p-views > ul' ).append( '<li></li>' );
$( '#p-views > ul > li:not([id])' ).attr( 'id', 'ca-cargo-purge' );
$( '#ca-cargo-purge' ).append( '<span><a>⟳</a></span>' );
$( '#ca-cargo-purge > span > a' )
.attr( { 'title': 'Purge the cache [alt-shift-g]', 'href': purge_href, 'accesskey': 'g' } )
.css( { 'line-height': 0, 'font-size': 'large' } );
} );
// Tooltips
$( document ).on( 'mousemove', function ( event ) {
$( '.tooltip:hover > .tooltip-block' ).css( { 'left': event.clientX + 10 + 'px', 'top': event.clientY + 20 + 'px' } );
} );
$( function () {
// Links titles
$( '.notitle, .tooltip' )
.find( 'a' )
.attr( 'title', '' );
// Nav
$( '.nav-master-button-visible' ).hide();
$( '.nav-master-button-collapsed' ).show();
$( '.nav-master' ).hide();
$( '.nav-master-button-visible' ).click( function () {
$( '.nav-master-button-visible' ).hide();
$( '.nav-master-button-collapsed' ).show();
$( '.nav-master' ).hide();
} );
$( '.nav-master-button-collapsed' ).click( function () {
$( '.nav-master-button-visible' ).show();
$( '.nav-master-button-collapsed' ).hide();
$( '.nav-master' ).show();
} );
// Slideshows initialization
var $slideshows = $( '.infobox-slideshow' ),
anim = new Array( $slideshows.size() ).fill( 0 );
$slideshows.each( function () {
var maxHeight = 0,
maxWidth = 0;
$( this )
.find( '.slide' )
.each( function () {
maxHeight = Math.max( maxHeight, $( this ).height() );
maxWidth = Math.max( maxWidth , $( this ).width() );
} );
$( this )
.height( maxHeight )
.width ( maxWidth );
} );
// Slideshows loop
setInterval( function () {
$slideshows.each( function ( i, slideshow ) {
var $slides = $( slideshow ).find( '.slide' );
if ( $slides.length > 1 )
if ( $( slideshow ).hasClass( 'infobox-slideshow-smooth' ) ) {
$( $slides.get( anim[ i ] ) ).fadeOut( 'slow' );
anim[ i ] = $slides.get( anim[ i ] + 1 ) ? anim[ i ] + 1 : 0;
$( $slides.get( anim[ i ] ) ).fadeIn( 'slow' );
} else {
$( $slides.get( anim[ i ] ) ).fadeOut( 'slow' );
anim[ i ] = $slides.get( anim[ i ] + 1 ) ? anim[ i ] + 1 : 0;
$( $slides.get( anim[ i ] ) ).fadeIn( 'slow' );
}
} );
}, 3000 );
} )
// Translation progress
var pageName = mw.config.get( 'wgPageName' );
fetch( "https://bindingofisaacrebirth-fr.gamepedia.com/api.php?format=json&action=cargoquery&tables=maintenance&fields=origine,revision&where=_pageName='" + pageName + "'&limit=1" )
.then( function( r ) { return r.json(); } )
.then( function( r ) {
if ( r.cargoquery.length ) {
var fr = r.cargoquery[0].title;
var revision = fr.revision;
var origine = fr.origine;
fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&pageids=" + origine )
.then( function( r2 ) { return r2.json(); } )
.then( function( r2 ) {
var lastRevision = r2.query.pages[origine].revisions[0].revid;
if ( lastRevision == revision ) {
$( 'body.action-view #firstHeading' )
.prepend( '<div style="width: 15px; height: 15px; float: right; background: green"></div>' );
$( 'body.action-edit #mw-translation-editnotice' )
.css( 'background', 'green' )
.html( '<b>Cette page est à jour.</b><br>Elle est une traduction de la révision <code>' + lastRevision + '</code> de la page <a href="https://bindingofisaacrebirth.gamepedia.com/index.php?curid=' + origine + '">' + r2.query.pages[origine].title + '</a>.' );
} else {
$( 'body.action-view #firstHeading' )
.prepend( '<a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '"><div style="width: 15px; height: 15px; float: right; background: darkred"></div></a>' );
$( 'body.action-edit #mw-translation-editnotice' )
.css( 'background', 'darkred' )
.html( '<b>Cette page n’est pas à jour.</b><br>Vous pouvez aider en <a target="_blank" rel="noopener noreferrer" href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '">la mettant à jour</a>, puis en remplaçant <code>{{révision | ' + revision + ' | ' + origine + ' }}</code> par <code>{{révision | ' + lastRevision + ' | ' + origine + ' }}</code> en haut de la page.' );
}
} );
} else
$( 'body.action-edit #mw-translation-editnotice' )
.append( '<br><br>Entrer le nom d’une page pour obtenir le texte correspondant à la dernière révision.<br><div class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-textInputWidget oo-ui-textInputWidget-type-text oo-ui-labelElement" style="width: 40%; display: inline-block"><input type="text" id="mw-translation-editnotice-search" class="oo-ui-inputWidget-input"></div><a class="mw-ui-button button" style="min-width: 30px; margin-right: 0.5em" onclick="translationSearch()"><b>></b></a><br><code>{{révision | <span id="mw-translation-editnotice-revision"></span> | <span id="mw-translation-editnotice-origine"></span> }}</code>' );
} );
function translationSearch() {
var pageName = $( '#mw-translation-editnotice-search' ).val();
fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&titles=" + pageName )
.then( function( r ) { return r.json(); } )
.then( function( r ) {
var pages = r.query.pages;
var p;
for ( p in pages )
break;
if ( p === "-1" )
$( '#mw-translation-editnotice-revision, #mw-translation-editnotice-origine' ).html( '' );
else {
var page = pages[p];
$( '#mw-translation-editnotice-revision' ).html( page.revisions[0].revid );
$( '#mw-translation-editnotice-origine' ).html( page.pageid );
}
} );
}
// Outdated pages list
var $list = $( '#mw-translation-list' );
if ( $list.length )
fetch( "https://bindingofisaacrebirth-fr.gamepedia.com/api.php?format=json&action=cargoquery&tables=maintenance&fields=_pageName=page,origine,revision&limit=500" )
.then( function( r ) { return r.json(); } )
.then( function( r ) {
var pages = r.cargoquery;
for ( var p in pages )
li( pages[p].title );
} );
function li( page ) {
var title = page.page;
var revision = page.revision;
var origine = page.origine;
if ( origine !== "0" )
fetch( "https://cors-anywhere.herokuapp.com/https://bindingofisaacrebirth.gamepedia.com/api.php?format=json&action=query&prop=revisions&pageids=" + origine )
.then( function( r ) { return r.json(); } )
.then( function( r ) {
var lastRevision = r.query.pages[origine].revisions[0].revid;
$list.append( '<li><a href="https://bindingofisaacrebirth-fr.gamepedia.com/index.php?title=' + title + '">' + title + '</a> : <a href="https://bindingofisaacrebirth.gamepedia.com/index.php?type=revision&diff=' + lastRevision + '&oldid=' + revision + '"><code>' + revision + '</code> -> <code>' + lastRevision + '</code></a>' );
} );
}