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

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

MediaWikiインターフェイスページ
編集の要約なし
編集の要約なし
1行目: 1行目:
// トップに戻るボタンを追加する
/* ✅ Citizenスキン完全対応版 Common.js */
$(function() {
    // ボタンを作成
    var toTopButton = $('<a href="#" id="toTop">↑ トップへ戻る</a>');


    // CSSでボタンをデザイン
mw.hook('wikipage.content').add(function ($content) {
    toTopButton.css({
  console.log("✅ Citizen hook fired");
        position: 'fixed',
        bottom: '20px',
        right: '20px',
        background: '#555',
        color: '#fff',
        padding: '5px 10px',
        borderRadius: '4px',
        textDecoration: 'none',
        display: 'none', // 初期は非表示
        zIndex: '1000'
    });


    // ページに追加
  // トップに戻るボタン
    $('body').append(toTopButton);
  const toTopButton = $('<a href="#" id="toTop">↑ トップへ戻る</a>').css({
    position: 'fixed', bottom: '20px', right: '20px', background: '#555',
    color: '#fff', padding: '5px 10px', borderRadius: '4px', textDecoration: 'none', display: 'none', zIndex: 1000
  }).appendTo('body');


    // スクロールしたら表示
  $(window).on('scroll', function () {
    $(window).scroll(function() {
    toTopButton.toggle($(this).scrollTop() > 200);
        if ($(this).scrollTop() > 200) {
  });
            toTopButton.fadeIn();
 
        } else {
  toTopButton.on('click', function () {
            toTopButton.fadeOut();
    $('html, body').animate({ scrollTop: 0 }, 500);
        }
    return false;
    });
  });


     // ボタンクリックでトップに戻る
  // コピーコードボタン
     toTopButton.click(function() {
  $content.find('pre').each(function () {
         $('html, body').animate({scrollTop:0}, 500);
     const copyBtn = $('<button class="copy-btn">コピー</button>');
        return false;
    $(this).before(copyBtn);
     copyBtn.on('click', () => {
      navigator.clipboard.writeText($(this).text()).then(() => {
         copyBtn.text('コピー済');
        setTimeout(() => copyBtn.text('コピー'), 2000);
      });
     });
     });
});
  });
 


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


// 外部リンクを新規タブで開く
   // 目次トグル
$(function() {
   const toc = $content.find('#toc');
   $('a.external').attr('target', '_blank');
   if (toc.length) {
});
 
// 目次トグル機能追加
$(function(){
   var toc = $('#toc');
   if(toc.length){
     toc.before('<button id="toggle-toc">目次を開閉</button>');
     toc.before('<button id="toggle-toc">目次を開閉</button>');
     $('#toggle-toc').css({
     $('#toggle-toc').css({ margin: '5px', padding: '3px 6px', cursor: 'pointer' })
      margin: '5px', padding: '3px 6px', cursor: 'pointer'
      .on('click', function () {
    }).click(function(){
        toc.slideToggle();
      toc.slideToggle();
      });
    });
   }
   }
});
// 編集リンクをアイコン化
//$(function() {
//  $('.mw-editsection a').html('<span style="font-size:14px">📝</span>');
//});


// Lightbox2読み込み
  // 画像に Lightbox 属性を追加
mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/js/lightbox.min.js');
  $content.find('a.image').attr('data-lightbox', 'image-gallery');
$('head').append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.4/css/lightbox.min.css" />');


// 画像にdata-lightbox属性を自動追加
  // セクション折りたたみ
$(function() {
   $content.find('.mw-headline').css('cursor', 'pointer').on('click', function () {
   $('a.image').each(function() {
    $(this).attr('data-lightbox', 'image-gallery');
  });
});
 
// 折りたたみ可能セクション
$(function() {
  $('.mw-headline').click(function() {
     $(this).parent().nextUntil('h2, h3, h4, h5, h6').slideToggle();
     $(this).parent().nextUntil('h2, h3, h4, h5, h6').slideToggle();
  }).css('cursor', 'pointer');
});
// リアルタイム時計
//$(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(){
    var recentBtn = $('<button id="recent-popup">最近の更新</button>').css({
        position: 'fixed', bottom: '50px', right: '20px',
        padding: '5px 10px', background: '#444', color: '#fff', borderRadius: '4px', cursor: 'pointer', zIndex: 1000
    }).appendTo('body');
    recentBtn.click(function(){
        window.open(mw.util.getUrl('特別:最近の更新'), 'recentChanges', 'width=800,height=600');
    });
});
// ユーザー名歓迎表示
$(function(){
    if(mw.config.get('wgUserName')){
        $('#mw-head').prepend(
            '<div style="padding:5px;background:#1a73e8;color:#fff;text-align:center;">ようこそ、' +
            mw.config.get('wgUserName') + 'さん!</div>'
        );
    }
});
// ユーステラ風✨星キラキラカーソル(頻度調整+水色強化版)
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();
    });
});
// ツールチップ機能
$(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(); });
   });
   });
});
// スムーズスクロール
$(function(){
  $('a[href^="#"]').click(function(e){
    e.preventDefault();
    var target = $(this.hash);
    if(target.length){
      $('html, body').animate({scrollTop:target.offset().top},600);
    }
  });
});
// 最終更新日の表示
//$(function(){
//  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');
//});


