メニューを切り替える
Toggle preferences menu
個人設定を切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。

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

MediaWikiインターフェイスページ
編集の要約なし
タグ: 差し戻し済み
編集の要約なし
 
(同じ利用者による、間の129版が非表示)
2行目: 2行目:
   // すべての中身をここに入れて動かす
   // すべての中身をここに入れて動かす


    // CSSでボタンをデザイン
$(function () {
     toTopButton.css({
  // Citizenスキンの「案内」セクションを検出して削除
        position: 'fixed',
  $(".mw-portlet h3").each(function () {
        bottom: '20px',
    const heading = $(this);
        right: '20px',
    if (heading.text().trim() === "案内") {
        background: '#555',
      heading.closest(".mw-portlet").remove();
        color: '#fff',
     }
        padding: '5px 10px',
  });
        borderRadius: '4px',
});
        textDecoration: 'none',
$(function () {
        display: 'none', // 初期は非表示
  $(".sidebar-group").each(function () {
        zIndex: '1000'
    const group = $(this);
     });
    const heading = group.find("h2").first().text().trim();
    if (heading === "案内") {
      group.remove();
    }
  });
});
$(function () {
  $(".citizen-menu__heading").each(function () {
    if ($(this).text().trim() === "案内") {
      $(this).next(".citizen-menu__content").remove(); // 中身消す
      $(this).remove(); // 見出しも消す
    }
  });
});
 
 
//メインページだけ読了目安を無効化
$(function () {
  if ( mw.config.get('ReadingTimeDisabled') ) {
     $('.read-time-box, .citizen-page-info-readtime').remove();
  }
});


    // ページに追加
    $('body').append(toTopButton);


    // スクロールしたら表示
//折り畳み機能
    $(window).scroll(function() {
$(function () {
        if ($(this).scrollTop() > 200) {
  $(".mw-collapsible").each(function () {
            toTopButton.fadeIn();
    const $block = $(this);
        } else {
    const $toggle = $('<a href="#" style="float:right;">[開く]</a>');
            toTopButton.fadeOut();
    $toggle.on("click", function (e) {
        }
      e.preventDefault();
      $block.toggleClass("collapsed");
      $block.find("ul").slideToggle();
      $toggle.text($block.hasClass("collapsed") ? "[開く]" : "[閉じる]");
     });
     });
    $block.prepend($toggle);
    if ($block.hasClass("mw-collapsed")) {
      $block.addClass("collapsed");
      $block.find("ul").hide();
    }
  });
});


     // ボタンクリックでトップに戻る
$(function () {
     toTopButton.click(function() {
  $(".u-stella-box").each(function () {
        $('html, body').animate({scrollTop:0}, 500);
     const $block = $(this);
        return false;
    const $toggle = $('<a href="#" style="float:right; font-size:90%;">[+]</a>');
     $toggle.on("click", function (e) {
      e.preventDefault();
      $block.toggleClass("collapsed");
      $block.find("ul").slideToggle();
      $toggle.text($block.hasClass("collapsed") ? "[+]" : "[-]");
     });
     });
    $block.prepend($toggle);
    if ($block.hasClass("collapsed")) {
      $block.find("ul").hide();
    }
  });
});
});


// 外部リンクを新規タブで開く
 
$(function() {
 
   $('a.external').attr('target', '_blank');
  // 全角スペースを黒四角に
mw.hook('wikipage.content').add(function ($content) {
   $content.find('.mw-parser-output').each(function () {
    const $this = $(this);
    const html = $this.html().replace(/ /g, '');
    $this.html(html);
  });
});
});


// 目次トグル機能追加
  // スクロール進捗バー
