|
|
| Línea 16: |
Línea 16: |
| $temp.remove(); | | $temp.remove(); |
| } ); | | } ); |
|
| |
| if ( window.vanaheimLanguageSwitcherLoaded ) {
| |
| return;
| |
| }
| |
|
| |
| window.vanaheimLanguageSwitcherLoaded = true;
| |
|
| |
| var heading = document.getElementById( 'firstHeading' ) ||
| |
| document.querySelector( '.mw-first-heading' );
| |
|
| |
| if ( !heading ) {
| |
| return;
| |
| }
| |
|
| |
| function originalPageUrl() {
| |
| var url = new URL( window.location.href );
| |
| url.searchParams.delete( 'googtrans' );
| |
| return url.href;
| |
| }
| |
|
| |
| function googleTranslateUrl( targetLanguage ) {
| |
| return 'https://translate.google.com/translate?sl=es&tl=' +
| |
| encodeURIComponent( targetLanguage ) +
| |
| '&u=' + encodeURIComponent( originalPageUrl() );
| |
| }
| |
|
| |
| function makeButton( label, title, href ) {
| |
| var link = document.createElement( 'a' );
| |
| link.href = href;
| |
| link.textContent = label;
| |
| link.title = title;
| |
| link.setAttribute( 'aria-label', title );
| |
| link.style.display = 'inline-flex';
| |
| link.style.alignItems = 'center';
| |
| link.style.justifyContent = 'center';
| |
| link.style.width = '1.9em';
| |
| link.style.height = '1.9em';
| |
| link.style.marginLeft = '0.35em';
| |
| link.style.border = '1px solid #a2a9b1';
| |
| link.style.borderRadius = '999px';
| |
| link.style.background = '#fff';
| |
| link.style.fontSize = '0.55em';
| |
| link.style.lineHeight = '1';
| |
| link.style.textDecoration = 'none';
| |
| link.style.verticalAlign = 'middle';
| |
| link.style.boxShadow = '0 1px 2px rgba(0, 0, 0, 0.12)';
| |
| return link;
| |
| }
| |
|
| |
| var wrapper = document.createElement( 'span' );
| |
| wrapper.className = 'vanaheim-language-switcher';
| |
| wrapper.style.whiteSpace = 'nowrap';
| |
| wrapper.style.marginLeft = '0.35em';
| |
| wrapper.style.fontFamily = 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif';
| |
|
| |
| wrapper.appendChild( makeButton( '🇪🇸', 'Ver página original en español', originalPageUrl() ) );
| |
| wrapper.appendChild( makeButton( '🇺🇸', 'Traducir esta página al inglés con Google Translate', googleTranslateUrl( 'en' ) ) );
| |
|
| |
| heading.appendChild( wrapper );
| |
| } ); | | } ); |