// 読了時間表示
  // 最近の更新ポップアップボタン
$(function(){
   const recentBtn = $('<button id="recent-popup">最近の更新</button>').css({
   var text = $('#mw-content-text').text();
     position: 'fixed', bottom: '50px', right: '20px',
  var minutes = Math.ceil(text.length / 500); //500文字/分で計算
     padding: '5px 10px', background: '#444', color: '#fff', borderRadius: '4px', cursor: 'pointer', zIndex: 1000
  $('<div id="read-time">⏳ 読了目安: ' + minutes + '分</div>').css({
     padding: '5px', background: '#e2f0ff', borderRadius: '5px',
     display: 'inline-block', marginBottom: '10px'
  }).prependTo('#mw-content-text');
});
 
// スクロール進捗バー
$(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');
   }).appendTo('body');


   $(window).scroll(function(){
   recentBtn.on('click', function () {
     var winScroll = $(window).scrollTop();
     window.open(mw.util.getUrl('特別:最近の更新'), 'recentChanges', 'width=800,height=600');
    var height = $(document).height() - $(window).height();
    var scrolled = (winScroll / height) * 100;
    progressBar.css('width', scrolled + '%');
   });
   });
});


/* ユーステラFANBOXボタンのスタイル */
  // 閲覧数表示
$(document).ready(function () {
  $.getJSON(mw.util.wikiScript('api'), {
  // すでに表示されていたらスキップ
    action: 'query', prop: 'pageviews', titles: mw.config.get('wgPageName'), format: 'json'
  if ($('#fanbox-button-wrapper').length > 0) return;
  }, function (data) {
  // ボタンとラッパー作成
    const views = Object.values(data.query.pages)[0].pageviews;
  const $wrapper = $('<div>', {
    const total = Object.values(views).reduce((a, b) => a + (b || 0), 0);
    id: 'fanbox-button-wrapper',
    $('<div id="view-count">👀 閲覧数: ' + total + '</div>').css({
    css: {
      position: 'fixed', bottom: '150px', right: '20px',
       textAlign: 'center',
       padding: '4px 8px', background: '#333', color: '#fff',
      marginTop: '1em',
       borderRadius: '5px', zIndex: 1000
       marginBottom: '1em'
     }).appendTo('body');
     }
   });
   });
  const $button = $('<a>', {
    href: 'https://u-stella.fanbox.cc/',
    class: 'fanbox-button',
    text: '💖 ユーステラFANBOX',
    target: '_blank'
  });
  $wrapper.append($button);
  // コンテンツの直前(ページタイトルのすぐ下)に追加
  $('.mw-parser-output').first().before($wrapper);
});


mw.loader.using(['ext.visualEditor.desktopArticleTarget.init'], function () {
   // 読了時間表示
   // VisualEditorが起動したら実行
   const text = $content.text();
   if (mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit') {
  const minutes = Math.ceil(text.length / 500);
    const $uploadContainer = $('<div>', {
  $('<div id="read-time">⏳ 読了目安: ' + minutes + '</div>').css({
      id: 'msupload-in-ve',
    padding: '5px', background: '#e2f0ff', borderRadius: '5px', display: 'inline-block', marginBottom: '10px'
      css: {
  }).prependTo($content);
        marginTop: '1em',
        padding: '1em',
        border: '1px dashed #aaa',
        background: '#f9f9f9'
      }
    }).text('📁 MsUploadからファイルを挿入:');


    // MsUploadのフォームを読み込む(存在する場合)
   // 自動リンク化
    $.get('/index.php?title=Special:MsUpload&action=render', function (data) {
      $uploadContainer.append(data);
    });
 
    // VisualEditorのUIの下に追加
    $('.ve-init-mw-desktopArticleTarget .ve-ui-surface').after($uploadContainer);
  }
});
 
$(function () {
  // 記事本文だけ変換
  $('.mw-parser-output').each(function () {
    let html = $(this).html();
    html = html.replace(/ /g, '■'); // 全角スペースを黒四角に
    $(this).html(html);
   });
});
 