$(function(){
$(function(){
   var toc = $('#toc');
   var progressBar = $('<div id="progress-bar"></div>').css({
   if(toc.length){
    position:'fixed', top:'0', left:'0', height:'4px',
     toc.before('<button id="toggle-toc">目次を開閉</button>');
    background:'#6cf', width:'0%', zIndex:1000
    $('#toggle-toc').css({
  }).appendTo('body');
      margin: '5px', padding: '3px 6px', cursor: 'pointer'
 
     }).click(function(){
   $(window).scroll(function(){
      toc.slideToggle();
     var winScroll = $(window).scrollTop();
    });
    var height = $(document).height() - $(window).height();
  }
    var scrolled = (winScroll / height) * 100;
    progressBar.css('width', scrolled + '%');
  });
});
 
// 読了時間表示(メインページは除外)
$(function () {
  // メインページなら何もしない
  if (mw.config.get('wgPageName') === 'メインページ') return;
 
  var text = $('#mw-content-text').text();
  var minutes = Math.ceil(text.length / 500); // 500文字/分で計算
  $('<div id="read-time">⏳ 読了目安: ' + minutes + '分</div>').css({
    padding: '5px',
    background: '#e2f0ff',
    borderRadius: '5px',
     display: 'inline-block',
    marginBottom: '10px'
  }).prependTo('#mw-content-text');
});
});


// 編集リンクをアイコン化
//$(function() {
//  $('.mw-editsection a').html('<span style="font-size:14px">📝</span>');
//});


// Lightbox2読み込み
 
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/js/lightbox.min.js');
  // スムーズスクロール
$('head').append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/css/lightbox.min.css" />');
$(function(){
  $('a[href^="#"]').click(function(e){
    e.preventDefault();
    var target = $(this.hash);
    if(target.length){
      $('html, body').animate({scrollTop:target.offset().top},600);
    }
  });
});
 
  // ツールチップ機能
$(function(){
  $('[data-tooltip]').hover(function(){
    var tooltip = $('<div class="tooltip"></div>').text($(this).attr('data-tooltip')).css({
      position: 'absolute',
      background: '#444',
      color: '#fff',
      padding: '4px 8px',
      borderRadius: '5px',
      zIndex: 1000,
      whiteSpace: 'nowrap'
    }).appendTo('body').hide().fadeIn(200);


// 画像にdata-lightbox属性を自動追加
    $(this).mousemove(function(e){
$(function() {
      tooltip.css({top:e.pageY+10, left:e.pageX+10});
   $('a.image').each(function() {
    });
    $(this).attr('data-lightbox', 'image-gallery');
   }, function(){
    $('.tooltip').fadeOut(200,function(){ $(this).remove(); });
   });
   });
});
});


// 折りたたみ可能セクション
 
// ユーザー名歓迎表示(メインページ限定)
mw.hook('wikipage.content').add(function () {
  if (
    mw.config.get('wgUserName') &&
    mw.config.get('wgPageName') === 'メインページ'
  ) {
    const msg = 'おかえりなさい、' + mw.config.get('wgUserName') + ' さん!';
    $('<div>')
      .text(msg)
      .css({
        textAlign: 'center',
        fontSize: '20px',
        background: '#43C2E8',
        color: '#fff',
        padding: '8px',
        borderRadius: '8px',
        marginBottom: '10px'
      })
      .prependTo('#mw-content-text');
  }
});
 
 
 
  // 折りたたみ可能セクション
