|
|
1行目: |
1行目: |
| /* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ | | /* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */ |
|
| |
| // トップに戻るボタンを追加する
| |
| $(function() {
| |
| // ボタンを作成
| |
| var toTopButton = $('<a href="#" id="toTop">↑ トップへ戻る</a>');
| |
|
| |
| // CSSでボタンをデザイン
| |
| toTopButton.css({
| |
| position: 'fixed',
| |
| bottom: '20px',
| |
| right: '20px',
| |
| background: '#555',
| |
| color: '#fff',
| |
| padding: '5px 10px',
| |
| borderRadius: '4px',
| |
| textDecoration: 'none',
| |
| display: 'none', // 初期は非表示
| |
| zIndex: '1000'
| |
| });
| |
|
| |
| // ページに追加
| |
| $('body').append(toTopButton);
| |
|
| |
| // スクロールしたら表示
| |
| $(window).scroll(function() {
| |
| if ($(this).scrollTop() > 200) {
| |
| toTopButton.fadeIn();
| |
| } else {
| |
| toTopButton.fadeOut();
| |
| }
| |
| });
| |
|
| |
| // ボタンクリックでトップに戻る
| |
| toTopButton.click(function() {
| |
| $('html, body').animate({scrollTop:0}, 500);
| |
| return false;
| |
| });
| |
| });
| |
|
| |
| // コピーコードボタン追加
| |
| $(function() {
| |
| $('pre').each(function(){
| |
| var copyBtn = $('<button class="copy-btn">コピー</button>');
| |
| $(this).before(copyBtn);
| |
| copyBtn.click(() => {
| |
| navigator.clipboard.writeText($(this).text()).then(() => {
| |
| copyBtn.text('コピー済');
| |
| setTimeout(() => copyBtn.text('コピー'), 2000);
| |
| });
| |
| });
| |
| });
| |
| });
| |
|
| |
| // 外部リンクを新規タブで開く
| |
| $(function() {
| |
| $('a.external').attr('target', '_blank');
| |
| });
| |
|
| |
| // 目次トグル機能追加
| |
| $(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() {
| |
| // $('.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" />');
| |
|
| |
| // 画像にdata-lightbox属性を自動追加
| |
| $(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();
| |
| }).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(){
| |
| $.getJSON(mw.util.wikiScript('api'), {
| |
| action: 'query',
| |
| prop: 'pageviews',
| |
| titles: mw.config.get('wgPageName'),
| |
| format: 'json'
| |
| }, function(data){
| |
| var views = Object.values(data.query.pages)[0].pageviews;
| |
| var 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');
| |
| });
| |
| });
| |
|
| |
| // 読了時間表示
| |
| $(function(){
| |
| 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(){
| |
| 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 + '%');
| |
| });
| |
| });
| |
|
| |
| /* ユーステラFANBOXボタンのスタイル */
| |
| $(document).ready(function () {
| |
| // すでに表示されていたらスキップ
| |
| if ($('#fanbox-button-wrapper').length > 0) return;
| |
| // ボタンとラッパー作成
| |
| const $wrapper = $('<div>', {
| |
| id: 'fanbox-button-wrapper',
| |
| css: {
| |
| textAlign: 'center',
| |
| marginTop: '1em',
| |
| marginBottom: '1em'
| |
| }
| |
| });
| |
| 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が起動したら実行
| |
| if (mw.config.get('wgAction') === 'edit' || mw.config.get('wgAction') === 'submit') {
| |
| const $uploadContainer = $('<div>', {
| |
| id: 'msupload-in-ve',
| |
| css: {
| |
| 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'), {
| |
| 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);
| |
|
| |
| $('.mw-parser-output').each(function () {
| |
| let html = $(this).html();
| |
|
| |
| titles.forEach(title => {
| |
| const safeTitle = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
| |
| const regex = new RegExp(`(?<!href=["'][^>]{0,500})(${safeTitle})(?![^<]*?>)`, 'g');
| |
| const link = `<a href="${mw.util.getUrl(title)}">$1</a>`;
| |
| html = html.replace(regex, link);
| |
| });
| |
|
| |
| $(this).html(html);
| |
| });
| |
| });
| |
| });
| |