//完全自動リンク化スクリプト(最新版)
$(document).ready(function () {
   $.getJSON(mw.util.wikiScript('api'), {
   $.getJSON(mw.util.wikiScript('api'), {
     action: 'query',
     action: 'query', list: 'allpages', aplimit: 'max', apnamespace: 0, format: 'json'
    list: 'allpages',
    aplimit: 'max',
    apnamespace: 0,
    format: 'json'
   }, function (data) {
   }, function (data) {
     const pages = data.query.allpages;
     const pages = data.query.allpages;
     const titles = pages.map(p => p.title).filter(title => title.length >= 3);
     const titles = pages.map(p => p.title).filter(title => title.length >= 3);
 
     let html = $content.html();
     $('.mw-parser-output').each(function () {
    titles.forEach(title => {
      let html = $(this).html();
      const safeTitle = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
 
      const regex = new RegExp('([^>])(' + safeTitle + ')([^<])', 'g');
      titles.forEach(title => {
      const link = '$1<a href="' + mw.util.getUrl(title) + '">$2</a>$3';
        const safeTitle = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
      html = html.replace(regex, link);
        const regex = new RegExp('([^>])(' + safeTitle + ')([^<])', 'g');
const link = '$1<a href=\"' + mw.util.getUrl(title) + '\">$2</a>$3';
html = html.replace(regex, link);
      });
 
      $(this).html(html);
     });
     });
    $content.html(html);
   });
   });
});
});
// Lightbox 読み込み(外部)
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" />');

2025年3月28日 (金) 01:46時点における版

/* ✅ Citizenスキン完全対応版 Common.js */

mw.hook('wikipage.content').add(function ($content) {
  console.log("✅ Citizen hook fired");

  // トップに戻るボタン
  const toTopButton = $('<a href="#" id="toTop">↑ トップへ戻る</a>').css({
    position: 'fixed', bottom: '20px', right: '20px', background: '#555',
    color: '#fff', padding: '5px 10px', borderRadius: '4px', textDecoration: 'none', display: 'none', zIndex: 1000
  }).appendTo('body');

  $(window).on('scroll', function () {
    toTopButton.toggle($(this).scrollTop() > 200);
  });

  toTopButton.on('click', function () {
    $('html, body').animate({ scrollTop: 0 }, 500);
    return false;
  });

  // コピーコードボタン
  $content.find('pre').each(function () {
    const copyBtn = $('<button class="copy-btn">コピー</button>');
    $(this).before(copyBtn);
    copyBtn.on('click', () => {
      navigator.clipboard.writeText($(this).text()).then(() => {
        copyBtn.text('コピー済');
        setTimeout(() => copyBtn.text('コピー'), 2000);
      });
    });
  });

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

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

  // 画像に Lightbox 属性を追加
  $content.find('a.image').attr('data-lightbox', 'image-gallery');

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

  // 最近の更新ポップアップボタン
  const recentBtn = $('<button id="recent-popup">最近の更新</button>').css({
    position: 'fixed', bottom: '50px', right: '20px',
    padding: '5px 10px', background: '#444', color: '#fff', borderRadius: '4px', cursor: 'pointer', zIndex: 1000
  }).appendTo('body');

  recentBtn.on('click', function () {
    window.open(mw.util.getUrl('特別:最近の更新'), 'recentChanges', 'width=800,height=600');
  });

  // 閲覧数表示
  $.getJSON(mw.util.wikiScript('api'), {
    action: 'query', prop: 'pageviews', titles: mw.config.get('wgPageName'), format: 'json'
  }, function (data) {
    const views = Object.values(data.query.pages)[0].pageviews;
    const total = Object.values(views).reduce((a, b) => a + (b || 0), 0);
    $('<div id="view-count">👀 閲覧数: ' + total + '</div>').css({
      position: 'fixed', bottom: '150px', right: '20px',
      padding: '4px 8px', background: '#333', color: '#fff',
      borderRadius: '5px', zIndex: 1000
    }).appendTo('body');
  });

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

  // 自動リンク化
  $.getJSON(mw.util.wikiScript('api'), {
    action: 'query', list: 'allpages', aplimit: 'max', apnamespace: 0, format: 'json'
  }, function (data) {
    const pages = data.query.allpages;
    const titles = pages.map(p => p.title).filter(title => title.length >= 3);
    let html = $content.html();
    titles.forEach(title => {
      const safeTitle = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
      const regex = new RegExp('([^>])(' + safeTitle + ')([^<])', 'g');
      const link = '$1<a href="' + mw.util.getUrl(title) + '">$2</a>$3';
      html = html.replace(regex, link);
    });
    $content.html(html);
  });
});

// Lightbox 読み込み(外部)
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" />');