Diferencia entre revisiones de «MediaWiki:Common.js»

De Oroza RO Wiki
Ir a la navegación Ir a la búsqueda
Página creada con «function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'es', includedLanguages: 'en,pt', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } var gtScript = document.createElement('script'); gtScript.type = 'text/javascript'; gtScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'; document.head.appendChild(gtScript); // Cambiar idio…»
 
Sin resumen de edición
 
(No se muestran 6 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
function googleTranslateElementInit() {
(function () {
   new google.translate.TranslateElement({
  function safeNormalize(text) {
     pageLanguage: 'es',
    text = String(text || '').toLowerCase().trim();
     includedLanguages: 'en,pt',
 
     layout: google.translate.TranslateElement.InlineLayout.SIMPLE
    try {
   }, 'google_translate_element');
      return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
    } catch (e) {
      return text;
    }
  }
 
  function hasMark(cellText) {
    cellText = String(cellText || '').replace(/\s+/g, '').trim();
 
    return (
      cellText !== '' &&
      (
        cellText.indexOf('✔') !== -1 ||
        cellText.indexOf('✅') !== -1 ||
        cellText.indexOf('☑') !== -1
      )
    );
  }
 
  function getActiveCategoryCol(tableId) {
    var activeBtn = document.querySelector('.oroza-cat-btn.active[data-table="' + tableId + '"]');
    if (!activeBtn) {
      var firstBtn = document.querySelector('.oroza-cat-btn[data-table="' + tableId + '"]');
      if (!firstBtn) return null;
      firstBtn.classList.add('active');
      return firstBtn.getAttribute('data-col');
    }
    return activeBtn.getAttribute('data-col'); // Puede retornar "all" en string
  }
 
   function getSearchTextForRow(row, tableId) {
    var cells = row.getElementsByTagName('td');
    var text = row.getAttribute('data-search') || '';
    // Como añadimos "Prob.", ahora las columnas de información base son 3 en Slot 1 y 4 en Slot 2
    var visibleInfoCols = tableId === 'tableSlot1' ? 3 : 4;
 
    for (var i = 0; i < visibleInfoCols; i++) {
      if (cells[i]) {
        text += ' ' + (cells[i].textContent || cells[i].innerText || '');
      }
    }
 
    return safeNormalize(text);
  }
 
  function updateCategoryView(tableId, inputId) {
     var table = document.getElementById(tableId);
    var input = document.getElementById(inputId);
 
    if (!table || !table.tBodies.length || !table.tHead || !table.tHead.rows.length) return;
 
    var activeColRaw = getActiveCategoryCol(tableId);
    if (activeColRaw === null) return;
 
    var showAll = (activeColRaw === 'all');
    var activeCol = showAll ? -1 : parseInt(activeColRaw, 10);
 
    var searchText = input ? safeNormalize(input.value) : '';
    var rows = table.tBodies[0].getElementsByTagName('tr');
    var headerRow = table.tHead.rows[0];
   
    // Columnas que SIEMPRE se ven (Atributo, Prob, Rango, etc.)
     var staticCols = tableId === 'tableSlot1' ? 3 : 4;
 
    // Actualizar Header
    for (var h = 0; h < headerRow.cells.length; h++) {
      headerRow.cells[h].style.display = (showAll || h < staticCols || h === activeCol) ? '' : 'none';
    }
 
    // Actualizar Body
    for (var i = 0; i < rows.length; i++) {
      var row = rows[i];
      var cells = row.getElementsByTagName('td');
     
      // Si estamos en "Todos", empezamos asumiendo que sí tiene categoría válida
      var matchCategory = showAll;
      var matchText = true;
 
      // Si se escogió una categoría específica, verificamos si tiene "✔"
      if (!showAll && cells[activeCol]) {
        matchCategory = hasMark(cells[activeCol].textContent || cells[activeCol].innerText);
      }
 
      // Verificación de búsqueda por texto
      if (searchText !== '') {
        var searchPool = getSearchTextForRow(row, tableId);
        if (searchPool.indexOf(searchText) === -1) {
          matchText = false;
        }
      }
 
      row.style.display = (matchCategory && matchText) ? '' : 'none';
 
      for (var c = 0; c < cells.length; c++) {
        cells[c].style.display = (showAll || c < staticCols || c === activeCol) ? '' : 'none';
      }
    }
  }
 
  function bindCategoryButtons(tableId, inputId) {
    var buttons = document.querySelectorAll('.oroza-cat-btn[data-table="' + tableId + '"]');
 
     for (var i = 0; i < buttons.length; i++) {
      if (buttons[i].dataset.orozaBound === '1') continue;
 
      buttons[i].dataset.orozaBound = '1';
      buttons[i].addEventListener('click', function () {
        var sameTableButtons = document.querySelectorAll('.oroza-cat-btn[data-table="' + tableId + '"]');
        for (var j = 0; j < sameTableButtons.length; j++) {
          sameTableButtons[j].classList.remove('active');
        }
 
        this.classList.add('active');
        updateCategoryView(tableId, inputId);
      });
    }
  }
 
  function bindSearchInput(tableId, inputId) {
    var input = document.getElementById(inputId);
    if (!input || input.dataset.orozaBound === '1') return;
 
    input.dataset.orozaBound = '1';
    input.addEventListener('input', function () {
      updateCategoryView(tableId, inputId);
    });
  }
 
  function initOrozaDropFilters() {
    if (document.getElementById('tableSlot1')) {
      bindCategoryButtons('tableSlot1', 'textSlot1');
      bindSearchInput('tableSlot1', 'textSlot1');
      updateCategoryView('tableSlot1', 'textSlot1');
    }
 
    if (document.getElementById('tableSlot2')) {
      bindCategoryButtons('tableSlot2', 'textSlot2');
      bindSearchInput('tableSlot2', 'textSlot2');
      updateCategoryView('tableSlot2', 'textSlot2');
    }
  }
 
  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(function () {
      initOrozaDropFilters();
    });
  } else if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initOrozaDropFilters);
  } else {
    initOrozaDropFilters();
  }
})();
 
