「MediaWiki:Common.js」の版間の差分

提供: 小樽のじかん事典
編集の要約なし
タグ: 差し戻し済み
編集の要約なし
 
(同じ利用者による、間の7版が非表示)
3行目: 3行目:
  * 既に書き換え済みの場合は処理をスキップするように修正しました。
  * 既に書き換え済みの場合は処理をスキップするように修正しました。
  */
  */
(function() {
(function () {
    var enforce = function() {
  function enforce() {
        if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return;
    if (!window.mw || !mw.config) return;
    if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return;
 
    // 1. ラベルの書き換え
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
      var label = labels[i];


        // 1. メールアドレスの書き換え
      // メールアドレス
        var labels = document.getElementsByTagName('label');
      if (label.getAttribute('for') === 'wpEmail' || (label.innerHTML || '').indexOf('メールアドレス') !== -1) {
        for (var i = 0; i < labels.length; i++) {
        if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
            var label = labels[i];
          label.innerHTML = 'メールアドレス';
            // 「(省略可能)」が含まれている場合のみ書き換える(無限ループ防止)
            if (label.getAttribute('for') === 'wpEmail' || label.innerHTML.indexOf('メールアドレス') !== -1) {
                if (label.innerHTML.indexOf('(省略可能)') !== -1) {
                    label.innerHTML = 'メールアドレス';
                }
            }
            // 本名の書き換え
            if (label.getAttribute('for') === 'wpRealName' || label.innerHTML.indexOf('HN') !== -1) {
                if (label.innerHTML.indexOf('(省略可能)') !== -1) {
                    label.innerHTML = 'HN(省略可能)';
                }
            }
         }
         }
      }


        // 2. 必須属性の付与
      // 本名(HN)
        var emailInput = document.getElementById('wpEmail');
      if (label.getAttribute('for') === 'wpRealName' || (label.innerHTML || '').indexOf('HN') !== -1) {
         if (emailInput && !emailInput.required) {
         if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
            emailInput.required = true;
          label.innerHTML = 'HN(省略可能)';
            emailInput.setAttribute('required', 'required');
         }
         }
     };
      }
     }
 
    // 2. 必須属性の付与
    var emailInput = document.getElementById('wpEmail');
    if (emailInput && !emailInput.required) {
      emailInput.required = true;
      emailInput.setAttribute('required', 'required');
    }
  }


    if (mw.config.get('wgCanonicalSpecialPageName') === 'CreateAccount') {
  function boot() {
        // 初回実行
    enforce();
        enforce();


        // 監視対象を限定し、無限ループを回避
    // 監視対象を限定
        var observer = new MutationObserver(function(mutations) {
    var target = document.getElementById('mw-content-text');
            for (var i = 0; i < mutations.length; i++) {
    if (!target || !window.MutationObserver) return;
                if (mutations[i].addedNodes.length > 0) {
                    enforce();
                    break;
                }
            }
        });


        var target = document.getElementById('mw-content-text');
    var observer = new MutationObserver(function (mutations) {
         if (target) {
      for (var i = 0; i < mutations.length; i++) {
            observer.observe(target, {childList: true, subtree: true});
         if (mutations[i].addedNodes && mutations[i].addedNodes.length > 0) {
          enforce();
          break;
         }
         }
     }
      }
     });
 
    observer.observe(target, { childList: true, subtree: true });
  }
 
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', boot);
  } else {
    boot();
  }
})();
})();


