MediaWiki:Common.js

From Diustou Wiki
Revision as of 14:18, 18 March 2021 by Admin (talk | contribs) (Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $(function() { showProductTabs(); hideToc(); addLanguageBtn(); }); function showProductTabs()...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
  showProductTabs();
  hideToc();
  addLanguageBtn();
});

function showProductTabs() {
  var $productTabs = $("tbody .tabbertab");
  $.each($productTabs, function(i, tab) {
    $(tab).css("border", "1px solid #ccc");
	info = $("<p></p>").text($(tab).attr("title"));
    $(tab).find("a").append(info);
  });
}

function hideToc() {
  var toc = document.getElementById("toctogglecheckbox");
  if (toc) {
    toc.checked = true;
  }
}

function addLanguageBtn() {
    var caHistory = document.querySelector('#ca-history');
    if (caHistory != null) {
        var currentURL = window.location.pathname;
        var urlParts = currentURL.split('/');
        urlParts[1] = 'cn';
        var redirectURL = urlParts.join('/');
        var caLanguage = document.createElement('li');
        caLanguage.id = 'ca-varlang-1';
        caLanguage.innerHTML = '<a href=' + redirectURL + ' lang="en" hreflang="en">中文</a>';
        caHistory.parentNode.appendChild(caLanguage);
    }
}