/* =========================================================
  RESALTAR MENÚ LATERAL ACTIVO (VERSIÓN NATIVA MEDIAWIKI)
========================================================= */
function highlightActiveSidebarLink() {
  // 1. Obtenemos el nombre exacto de la página actual desde el motor de MediaWiki
  var currentPage = mw.config.get('wgPageName');
  if (!currentPage) return;
 
  // Limpiamos el nombre de la página actual (todo a minúsculas y espacios a guiones bajos)
  currentPage = currentPage.replace(/ /g, '_').toLowerCase();
 
  var sidebarLinks = document.querySelectorAll('.oroza-sidebar li a');
 
   for (var i = 0; i < sidebarLinks.length; i++) {
    var linkHref = sidebarLinks[i].getAttribute('href');
    if (!linkHref) continue;
 
    // 2. Extraemos el nombre de la página del enlace del menú
    var linkPage = "";
    if (linkHref.indexOf('title=') !== -1) {
      linkPage = linkHref.split('title=')[1].split('&')[0];
    } else {
      linkPage = linkHref.split('/').pop(); // Toma lo último después del slash (ej. "Como-instalarlo")
    }
 
    if (!linkPage) continue;
 
    // 3. Decodificamos caracteres especiales (como acentos o espacios %20)
    try {
      linkPage = decodeURIComponent(linkPage);
    } catch(e) {}
 
    // Limpiamos el enlace de la misma forma para que la comparación sea exacta
    linkPage = linkPage.replace(/ /g, '_').toLowerCase();
 
    // 4. Comparamos
    if (currentPage === linkPage) {
      sidebarLinks[i].classList.add('active');
    } else {
      sidebarLinks[i].classList.remove('active'); // Limpia los demás por si acaso
    }
  }
}
 
// Integración con MediaWiki
if (window.mw && mw.hook) {
  mw.hook('wikipage.content').add(highlightActiveSidebarLink);
} else if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', highlightActiveSidebarLink);
} else {
  highlightActiveSidebarLink();
}
}


var gtScript = document.createElement('script');
gtScript.type = 'text/javascript';
gtScript.src = '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit';
document.head.appendChild(gtScript);


// Cambiar idioma al hacer clic
 