/**
* Comments: 「並べ替え」「自動更新」UIを非表示(mw依存なし)
*/
(function () {
(function () {
   window.RLQ = window.RLQ || [];
   function hideAutoUpdate(root) {
  window.RLQ.push(function () {
     var links = root.querySelectorAll('a');
     var TEXT_SORT = '日付順に並べ替え';
     for (var i = 0; i < links.length; i++) {
     var TEXT_AUTO = 'コメントの自動更新を有効化';
       var a = links[i];
 
      var t = (a.textContent || '').trim();
    function trim(s) {
      if (t.indexOf('コメントの自動更新を有効化') !== -1) {
       return (s || '').replace(/^\s+|\s+$/g, '');
        a.style.display = 'none';
      }
     }
     }
  }


    function dispatchChange(input) {
  function apply() {
      try {
    var root = document.getElementById('comments-body');
        if (document.createEvent) {
    if (!root) return;
          var ev = document.createEvent('HTMLEvents');
    hideAutoUpdate(root);
          ev.initEvent('change', true, false);
  }
          input.dispatchEvent(ev);
        }
      } catch (e) {}
    }


    function hideByText(text) {
  function boot() {
      var scope = document.getElementById('mw-data-after-content') || document.body;
    apply();
      if (!scope) return;


      var nodes = scope.querySelectorAll('label, a, span, div, li, p');
    var watchRoot =
       for (var i = 0; i < nodes.length; i++) {
      document.getElementById('comments-body') ||
        var el = nodes[i];
       document.getElementById('mw-data-after-content') ||
        var t = trim(el.textContent);
      document.body;
        if (!t) continue;
        if (t.indexOf(text) === -1) continue;


        // ラベルがチェックボックスを指していればOFF化
    if (watchRoot && window.MutationObserver) {
        var forId = el.getAttribute ? el.getAttribute('for') : null;
      var obs = new MutationObserver(function () { apply(); });
        if (forId) {
      obs.observe(watchRoot, { childList: true, subtree: true });
          var input = document.getElementById(forId);
    }
          if (input && input.type === 'checkbox' && input.checked) {
  }
            input.checked = false;
            dispatchChange(input);
          }
        }


        // 近い親要素を隠す(closest を使わない)
  if (window.RLQ && typeof window.RLQ.push === 'function') {
        var box = el;
    window.RLQ.push(boot);
        for (var step = 0; step < 6; step++) {
  } else if (document.readyState === 'loading') {
          if (!box || !box.parentNode) break;
    document.addEventListener('DOMContentLoaded', boot);
          var cls = String(box.className || '');
  } else {
          if (cls.indexOf('oo-ui') !== -1 || cls.indexOf('mw-ui') !== -1 || cls.indexOf('comments') !== -1) {
    boot();
            break;
  }
          }
})();
          box = box.parentNode;
        }
        (box || el).style.display = 'none';
      }
    }


    function apply() {
/* anonの時刻補正(必ず落ちない版) */
      hideByText(TEXT_SORT);
window.RLQ = window.RLQ || [];
      hideByText(TEXT_AUTO);
window.RLQ.push(function () {
    }
  if (!window.mw || !mw.loader) return;


    function boot() {
  mw.loader.using(['mediawiki.user', 'user.options']).done(function () {
      apply();
    if (!mw.user || typeof mw.user.isAnon !== 'function' || !mw.user.options) return;


      var watchRoot = document.getElementById('mw-data-after-content') || document.body;
    // 匿名で timecorrection が未設定のときだけ補う
      if (watchRoot && window.MutationObserver) {
    if (mw.user.isAnon() && !mw.user.options.get('timecorrection')) {
        var obs = new MutationObserver(function () {
       mw.user.options.set('timecorrection', 'ZoneInfo|Asia/Tokyo');
          apply();
        });
        obs.observe(watchRoot, { childList: true, subtree: true });
       } else {
        setInterval(apply, 1000);
      }
     }
     }
    // comments-body が出るまで少し待つ
    var tries = 0;
    var timer = setInterval(function () {
      tries++;
      if (document.getElementById('comments-body') || document.querySelector('.comments')) {
        clearInterval(timer);
        boot();
        return;
      }
      if (tries > 40) {
        clearInterval(timer);
      }
    }, 250);
   });
   });
})();
});

2026年1月25日 (日) 19:24時点における最新版

/**
 * MediaWiki 1.44.3 アカウント作成画面 無限ループ防止版
 * 既に書き換え済みの場合は処理をスキップするように修正しました。
 */
(function () {
  function enforce() {
    if (!window.mw || !mw.config) return;
    if (mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') return;

    // 1. ラベルの書き換え
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
      var label = labels[i];

      // メールアドレス
      if (label.getAttribute('for') === 'wpEmail' || (label.innerHTML || '').indexOf('メールアドレス') !== -1) {
        if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
          label.innerHTML = 'メールアドレス';
        }
      }

      // 本名(HN)
      if (label.getAttribute('for') === 'wpRealName' || (label.innerHTML || '').indexOf('HN') !== -1) {
        if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
          label.innerHTML = 'HN(省略可能)';
        }
      }
    }

    // 2. 必須属性の付与
    var emailInput = document.getElementById('wpEmail');
    if (emailInput && !emailInput.required) {
      emailInput.required = true;
      emailInput.setAttribute('required', 'required');
    }
  }

  function boot() {
    enforce();

    // 監視対象を限定
    var target = document.getElementById('mw-content-text');
    if (!target || !window.MutationObserver) return;

    var observer = new MutationObserver(function (mutations) {
      for (var i = 0; i < mutations.length; i++) {
        if (mutations[i].addedNodes && mutations[i].addedNodes.length > 0) {
          enforce();
          break;
        }
      }
    });

    observer.observe(target, { childList: true, subtree: true });
  }

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

/**
 * Comments: 「並べ替え」「自動更新」UIを非表示(mw依存なし)
 */
(function () {
  function hideAutoUpdate(root) {
    var links = root.querySelectorAll('a');
    for (var i = 0; i < links.length; i++) {
      var a = links[i];
      var t = (a.textContent || '').trim();
      if (t.indexOf('コメントの自動更新を有効化') !== -1) {
        a.style.display = 'none';
      }
    }
  }

  function apply() {
    var root = document.getElementById('comments-body');
    if (!root) return;
    hideAutoUpdate(root);
  }

  function boot() {
    apply();

    var watchRoot =
      document.getElementById('comments-body') ||
      document.getElementById('mw-data-after-content') ||
      document.body;

    if (watchRoot && window.MutationObserver) {
      var obs = new MutationObserver(function () { apply(); });
      obs.observe(watchRoot, { childList: true, subtree: true });
    }
  }

  if (window.RLQ && typeof window.RLQ.push === 'function') {
    window.RLQ.push(boot);
  } else if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', boot);
  } else {
    boot();
  }
})();

/* anonの時刻補正(必ず落ちない版) */
window.RLQ = window.RLQ || [];
window.RLQ.push(function () {
  if (!window.mw || !mw.loader) return;

  mw.loader.using(['mediawiki.user', 'user.options']).done(function () {
    if (!mw.user || typeof mw.user.isAnon !== 'function' || !mw.user.options) return;

    // 匿名で timecorrection が未設定のときだけ補う
    if (mw.user.isAnon() && !mw.user.options.get('timecorrection')) {
      mw.user.options.set('timecorrection', 'ZoneInfo|Asia/Tokyo');
    }
  });
});