$(function() {
$(function() {
   $('.mw-headline').click(function() {
   $('.mw-headline').click(function() {
76行目: 182行目:
});
});


// リアルタイム時計
 
//$(function() {
// 目次トグル機能追加
//    var clock = $('<div id="wiki-clock"></div>').css({
//        position: 'fixed',
//        top: '10px',
//        right: '20px',
//        background: '#333',
//        color: '#fff',
//        padding: '3px 8px',
//        borderRadius: '4px',
//        zIndex: 1000
//    }).appendTo('body');
 
//    function updateClock(){
//        clock.text(new Date().toLocaleString());
//    }
//    setInterval(updateClock, 1000);
//    updateClock();
//});
 
// 最近の更新をポップアップ表示
$(function(){
$(function(){
    var recentBtn = $('<button id="recent-popup">最近の更新</button>').css({
  var toc = $('#toc');
        position: 'fixed', bottom: '50px', right: '20px',
  if(toc.length){
        padding: '5px 10px', background: '#444', color: '#fff', borderRadius: '4px', cursor: 'pointer', zIndex: 1000
    toc.before('<button id="toggle-toc">目次を開閉</button>');
     }).appendTo('body');
    $('#toggle-toc').css({
 
      margin: '5px', padding: '3px 6px', cursor: 'pointer'
    recentBtn.click(function(){
     }).click(function(){
        window.open(mw.util.getUrl('特別:最近の更新'), 'recentChanges', 'width=800,height=600');
      toc.slideToggle();
     });
     });
  }
});
});


// ユーザー名歓迎表示
 
$(function(){
// 外部リンクを新規タブで開く
    if(mw.config.get('wgUserName')){
$(function() {
        $('#mw-head').prepend(
  $('a.external').attr('target', '_blank');
            '<div style="padding:5px;background:#1a73e8;color:#fff;text-align:center;">ようこそ、' +
            mw.config.get('wgUserName') + 'さん!</div>'
        );
    }
});
});


// ユーステラ風✨星キラキラカーソル(頻度調整+水色強化版)
// ユーステラ風✨星キラキラカーソル(頻度調整+水色強化版)
147行目: 232行目:
         $(this).remove();
         $(this).remove();
     });
     });
});
});
});


// ツールチップ機能
// h2-h4の埋め込みリンクを剥がす
$(function(){
$(function () {
   $('[data-tooltip]').hover(function(){
  // 対象:h3〜h4の .mw-headline 内にあるリンクだけ
     var tooltip = $('<div class="tooltip"></div>').text($(this).attr('data-tooltip')).css({
   $('h3 .mw-headline > a, h4 .mw-headline > a').each(function () {
      position: 'absolute',
     const text = $(this).text();          // リンクの中身を取り出して
      background: '#444',
    $(this).replaceWith(text);          // リンクをプレーンテキストに置き換える
      color: '#fff',
  });
       padding: '4px 8px',
});
       borderRadius: '5px',
 
       zIndex: 1000,
//転送先Popups
       whiteSpace: 'nowrap'
mw.loader.using(['jquery', 'mediawiki.api']).then(function () {
     }).appendTo('body').hide().fadeIn(200);
  $(document).on('mouseover', 'a', function () {
    const $link = $(this);
    const title = $link.attr('title');
    if (!title || $link.hasClass('mw-redirect')) return; // 転送元だけ対応
 
    const api = new mw.Api();
    api.get({
       action: 'query',
       titles: title,
       redirects: 1,
       format: 'json'
     }).then(function (data) {
      const pages = data.query.pages;
      const page = Object.values(pages)[0];
 
      if (page.redirects && page.redirects.length > 0) {
        const target = page.redirects[0].to;


    $(this).mousemove(function(e){
        // Popupsの data-title を書き換えて、強制的に転送先にする
      tooltip.css({top:e.pageY+10, left:e.pageX+10});
        $link.attr('data-title', target);
        $link.attr('title', target);
      }
     });
     });
  }, function(){
    $('.tooltip').fadeOut(200,function(){ $(this).remove(); });
   });
   });
});
});