window.changeLang = function(lang) {
/* =========================================================
   const interval = setInterval(() => {
  OROZA PET ATTACK REBALANCE V13.3 - SIMPLE SEARCH
     const combo = document.querySelector('.goog-te-combo');
  Paste into MediaWiki:Common.js
     if (combo && combo.options.length > 1) {
========================================================= */
       combo.value = lang;
(function () {
       combo.dispatchEvent(new Event('change'));
  function normalize(text) {
       clearInterval(interval);
    return (text || '')
      .toString()
      .toLowerCase()
      .normalize('NFD')
      .replace(/[\u0300-\u036f]/g, '')
      .replace(/_/g, ' ')
      .replace(/\s+/g, ' ')
      .trim();
  }
 
   function initOrozaPetSearchV9(root) {
    root = root || document;
 
    var input = root.querySelector ? root.querySelector('#orozaPetSearchV6') : document.getElementById('orozaPetSearchV6');
    if (!input || input.dataset.ready === 'v9') return;
    input.dataset.ready = 'v9';
 
     var container = input.closest('.oroza-pet-v6') || document;
    var cards = Array.prototype.slice.call(container.querySelectorAll('.oroza-pet-v6-card'));
    var sections = Array.prototype.slice.call(container.querySelectorAll('[data-pet-section]'));
    var result = container.querySelector('#orozaPetSearchV6Result');
    var clearBtn = container.querySelector('[data-pet-clear]');
 
     function applySearch() {
      var q = normalize(input.value);
      var shown = 0;
 
      cards.forEach(function (card) {
        var haystack = normalize((card.getAttribute('data-pet-search') || '') + ' ' + card.textContent);
        var match = !q || haystack.indexOf(q) !== -1;
 
        card.classList.toggle('is-hidden', !match);
        if (match) shown++;
      });
 
      sections.forEach(function (section) {
        var visibleCards = section.querySelectorAll('.oroza-pet-v6-card:not(.is-hidden)').length;
        var shouldHide = visibleCards === 0 && q;
        section.classList.toggle('is-hidden', shouldHide);
        if (!shouldHide && q) section.open = true;
      });
 
      if (result) {
        if (shown === 0) {
          result.textContent = 'No pets were found with that text.';
        } else if (q) {
          result.textContent = 'Visible results: ' + shown + '. Open the card to review each Pokémon skill and level.';
        } else {
          result.textContent = 'Showing all pets.';
        }
       }
    }
 
    input.addEventListener('input', applySearch);
 
    if (clearBtn) {
       clearBtn.addEventListener('click', function () {
        input.value = '';
        applySearch();
        input.focus();
       });
     }
     }
   }, 200);
 
};
    applySearch();
   }
 
  function boot() {
    initOrozaPetSearchV9(document);
  }
 
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', boot);
  } else {
    boot();
  }
 
  if (window.mw && window.mw.hook) {
    window.mw.hook('wikipage.content').add(function ($content) {
      var node = $content && $content[0] ? $content[0] : document;
      initOrozaPetSearchV9(node);
    });
  }
})();

Revisión actual - 22:43 11 may 2026

