사용자:낙엽1124/common.js

최근 편집: 2017년 11월 29일 (수) 17:20
낙엽1124 (토론 | 기여)님의 2017년 11월 29일 (수) 17:20 판

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

  • 파이어폭스 / 사파리: 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-share-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 () {
  $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'section': 'main',
    'group': 'insert',
    'tools': {
      'comment': {
        label: '스포일러',
        type: 'button',
        //icon: {},
        offset: [8, -1798],
        action: {
          type: 'encapsulate',
          options: {
            pre: "<noinclude>{"+"{스포일러}}</noinclude>\n<includeonly>",
            peri: "text",
            post: "</includeonly>"
          }
        }
      }
    }
  } );
};

$(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 );
	    }
	  } );
	}
});

//시각편집기
function personalize() {

	function AddCategoriesCommand() {
		AddCategoriesCommand.parent.call( this, 'addCategories' );
	}
	OO.inheritClass( AddCategoriesCommand, ve.ui.Command );

	AddCategoriesCommand.prototype.execute = function( surface ) {
		var surfaceModel = ve.init.target.getSurface().getModel();
		surfaceModel.getFragment().insertContent(
		  [
		    {
		      type: 'mwTransclusionInline',
		      attributes: {
		        mw: {
		          parts: [
		            {
		              template: {
		                target: {
		                  wt: '분류'
		                },
		                params: {
		                	1 : { wt: ''}
		                }
		              }
		            }
		          ]
		        }
		      }
		    }
		  ]
		).collapseToEnd().select();

		return true;
	};
	ve.ui.commandRegistry.register( new AddCategoriesCommand() );

	function AddNotesSectionCommand() {
		AddNotesSectionCommand.parent.call( this, 'addNotesSection' );
	}
	OO.inheritClass( AddNotesSectionCommand, ve.ui.Command );

	AddNotesSectionCommand.prototype.execute = function( surface ) {
		var surfaceModel = ve.init.target.getSurface().getModel();
		surfaceModel.getFragment()
		.insertContent( [
			{ type: 'heading', attributes: { level: 2 }  }, '부', '연', ' ', '설', '명', { type: '/heading' },
			{
		      type: 'mwTransclusionInline',
		      attributes: {
		        mw: {
		          parts: [
		            {
		              template: {
		                target: {
		                  wt: '부연 설명'
		                },
		                params: {
		                }
		              }
		            }
		          ]
		        }
		      }
		    }
		] ).collapseToEnd().select();

		return true;
	};
	ve.ui.commandRegistry.register( new AddNotesSectionCommand() );

	function AddReferencesListCommand() {
		AddReferencesListCommand.parent.call( this, 'addReferencesList' );
	}
	OO.inheritClass( AddReferencesListCommand, ve.ui.Command );

	AddReferencesListCommand.prototype.execute = function( surface ) {
		var surfaceModel = ve.init.target.getSurface().getModel();
		surfaceModel.getFragment()
		.insertContent( [
			{ type: 'heading', attributes: { level: 2 }  }, '출', '처', { type: '/heading' },
			{ type: 'mwReferencesList', attributes: { name: null }}
		] ).collapseToEnd().select();

		return true;
	};
	ve.ui.commandRegistry.register( new AddReferencesListCommand() );


	ve.ui.triggerRegistry.register(
		'transclusion', 
		{
			pc: new ve.ui.Trigger( 'ctrl+shift+k' )
		}
	);
	ve.ui.triggerRegistry.register(
		'addCategories', 
		{
			pc: new ve.ui.Trigger( 'ctrl+shift+c' )
		}
	);
	ve.ui.toolFactory.registry.categories.static.commandName = "addCategories";

	ve.ui.sequenceRegistry.register(
	new ve.ui.Sequence(
		'addNotesSection', // Sequence name
		'addNotesSection', // Command name
		'=ㅂ',
		2
	));

	ve.ui.sequenceRegistry.register(
	new ve.ui.Sequence(
		'addReferencesList', // Sequence name
		'addReferencesList', // Command name
		'=ㅊ',
		2
	));
}

mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).then( function() {
	mw.libs.ve.addPlugin( function() {
		return mw.loader.using( [ 'ext.visualEditor.core' ] )
			.then( function() {
				personalize();
			} );
	} );
} );