// スムーズスクロール
//未ログインユーザーは強制ライト
$(function(){
mw.loader.using('mediawiki.user').then(function () {
   $('a[href^="#"]').click(function(e){
   if (!mw.config.get('wgUserName')) {
    e.preventDefault();
    document.documentElement.setAttribute('data-theme', 'light');
     var target = $(this.hash);
  }
     if(target.length){
});
       $('html, body').animate({scrollTop:target.offset().top},600);
 
//関連記事を全記事のフッターに自動表示する機能 停止中
 
//FANBOX支援ボタン
mw.loader.using(['mediawiki.util']).then(function () {
  function insertFanboxButton() {
     var footer = document.querySelector('.citizen-footer');
     if (!footer) {
       console.warn('footer未検出、再試行します...');
      setTimeout(insertFanboxButton, 300);
      return;
     }
     }
  });
});


// 最終更新日の表示
    // 二重挿入防止
//$(function(){
    if (document.querySelector('.fanbox-button')) return;
//  var lastEdit = $('#footer-info-lastmod').text();
//  $('<div class="last-modified"></div>').text('🕑 ' + lastEdit).css({
//    position:'absolute', top:'5px', right:'5px', padding:'5px 10px',
//    background:'#333', color:'#fff', borderRadius:'5px', zIndex:1000
//  }).prependTo('#mw-content-text');
//});


    var btn = document.createElement('a');
    btn.href = 'https://u-stella.fanbox.cc/';
    btn.target = '_blank';
    btn.rel = 'noopener';
    btn.textContent = ' 💎 100円から応援できて、特典いっぱい! いつも支えてくれて本当にありがとう。ユーステラは、FANBOXで全部が動いてるよ。';
    btn.className = 'fanbox-button';


// 読了時間表示
    // 古い方法でスタイルを直書き
$(function(){
    btn.style.display = 'inline-block';
  var text = $('#mw-content-text').text();
    btn.style.backgroundColor = '#43C2E8';
  var minutes = Math.ceil(text.length / 500); //500文字/分で計算
    btn.style.color = 'white';
  $('<div id="read-time">⏳ 読了目安: ' + minutes + '分</div>').css({
     btn.style.padding = '0.6em 1.4em';
     padding: '5px', background: '#e2f0ff', borderRadius: '5px',
    btn.style.borderRadius = '999px';
     display: 'inline-block', marginBottom: '10px'
     btn.style.textDecoration = 'none';
  }).prependTo('#mw-content-text');
    btn.style.fontWeight = 'bold';
});
    btn.style.margin = '1em auto';


// スクロール進捗バー
    footer.appendChild(btn);
$(function(){
    console.log('✅ FANBOXボタン追加済み');
  var progressBar = $('<div id="progress-bar"></div>').css({
   }
    position:'fixed', top:'0', left:'0', height:'4px',
    background:'#6cf', width:'0%', zIndex:1000
   }).appendTo('body');


   $(window).scroll(function(){
   mw.hook('wikipage.content').add(function () {
     var winScroll = $(window).scrollTop();
     insertFanboxButton();
    var height = $(document).height() - $(window).height();
    var scrolled = (winScroll / height) * 100;
    progressBar.css('width', scrolled + '%');
   });
   });
});
});
});

2025年4月15日 (火) 13:31時点における最新版