(function () {
  function safeNormalize(text) {
    text = String(text || '').toLowerCase().trim();

    try {
      return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
    } catch (e) {
      return text;
    }
  }

  function hasMark(cellText) {
    cellText = String(cellText || '').replace(/\s+/g, '').trim();

    return (
      cellText !== '' &&
      (
        cellText.indexOf('✔') !== -1 ||
        cellText.indexOf('✅') !== -1 ||
        cellText.indexOf('☑') !== -1
      )
    );
  }

  function getActiveCategoryCol(tableId) {
    var activeBtn = document.querySelector('.oroza-cat-btn.active[data-table="' + tableId + '"]');
    if (!activeBtn) {
      var firstBtn = document.querySelector('.oroza-cat-btn[data-table="' + tableId + '"]');
      if (!firstBtn) return null;
      firstBtn.classList.add('active');
      return firstBtn.getAttribute('data-col'); 
    }
    return activeBtn.getAttribute('data-col'); // Puede retornar "all" en string
  }

  function getSearchTextForRow(row, tableId) {
    var cells = row.getElementsByTagName('td');
    var text = row.getAttribute('data-search') || '';
    // Como añadimos "Prob.", ahora las columnas de información base son 3 en Slot 1 y 4 en Slot 2
    var visibleInfoCols = tableId === 'tableSlot1' ? 3 : 4;

    for (var i = 0; i < visibleInfoCols; i++) {
      if (cells[i]) {
        text += ' ' + (cells[i].textContent || cells[i].innerText || '');
      }
    }

    return safeNormalize(text);
  }

  function updateCategoryView(tableId, inputId) {
    var table = document.getElementById(tableId);
    var input = document.getElementById(inputId);

    if (!table || !table.tBodies.length || !table.tHead || !table.tHead.rows.length) return;

    var activeColRaw = getActiveCategoryCol(tableId);
    if (activeColRaw === null) return;

    var showAll = (activeColRaw === 'all');
    var activeCol = showAll ? -1 : parseInt(activeColRaw, 10);

    var searchText = input ? safeNormalize(input.value) : '';
    var rows = table.tBodies[0].getElementsByTagName('tr');
    var headerRow = table.tHead.rows[0];
    
    // Columnas que SIEMPRE se ven (Atributo, Prob, Rango, etc.)
    var staticCols = tableId === 'tableSlot1' ? 3 : 4;

    // Actualizar Header
    for (var h = 0; h < headerRow.cells.length; h++) {
      headerRow.cells[h].style.display = (showAll || h < staticCols || h === activeCol) ? '' : 'none';
    }

    // Actualizar Body
    for (var i = 0; i < rows.length; i++) {
      var row = rows[i];
      var cells = row.getElementsByTagName('td');
      
      // Si estamos en "Todos", empezamos asumiendo que sí tiene categoría válida
      var matchCategory = showAll;
      var matchText = true;

      // Si se escogió una categoría específica, verificamos si tiene "✔"
      if (!showAll && cells[activeCol]) {
        matchCategory = hasMark(cells[activeCol].textContent || cells[activeCol].innerText);
      }

      // Verificación de búsqueda por texto
      if (searchText !== '') {
        var searchPool = getSearchTextForRow(row, tableId);
        if (searchPool.indexOf(searchText) === -1) {
          matchText = false;
        }
      }

      row.style.display = (matchCategory && matchText) ? '' : 'none';

      for (var c = 0; c < cells.length; c++) {
        cells[c].style.display = (showAll || c < staticCols || c === activeCol) ? '' : 'none';
      }
    }
  }

  function bindCategoryButtons(tableId, inputId) {
    var buttons = document.querySelectorAll('.oroza-cat-btn[data-table="' + tableId + '"]');

    for (var i = 0; i < buttons.length; i++) {
      if (buttons[i].dataset.orozaBound === '1') continue;

      buttons[i].dataset.orozaBound = '1';
      buttons[i].addEventListener('click', function () {
        var sameTableButtons = document.querySelectorAll('.oroza-cat-btn[data-table="' + tableId + '"]');
        for (var j = 0; j < sameTableButtons.length; j++) {
          sameTableButtons[j].classList.remove('active');
        }

        this.classList.add('active');
        updateCategoryView(tableId, inputId);
      });
    }
  }

  function bindSearchInput(tableId, inputId) {
    var input = document.getElementById(inputId);
    if (!input || input.dataset.orozaBound === '1') return;

    input.dataset.orozaBound = '1';
    input.addEventListener('input', function () {
      updateCategoryView(tableId, inputId);
    });
  }

  function initOrozaDropFilters() {
    if (document.getElementById('tableSlot1')) {
      bindCategoryButtons('tableSlot1', 'textSlot1');
      bindSearchInput('tableSlot1', 'textSlot1');
      updateCategoryView('tableSlot1', 'textSlot1');
    }

    if (document.getElementById('tableSlot2')) {
      bindCategoryButtons('tableSlot2', 'textSlot2');
      bindSearchInput('tableSlot2', 'textSlot2');
      updateCategoryView('tableSlot2', 'textSlot2');
    }
  }

  if (window.mw && mw.hook) {
    mw.hook('wikipage.content').add(function () {
      initOrozaDropFilters();
    });
  } else if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initOrozaDropFilters);
  } else {
    initOrozaDropFilters();
  }
})();

