MediaWiki:Common.js

本版日期︰二〇二四年四月一一日 (四) 一一時五五分;作者︰十八子

註:重取頁面,文方新焉。

  • Firefox / Safari:Shift 並點 重新載入,或合鍵 Ctrl-F5Ctrl-R(Mac 為 ⌘-R)。
  • Google Chrome:Ctrl-Shift-R(Mac為 ⌘-Shift-R)。
  • Internet Explorer:Ctrl 並點 重新整理,或合鍵 Ctrl-F5
  • Opera:須至 Tools → Preferences 清謄本(Mac 為 Opera → Preferences)。
/* 此之JavaScript將載於全簿之頁。 */

var removeToggleMenu = function(featureName) {
    var menu = document.querySelector('a.toggle-' + featureName);
    menu && menu.parentNode.removeChild(menu);
}

var applyToggleMenu = function(featureName) {
    var menu = document.querySelector('a.toggle-' + featureName);
    if(!menu) return;
    var url = new URL(location.href);
    url.searchParams.set(featureName, 'toggle');
    menu.href = url.href;
}

var applyToggleFeature = function(featureName) {
    var localStorage = window.localStorage;
    var url = new URL(location.href);
    var urlParam = url.searchParams.get(featureName);
    var lsParam = localStorage && localStorage.getItem(featureName);
    var use = urlParam || lsParam || 'false';
    if(urlParam == 'toggle') {
        use = lsParam == 'false' ? 'true' : 'false';
        url.searchParams.set(featureName, use);
        location.href = url.href;
    }
    if(use == 'true') {
        document.body.classList.add('use-' + featureName);
    }
    if(use == 'false') {
        document.body.classList.remove('use-' + featureName);
    }
    localStorage && localStorage.setItem(featureName, use);
};

var addToggleFeature = function(featureName) {
    applyToggleFeature(featureName);
    window.addEventListener('load', function() {
        applyToggleFeature(featureName);
    });
    applyToggleMenu(featureName);
    window.addEventListener('load', function() {
        applyToggleMenu(featureName);
    });
}

mw.loader.using(['mediawiki.util'], function() {
    addToggleFeature('hangul');
    addToggleFeature('kaeriten');
    document.querySelector('input#searchInput').addEventListener('input', function() {
        $(this).trigger('keypress');
    });
});

var sectionCJK = {
  type: 'booklet',
  label: '漢',
  pages: {
    'Punct': {
      layout: 'characters',
      label: '、。〃',
      characters: [' ', '、', '。', '〃', '〄', '々', '〆', '〇', '〈', '〉', '《', '》', '「', '」', '『', '』', '【', '】', '〒', '〓', '〔', '〕', '〖', '〗', '〘', '〙', '〚', '〛', '〜', '〝', '〞', '〟', '〠', '〡', '〢', '〣', '〤', '〥', '〦', '〧', '〨', '〩', '〪', '〫', '〬', '〭', '〮', '〯', '〰', '〱', '〲', '〳', '〴', '〵', '〶', '〷', '〸', '〹', '〺', '〻', '〼', '〽']
    },
    'IDC': {
      layout: 'characters',
      label: '⿰⿱⿻',
      characters: ['⿰', '⿱', '⿲', '⿳', '⿴', '⿵', '⿶', '⿷', '⿸', '⿹', '⿺', '⿻']
    },
    'Kanbun': {
      layout: 'characters',
      label: '㆑㆒㆓',
      characters: ['㆐', '㆑', '㆒', '㆓', '㆔', '㆕', '㆖', '㆗', '㆘', '㆙', '㆚', '㆛', '㆜', '㆝', '㆞', '㆟']
    }
  }
}

mw.hook('wikiEditor.toolbarReady').add(function($textarea) {
  $textarea.wikiEditor('addToToolbar', {
    'sections': {
      'CJK': sectionCJK
    }
  });
});