mw.hook('wikipage.content').add(function ($content) {
  // すべての中身をここに入れて動かす

$(function () {
  // Citizenスキンの「案内」セクションを検出して削除
  $(".mw-portlet h3").each(function () {
    const heading = $(this);
    if (heading.text().trim() === "案内") {
      heading.closest(".mw-portlet").remove();
    }
  });
});
$(function () {
  $(".sidebar-group").each(function () {
    const group = $(this);
    const heading = group.find("h2").first().text().trim();
    if (heading === "案内") {
      group.remove();
    }
  });
});
$(function () {
  $(".citizen-menu__heading").each(function () {
    if ($(this).text().trim() === "案内") {
      $(this).next(".citizen-menu__content").remove(); // 中身消す
      $(this).remove(); // 見出しも消す
    }
  });
});


//メインページだけ読了目安を無効化
$(function () {
  if ( mw.config.get('ReadingTimeDisabled') ) {
    $('.read-time-box, .citizen-page-info-readtime').remove();
  }
});


//折り畳み機能
$(function () {
  $(".mw-collapsible").each(function () {
    const $block = $(this);
    const $toggle = $('<a href="#" style="float:right;">[開く]</a>');
    $toggle.on("click", function (e) {
      e.preventDefault();
      $block.toggleClass("collapsed");
      $block.find("ul").slideToggle();
      $toggle.text($block.hasClass("collapsed") ? "[開く]" : "[閉じる]");
    });
    $block.prepend($toggle);
    if ($block.hasClass("mw-collapsed")) {
      $block.addClass("collapsed");
      $block.find("ul").hide();
    }
  });
});

$(function () {
  $(".u-stella-box").each(function () {
    const $block = $(this);
    const $toggle = $('<a href="#" style="float:right; font-size:90%;">[+]</a>');
    $toggle.on("click", function (e) {
      e.preventDefault();
      $block.toggleClass("collapsed");
      $block.find("ul").slideToggle();
      $toggle.text($block.hasClass("collapsed") ? "[+]" : "[-]");
    });
    $block.prepend($toggle);
    if ($block.hasClass("collapsed")) {
      $block.find("ul").hide();
    }
  });
});



  // 全角スペースを黒四角に
mw.hook('wikipage.content').add(function ($content) {
  $content.find('.mw-parser-output').each(function () {
    const $this = $(this);
    const html = $this.html().replace(/ /g, '■');
    $this.html(html);
  });
});

  // スクロール進捗バー
$(function(){
  var progressBar = $('<div id="progress-bar"></div>').css({
    position:'fixed', top:'0', left:'0', height:'4px',
    background:'#6cf', width:'0%', zIndex:1000
  }).appendTo('body');

  $(window).scroll(function(){
    var winScroll = $(window).scrollTop();
    var height = $(document).height() - $(window).height();
    var scrolled = (winScroll / height) * 100;
    progressBar.css('width', scrolled + '%');
  });
});
  
// 読了時間表示(メインページは除外)
$(function () {
  // メインページなら何もしない
  if (mw.config.get('wgPageName') === 'メインページ') return;

  var text = $('#mw-content-text').text();
  var minutes = Math.ceil(text.length / 500); // 500文字/分で計算
  $('<div id="read-time">⏳ 読了目安: ' + minutes + '分</div>').css({
    padding: '5px',
    background: '#e2f0ff',
    borderRadius: '5px',
    display: 'inline-block',
    marginBottom: '10px'
  }).prependTo('#mw-content-text');
});


  
  // スムーズスクロール
$(function(){
  $('a[href^="#"]').click(function(e){
    e.preventDefault();
    var target = $(this.hash);
    if(target.length){
      $('html, body').animate({scrollTop:target.offset().top},600);
    }
  });
});
  
  // ツールチップ機能
$(function(){
  $('[data-tooltip]').hover(function(){
    var tooltip = $('<div class="tooltip"></div>').text($(this).attr('data-tooltip')).css({
      position: 'absolute',
      background: '#444',
      color: '#fff',
      padding: '4px 8px',
      borderRadius: '5px',
      zIndex: 1000,
      whiteSpace: 'nowrap'
    }).appendTo('body').hide().fadeIn(200);

    $(this).mousemove(function(e){
      tooltip.css({top:e.pageY+10, left:e.pageX+10});
    });
  }, function(){
    $('.tooltip').fadeOut(200,function(){ $(this).remove(); });
  });
});

  
// ユーザー名歓迎表示(メインページ限定)
mw.hook('wikipage.content').add(function () {
  if (
    mw.config.get('wgUserName') &&
    mw.config.get('wgPageName') === 'メインページ'
  ) {
    const msg = 'おかえりなさい、' + mw.config.get('wgUserName') + ' さん!';
    $('<div>')
      .text(msg)
      .css({
        textAlign: 'center',
        fontSize: '20px',
        background: '#43C2E8',
        color: '#fff',
        padding: '8px',
        borderRadius: '8px',
        marginBottom: '10px'
      })
      .prependTo('#mw-content-text');
  }
});



  // 折りたたみ可能セクション
$(function() {
  $('.mw-headline').click(function() {
    $(this).parent().nextUntil('h2, h3, h4, h5, h6').slideToggle();
  }).css('cursor', 'pointer');
});

  
// 目次トグル機能追加
$(function(){
  var toc = $('#toc');
  if(toc.length){
    toc.before('<button id="toggle-toc">目次を開閉</button>');
    $('#toggle-toc').css({
      margin: '5px', padding: '3px 6px', cursor: 'pointer'
    }).click(function(){
      toc.slideToggle();
    });
  }
});


// 外部リンクを新規タブで開く
$(function() {
  $('a.external').attr('target', '_blank');
});


// ユーステラ風✨星キラキラカーソル(頻度調整+水色強化版)
var lastStarTime = 0;
$(document).mousemove(function(e) {
    var now = Date.now();
    if (now - lastStarTime < 100) return; // 出現頻度を調整(100を大きくすればさらに少なくなる)
    lastStarTime = now;

    var colors = ['#6ff', '#9cf', '#cff', '#8df', '#7af']; // より水色っぽく調整
    var star = $('<div>').text('✦').css({
        position: 'absolute',
        top: e.pageY - 10,
        left: e.pageX - 10,
        color: colors[Math.floor(Math.random() * colors.length)],
        fontSize: '14px',
        pointerEvents: 'none',
        opacity: 1,
        zIndex: 9999,
        userSelect: 'none',
        textShadow: '0 0 6px #8df, 0 0 12px #6ff'
    }).appendTo('body');

    star.animate({
        top: e.pageY - (Math.random() * 40 - 20),
        left: e.pageX - (Math.random() * 40 - 20),
        opacity: 0,
        fontSize: '4px'
    }, 1000, function() {
        $(this).remove();
    });
});
});