/* =========================================================
   RESALTAR MENÚ LATERAL ACTIVO (VERSIÓN NATIVA MEDIAWIKI)
========================================================= */
function highlightActiveSidebarLink() {
  // 1. Obtenemos el nombre exacto de la página actual desde el motor de MediaWiki
  var currentPage = mw.config.get('wgPageName');
  if (!currentPage) return;

  // Limpiamos el nombre de la página actual (todo a minúsculas y espacios a guiones bajos)
  currentPage = currentPage.replace(/ /g, '_').toLowerCase();

  var sidebarLinks = document.querySelectorAll('.oroza-sidebar li a');

  for (var i = 0; i < sidebarLinks.length; i++) {
    var linkHref = sidebarLinks[i].getAttribute('href');
    if (!linkHref) continue;

    // 2. Extraemos el nombre de la página del enlace del menú
    var linkPage = "";
    if (linkHref.indexOf('title=') !== -1) {
      linkPage = linkHref.split('title=')[1].split('&')[0];
    } else {
      linkPage = linkHref.split('/').pop(); // Toma lo último después del slash (ej. "Como-instalarlo")
    }

    if (!linkPage) continue;

    // 3. Decodificamos caracteres especiales (como acentos o espacios %20)
    try {
      linkPage = decodeURIComponent(linkPage);
    } catch(e) {}

    // Limpiamos el enlace de la misma forma para que la comparación sea exacta
    linkPage = linkPage.replace(/ /g, '_').toLowerCase();

    // 4. Comparamos
    if (currentPage === linkPage) {
      sidebarLinks[i].classList.add('active');
    } else {
      sidebarLinks[i].classList.remove('active'); // Limpia los demás por si acaso
    }
  }
}

// Integración con MediaWiki
if (window.mw && mw.hook) {
  mw.hook('wikipage.content').add(highlightActiveSidebarLink);
} else if (document.readyState === 'loading') {
  document.addEventListener('DOMContentLoaded', highlightActiveSidebarLink);
} else {
  highlightActiveSidebarLink();
}



/* =========================================================
   OROZA PET ATTACK REBALANCE V13.3 - SIMPLE SEARCH
   Paste into MediaWiki:Common.js
========================================================= */
(function () {
  function normalize(text) {
    return (text || '')
      .toString()
      .toLowerCase()
      .normalize('NFD')
      .replace(/[\u0300-\u036f]/g, '')
      .replace(/_/g, ' ')
      .replace(/\s+/g, ' ')
      .trim();
  }

  function initOrozaPetSearchV9(root) {
    root = root || document;

    var input = root.querySelector ? root.querySelector('#orozaPetSearchV6') : document.getElementById('orozaPetSearchV6');
    if (!input || input.dataset.ready === 'v9') return;
    input.dataset.ready = 'v9';

    var container = input.closest('.oroza-pet-v6') || document;
    var cards = Array.prototype.slice.call(container.querySelectorAll('.oroza-pet-v6-card'));
    var sections = Array.prototype.slice.call(container.querySelectorAll('[data-pet-section]'));
    var result = container.querySelector('#orozaPetSearchV6Result');
    var clearBtn = container.querySelector('[data-pet-clear]');

    function applySearch() {
      var q = normalize(input.value);
      var shown = 0;

      cards.forEach(function (card) {
        var haystack = normalize((card.getAttribute('data-pet-search') || '') + ' ' + card.textContent);
        var match = !q || haystack.indexOf(q) !== -1;

        card.classList.toggle('is-hidden', !match);
        if (match) shown++;
      });

      sections.forEach(function (section) {
        var visibleCards = section.querySelectorAll('.oroza-pet-v6-card:not(.is-hidden)').length;
        var shouldHide = visibleCards === 0 && q;
        section.classList.toggle('is-hidden', shouldHide);
        if (!shouldHide && q) section.open = true;
      });

      if (result) {
        if (shown === 0) {
          result.textContent = 'No pets were found with that text.';
        } else if (q) {
          result.textContent = 'Visible results: ' + shown + '. Open the card to review each Pokémon skill and level.';
        } else {
          result.textContent = 'Showing all pets.';
        }
      }
    }

    input.addEventListener('input', applySearch);

    if (clearBtn) {
      clearBtn.addEventListener('click', function () {
        input.value = '';
        applySearch();
        input.focus();
      });
    }

    applySearch();
  }

  function boot() {
    initOrozaPetSearchV9(document);
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', boot);
  } else {
    boot();
  }

  if (window.mw && window.mw.hook) {
    window.mw.hook('wikipage.content').add(function ($content) {
      var node = $content && $content[0] ? $content[0] : document;
      initOrozaPetSearchV9(node);
    });
  }
})();