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

提供: 小樽のじかん事典
編集の要約なし
編集の要約なし
 
(同じ利用者による、間の5版が非表示)
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. メールアドレスの書き換え
    // 1. ラベルの書き換え
        var labels = document.getElementsByTagName('label');
    var labels = document.getElementsByTagName('label');
        for (var i = 0; i < labels.length; i++) {
    for (var i = 0; i < labels.length; i++) {
            var label = labels[i];
      var label = labels[i];
            // 「(省略可能)」が含まれている場合のみ書き換える(無限ループ防止)
            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. 必須属性の付与
      // メールアドレス
        var emailInput = document.getElementById('wpEmail');
      if (label.getAttribute('for') === 'wpEmail' || (label.innerHTML || '').indexOf('メールアドレス') !== -1) {
         if (emailInput && !emailInput.required) {
         if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
            emailInput.required = true;
          label.innerHTML = 'メールアドレス';
            emailInput.setAttribute('required', 'required');
         }
         }
    };
      }


    if (mw.config.get('wgCanonicalSpecialPageName') === 'CreateAccount') {
      // 本名(HN)
        // 初回実行
      if (label.getAttribute('for') === 'wpRealName' || (label.innerHTML || '').indexOf('HN') !== -1) {
        enforce();
        if ((label.innerHTML || '').indexOf('(省略可能)') !== -1) {
 
          label.innerHTML = 'HN(省略可能)';
        // 監視対象を限定し、無限ループを回避
        var observer = new MutationObserver(function(mutations) {
            for (var i = 0; i < mutations.length; i++) {
                if (mutations[i].addedNodes.length > 0) {
                    enforce();
                    break;
                }
            }
        });
 
        var target = document.getElementById('mw-content-text');
        if (target) {
            observer.observe(target, {childList: true, subtree: true});
         }
         }
      }
     }
     }
})();


(function () {
     // 2. 必須属性の付与
  function apply() {
     var emailInput = document.getElementById('wpEmail');
     // Comments のDOMがまだなら何もしない
     if (emailInput && !emailInput.required) {
     var root = document.getElementById('comments-body');
      emailInput.required = true;
     if (!root) return;
      emailInput.setAttribute('required', 'required');
    }
  }


    // 1) 並べ替えUI:option文言から親selectを特定して消す
  function boot() {
     var orderTexts = ['日付順に並べ替え', '得点順に並べ替え'];
     enforce();


     var options = root.querySelectorAll('option');
    // 監視対象を限定
     for (var i = 0; i < options.length; i++) {
     var target = document.getElementById('mw-content-text');
      var opt = options[i];
     if (!target || !window.MutationObserver) return;
      var t = (opt.textContent || '').trim();
      if (!t) continue;


      var hit = false;
    var observer = new MutationObserver(function (mutations) {
       for (var j = 0; j < orderTexts.length; j++) {
       for (var i = 0; i < mutations.length; i++) {
         if (t.indexOf(orderTexts[j]) !== -1) {
         if (mutations[i].addedNodes && mutations[i].addedNodes.length > 0) {
           hit = true;
           enforce();
           break;
           break;
         }
         }
       }
       }
      if (!hit) continue;
    });


      var sel = opt.closest ? opt.closest('select') : null;
    observer.observe(target, { childList: true, subtree: true });
      if (!sel) continue;
  }


      // select本体を消す
  if (document.readyState === 'loading') {
      sel.style.display = 'none';
    document.addEventListener('DOMContentLoaded', boot);
  } else {
    boot();
  }
})();


      // 可能なら周辺のラッパも消す(見た目の空きを減らす)
/**
      var wrapper = sel.closest ? sel.closest('label, .c-sort, .c-order, .comments-sort, .comments-order, .c-nav, .c-toolbar, .comments-toolbar') : null;
* Comments: 「並べ替え」「自動更新」UIを非表示(mw依存なし)
      if (wrapper) wrapper.style.display = 'none';
*/
    }
(function () {
 
  function hideAutoUpdate(root) {
    // 2) 自動更新リンク:文言一致のaを消す
     var links = root.querySelectorAll('a');
     var links = root.querySelectorAll('a');
     for (var k = 0; k < links.length; k++) {
     for (var i = 0; i < links.length; i++) {
       var a = links[k];
       var a = links[i];
       var at = (a.textContent || '').trim();
       var t = (a.textContent || '').trim();
       if (at.indexOf('コメントの自動更新を有効化') !== -1) {
       if (t.indexOf('コメントの自動更新を有効化') !== -1) {
         a.style.display = 'none';
         a.style.display = 'none';
        // 可能なら周辺のラッパも消す
        var aw = a.closest ? a.closest('li, div, span, label') : null;
        if (aw) aw.style.display = 'none';
       }
       }
     }
     }
  }
  function apply() {
    var root = document.getElementById('comments-body');
    if (!root) return;
    hideAutoUpdate(root);
   }
   }


107行目: 86行目:
     apply();
     apply();


    // Commentsが後からDOMを描画するので監視して再適用
     var watchRoot =
     var watchRoot = document.getElementById('comments-body') || document.getElementById('mw-data-after-content') || document.body;
      document.getElementById('comments-body') ||
      document.getElementById('mw-data-after-content') ||
      document.body;
 
     if (watchRoot && window.MutationObserver) {
     if (watchRoot && window.MutationObserver) {
       var obs = new MutationObserver(function () { apply(); });
       var obs = new MutationObserver(function () { apply(); });
115行目: 97行目:
   }
   }


  // RLQ優先、なければDOMContentLoaded
   if (window.RLQ && typeof window.RLQ.push === 'function') {
   if (window.RLQ && typeof window.RLQ.push === 'function') {
     window.RLQ.push(boot);
     window.RLQ.push(boot);
124行目: 105行目:
   }
   }
})();
})();
/* 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');
    }
  });
});

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');
    }
  });
});