// h2-h4の埋め込みリンクを剥がす
$(function () {
  // 対象:h3〜h4の .mw-headline 内にあるリンクだけ
  $('h3 .mw-headline > a, h4 .mw-headline > a').each(function () {
    const text = $(this).text();          // リンクの中身を取り出して
    $(this).replaceWith(text);           // リンクをプレーンテキストに置き換える
  });
});

//転送先Popups
mw.loader.using(['jquery', 'mediawiki.api']).then(function () {
  $(document).on('mouseover', 'a', function () {
    const $link = $(this);
    const title = $link.attr('title');
    if (!title || $link.hasClass('mw-redirect')) return; // 転送元だけ対応

    const api = new mw.Api();
    api.get({
      action: 'query',
      titles: title,
      redirects: 1,
      format: 'json'
    }).then(function (data) {
      const pages = data.query.pages;
      const page = Object.values(pages)[0];

      if (page.redirects && page.redirects.length > 0) {
        const target = page.redirects[0].to;

        // Popupsの data-title を書き換えて、強制的に転送先にする
        $link.attr('data-title', target);
        $link.attr('title', target);
      }
    });
  });
});

//未ログインユーザーは強制ライト
mw.loader.using('mediawiki.user').then(function () {
  if (!mw.config.get('wgUserName')) {
    document.documentElement.setAttribute('data-theme', 'light');
  }
});

//関連記事を全記事のフッターに自動表示する機能 停止中

//FANBOX支援ボタン
mw.loader.using(['mediawiki.util']).then(function () {
  function insertFanboxButton() {
    var footer = document.querySelector('.citizen-footer');
    if (!footer) {
      console.warn('footer未検出、再試行します...');
      setTimeout(insertFanboxButton, 300);
      return;
    }

    // 二重挿入防止
    if (document.querySelector('.fanbox-button')) return;

    var btn = document.createElement('a');
    btn.href = 'https://u-stella.fanbox.cc/';
    btn.target = '_blank';
    btn.rel = 'noopener';
    btn.textContent = ' 💎 100円から応援できて、特典いっぱい! いつも支えてくれて本当にありがとう。ユーステラは、FANBOXで全部が動いてるよ。';
    btn.className = 'fanbox-button';

    // 古い方法でスタイルを直書き
    btn.style.display = 'inline-block';
    btn.style.backgroundColor = '#43C2E8';
    btn.style.color = 'white';
    btn.style.padding = '0.6em 1.4em';
    btn.style.borderRadius = '999px';
    btn.style.textDecoration = 'none';
    btn.style.fontWeight = 'bold';
    btn.style.margin = '1em auto';

    footer.appendChild(btn);
    console.log('✅ FANBOXボタン追加済み');
  }

  mw.hook('wikipage.content').add(function () {
    insertFanboxButton();
  });
});