"미디어위키:Common.js"의 두 版 사이의 差異

(새 문서: →‎이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다.: var customizeToolbar = function () { $( '#wpTextbox1' ).wikiEditor( 'addToToolbar',...)
 
編輯 要約 없음
 
(같은 使用者(사용자)中間(중간) () 12()는 보이지 않습니다)
1番째 줄: 1番째 줄:
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
var removeGuestRubyMenu = function() {
    var menu = document.querySelector('a.toggle-ruby');
    menu && menu.parentNode.removeChild(menu);
}
var applyGuestRubyMenu = function() {
    var menu = document.querySelector('a.toggle-ruby');
    if(!menu) return;
    var url = new URL(location.href);
    url.searchParams.set('useruby', 'toggle');
    menu.href = url.href;
}
var applyGuestRuby = function() {
    var localStorage = window.localStorage;
    var url = new URL(location.href);
    var urlParam = url.searchParams.get('useruby');
    var lsParam = localStorage && localStorage.getItem('useruby');
    var useruby = urlParam || lsParam || 'true';
    if(urlParam == 'toggle') {
        useruby = lsParam == 'false' ? 'true' : 'false';
        url.searchParams.set('useruby', useruby);
        location.href = url.href;
    }
    if(useruby == 'false') {
        document.body.classList.add('noruby');
    }
    localStorage && localStorage.setItem('useruby', useruby);
};
var applyDarkMode = function() {
    if(window.matchMedia && document.body) {
        var match = window.matchMedia('(prefers-color-scheme: dark)');
        if(match.matches) {
            document.body.classList.add('dark-mode');
        }
        match.addEventListener('change', function(event) {
            var darkMode = event.matches;
            document.body.classList.toggle('dark-mode', darkMode);
        });
    }
};
mw.loader.using(['mediawiki.util'], function() {
    var searchInput = document.querySelector('input#searchInput');
    if(searchInput) {
        searchInput.addEventListener('input', function() {
            $(this).trigger('keypress');
        });
    }
    applyDarkMode();
    window.addEventListener('load', applyDarkMode);
    var username = mw.config.values.wgUserName;
    if(!username) {
        applyGuestRuby();
        window.addEventListener('load', applyGuestRuby);
        applyGuestRubyMenu();
        window.addEventListener('load', applyGuestRubyMenu);
    } else {
        removeGuestRubyMenu();
        window.addEventListener('load', removeGuestRubyMenu);
    }
});


var customizeToolbar = function () {
var customizeToolbar = function () {

2023年12月22日(金)17時40分 基準 最新版

/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */

var removeGuestRubyMenu = function() {
    var menu = document.querySelector('a.toggle-ruby');
    menu && menu.parentNode.removeChild(menu);
}

var applyGuestRubyMenu = function() {
    var menu = document.querySelector('a.toggle-ruby');
    if(!menu) return;
    var url = new URL(location.href);
    url.searchParams.set('useruby', 'toggle');
    menu.href = url.href;
}

var applyGuestRuby = function() {
    var localStorage = window.localStorage;
    var url = new URL(location.href);
    var urlParam = url.searchParams.get('useruby');
    var lsParam = localStorage && localStorage.getItem('useruby');
    var useruby = urlParam || lsParam || 'true';
    if(urlParam == 'toggle') {
        useruby = lsParam == 'false' ? 'true' : 'false';
        url.searchParams.set('useruby', useruby);
        location.href = url.href;
    }
    if(useruby == 'false') {
        document.body.classList.add('noruby');
    }
    localStorage && localStorage.setItem('useruby', useruby);
};

var applyDarkMode = function() {
    if(window.matchMedia && document.body) {
        var match = window.matchMedia('(prefers-color-scheme: dark)');
        if(match.matches) {
            document.body.classList.add('dark-mode');
        }
        match.addEventListener('change', function(event) {
            var darkMode = event.matches;
            document.body.classList.toggle('dark-mode', darkMode);
        });
    }
};

mw.loader.using(['mediawiki.util'], function() {
    var searchInput = document.querySelector('input#searchInput');
    if(searchInput) {
        searchInput.addEventListener('input', function() {
            $(this).trigger('keypress');
        });
    }
    applyDarkMode();
    window.addEventListener('load', applyDarkMode);

    var username = mw.config.values.wgUserName;
    if(!username) {
        applyGuestRuby();
        window.addEventListener('load', applyGuestRuby);
        applyGuestRubyMenu();
        window.addEventListener('load', applyGuestRubyMenu);
    } else {
        removeGuestRubyMenu();
        window.addEventListener('load', removeGuestRubyMenu);
    }
});

var customizeToolbar = function () {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tools': {
            'cite': {
                label: '註釋',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/4/4f/Cite_icon.svg',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: "{{*|",
                        peri: "內容",
                        post: "}}"
                    }
                }
            }
        }
    } );
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}