사용자:낙엽1124/common.js

최근 편집: 2018년 9월 8일 (토) 04:37

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
  • 오페라: Ctrl-F5를 입력.
//존재/가상에 있는 링크 기울이기
//mw.loader.load("/index.php?title=사용자:렌즈/categoryCheck.js&action=raw&ctype=text/javascript");

//메뉴에 Purge 링크 추가
$(document).ready( function () {
	try {
		var menu = document.getElementById("p-actions").
				getElementsByTagName('ul')[0],
			purge = document.createElement('li'),
			a = document.createElement('a');
		menu.append(purge);
		purge.append(a);
		a.innerHTML='새로고침';
		a.href = "#";
		a.onclick = function() {
			$.ajax(
				{ 
					url: window.location.protocol
						+'//'
						+window.location.hostname
						+"/api.php?action=purge&forcelinkupdate=1&titles="
						+mw.config.get('wgPageName') 
				});
//			location.reload();
			return false; 
		};
	} catch (err) {}
});

//공유 메뉴에 판 링크 만들기 추가
$(document).ready( function () {
	try {
		var menu = document.getElementById("p-page-tb").
				getElementsByTagName('ul')[0],
			ref = document.createElement('li'),
			a = document.createElement('a');
		menu.append(ref);
		ref.append(a);
		a.innerHTML='판 링크 만들기';
		a.href = "#";
		a.accesskey = "r";
		a.onclick = function() {
				document.getElementById('searchInput').value = 
					'[['+mw.config.get('wgPageName').replace(/_/g, ' ')
					+']]([[특:넘겨주기/revision/'+mw.config.get('wgRevisionId')+'|'
					+mw.config.get('wgRevisionId')+'판]])';
			return false; 
		};
	} catch (err) {}
});

//위키편집기에 분류 입력 툴 넣기
var pre = "{"+"{분류|";
if(mw.config.get('wgNamespaceNumber')===14)
	pre = "{"+"{분류 문서}}\n\n"+pre;
var addCategoryToolToWikiEditor = function () {
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'insert',
		'tools': {
			'comment': {
				label: '분류',
				type: 'button',
				//icon: {},
				offset: [2, -1798],
				action: {
					type: 'encapsulate',
					options: {
						pre: pre,
						peri: "/",
						post: "}}"
					}
				}
			}
		}
	} );
};

//위키편집기에 스포일러 입력 툴 넣기

var addSpoilerToolToWikiEditor = function () {
	var pre = '', post = '';
	if(mw.config.get('wgNamespaceNumber')===10) {
		pre = "<noinclude>{"+"{틀 설명문서}}</noinclude>";
	} else {
		pre = "<noinclude>{"+"{스포일러}}</noinclude>\n<includeonly>";
		post = "</includeonly>";
	}
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'insert',
		'tools': {
			'comment': {
				label: '스포일러',
				type: 'button',
				//icon: {},
				offset: [8, -1798],
				action: {
					type: 'encapsulate',
					options: {
						pre: pre,
						peri: "",
						post: post
					}
				}
			}
		}
	} );
};

//위키편집기에 동음이의어 문서 입력 툴 넣기
var addHomonymToolToWikiEditor = function () {
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'main',
		'group': 'insert',
		'tools': {
			'comment': {
				label: '동음이의어',
				type: 'button',
				//icon: {},
				offset: [8, -1798],
				action: {
					type: 'encapsulate',
					options: {
						pre: "{"+"{동음이의어 문서}}\n\n;[[",
						peri: "",
						post: "]]\n:\n;[[]]\n:\n\n{"+"{분류|성격/동음이의어}}"
					}
				}
			}
		}
	} );
};

$(document).ready( function () {
	if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
		mw.loader.using( 'user.options' ).then( function () {
			if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
				$.when(
					mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
				).then( addCategoryToolToWikiEditor )
				.then( addSpoilerToolToWikiEditor )
				.then( addHomonymToolToWikiEditor );
			}
		} );
	}
});

//시각편집기

mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).then( function() {
	mw.libs.ve.addPlugin( function() {
		ve.ui.triggerRegistry.register(
			'transclusion', 
			{
				pc: new ve.ui.Trigger( 'alt+shift+h' )
			}
		);
		ve.ui.triggerRegistry.register(
			'reference', 
			{
				pc: new ve.ui.Trigger( 'ctrl+shift+k' )
			}
		);
	} );
} );