コンテンツにスキップ
Wikipedia

MediaWiki:Common.js

お知らせ: 保存した後、ブラウザのキャッシュをクリアしてページを再読み込みする必要があります。

多くの WindowsLinux のブラウザ

  • Ctrl を押しながら F5 を押す。

Mac における Safari

  • Shift を押しながら、更新ボタン をクリックする。

Mac における ChromeFirefox

  • Cmd Shift を押しながら R を押す。

詳細についてはWikipedia:キャッシュを消すをご覧ください。

 /* ここに書いたスクリプトは全ての外装に反映されます */
 /* global mw, $ */
 /* jshint strict:false, browser:true */
 mw.loader.using(['mediawiki.util'],function(){
 /**
 	 * Map addPortletLink to mw.util
 	 * @deprecated: Use mw.util.addPortletLink instead.
 	 */
 mw.log.deprecate(window,'addPortletLink',mw.util.addPortletLink,'代わりにmw.util.addPortletLinkを使用してください');

 /**
 	 * Test if an element has a certain class
 	 * @deprecated: Use $(element).hasClass() instead.
 	 */
 mw.log.deprecate(window,'hasClass',function(element,className){
 return$(element).hasClass(className);
 },'代わりにjQuery.hasClass()を使用してください');

 /** &withJS= URL parameter, &withCSS= URL parameter *******
 	 * [[mw:Snippets/Load JS and CSS by URL]]より。MediaWiki空間に置かれているスクリプトまたはスタイルシートを
 	 * [[Special:Mypage/common.js]]または[[Special:Mypage/common.css]]を編集しないで体験できるようにする
 	 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 	 * @revision 2020年04月04日
 	 */
 varextraCSS=mw.util.getParamValue('withCSS'),
 extraJS=mw.util.getParamValue('withJS');

 if(extraCSS){
 // WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
 if(/^MediaWiki:[^&<>=%#]*\.css$/.test(extraCSS)){
 mw.loader.load('/w/index.php?title='+encodeURIComponent(extraCSS)+'&action=raw&ctype=text/css','text/css');
 }else{
 mw.notify('MediaWiki名前空間のページのみ許可されています。',{title:'withCSSパラメータの値が不正です'});
 }
 }

 if(extraJS){
 // WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks)
 if(/^MediaWiki:[^&<>=%#]*\.js$/.test(extraJS)){
 mw.loader.load('/w/index.php?title='+encodeURIComponent(extraJS)+'&action=raw&ctype=text/javascript');
 }else{
 mw.notify('MediaWiki名前空間のページのみ許可されています。',{title:'withJSパラメータの値が不正です'});
 }
 }

 /** Dynamic Navigation Bars (experimental) *************************************
 	 *
 	 * Description: See [[Wikipedia:NavFrame]].
 	 * Maintainers: UNMAINTAINED
 	 */

 varcollapseCaption='隠す';
 varexpandCaption='表示';

 // set up the words in your language
 varnavigationBarHide='['+collapseCaption+']';
 varnavigationBarShow='['+expandCaption+']';

 /**
 	* Shows and hides content and picture (if available) of navigation bars.
 	*
 	* @param {number} indexNavigationBar The index of navigation bar to be toggled
 	* @param {jQuery.Event} event Event object
 	* @return {boolean}
 	*/

 functiontoggleNavigationBar(indexNavigationBar,event){
 varnavToggle=document.getElementById('NavToggle'+indexNavigationBar);
 varnavFrame=document.getElementById('NavFrame'+indexNavigationBar);
 varnavChild;

 if(!navFrame||!navToggle){
 returnfalse;
 }

 // If shown now
 if(navToggle.firstChild.data===navigationBarHide){
 for(navChild=navFrame.firstChild;navChild!==null;navChild=navChild.nextSibling){
 if($(navChild).hasClass('NavContent')){
 navChild.style.display='none';
 }
 }
 navToggle.firstChild.data=navigationBarShow;

 // If hidden now
 }elseif(navToggle.firstChild.data===navigationBarShow){
 for(navChild=navFrame.firstChild;navChild!==null;navChild=navChild.nextSibling){
 if($(navChild).hasClass('NavContent')){
 navChild.style.display='block';
 }
 }
 navToggle.firstChild.data=navigationBarHide;
 }

 if(event!==undefined){
 event.preventDefault();
 }
 }

 /**
 	 * Adds show/hide-button to navigation bars.
 	 *
 	 * @param {jQuery} $content
 	 */

 functioncreateNavigationBarToggleButton($content){
 varj,navChild,navToggle,navToggleText,isCollapsed,
 indexNavigationBar=0;
 // Iterate over all < div >-elements
 var$divs=$content.find('div.NavFrame:not(.mw-collapsible)');
 $divs.each(function(i,navFrame){
 indexNavigationBar++;
 navToggle=document.createElement('a');
 navToggle.className='NavToggle';
 navToggle.setAttribute('id','NavToggle'+indexNavigationBar);
 navToggle.setAttribute('href','#');
 $(navToggle).on('click',$.proxy(toggleNavigationBar,null,indexNavigationBar));

 isCollapsed=true;
 /**
 			 * Check if any children are already hidden. This loop is here for backwards compatibility:
 			 * the old way of making NavFrames start out collapsed was to manually add style="display:none"
 			 * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
 			 * the content visible without JavaScript support), the new recommended way is to add the class
 			 * "collapsed" to the NavFrame itself, just like with collapsible tables.
 			 */
 for(navChild=navFrame.firstChild;navChild!==null&&!isCollapsed;navChild=navChild.nextSibling){
 if($(navChild).hasClass('NavPic')||$(navChild).hasClass('NavContent')){
 if(navChild.style.display==='none'){
 isCollapsed=true;
 }
 }
 }
 if(isCollapsed){
 for(navChild=navFrame.firstChild;navChild!==null;navChild=navChild.nextSibling){
 if($(navChild).hasClass('NavPic')||$(navChild).hasClass('NavContent')){
 navChild.style.display='none';
 }
 }
 }
 navToggleText=document.createTextNode(isCollapsed?navigationBarShow:navigationBarHide);
 navToggle.appendChild(navToggleText);

 // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
 for(j=0;j<navFrame.childNodes.length;j++){
 if($(navFrame.childNodes[j]).hasClass('NavHead')){
 navToggle.style.color=navFrame.childNodes[j].style.color;
 navFrame.childNodes[j].appendChild(navToggle);
 }
 }
 navFrame.setAttribute('id','NavFrame'+indexNavigationBar);
 });
 }

 mw.hook('wikipage.content').add(createNavigationBarToggleButton);

 /**
 	 * Collapsible tables; reimplemented with mw-collapsible
 	 * Styling is also in place to avoid FOUC
 	 *
 	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
 	 * @version 3.0.0 (2018年05月20日)
 	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 	 * @author [[User:R. Koot]]
 	 * @author [[User:Krinkle]]
 	 * @author [[User:TheDJ]]
 	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
 	 *
 	 * @param {jQuery} $content
 	 */
 functionmakeCollapsibleMwCollapsible($content){
 var$tables=$content
 .find('table.collapsible:not(.mw-collapsible)')
 .addClass('mw-collapsible');

 $.each($tables,function(index,table){
 // mw.log.warn( 'このページは非推奨のcollapsibleクラスを使用しています。mw-collapsibleクラスに置換してください。');
 if($(table).hasClass('collapsed')){
 $(table).addClass('mw-collapsed');
 // mw.log.warn( 'このページは非推奨のcollapsedクラスを使用しています。mw-collapsedクラスに置換してください。');
 }
 });
 if($tables.length>0){
 mw.loader.using('jquery.makeCollapsible').then(function(){
 $tables.makeCollapsible();
 });
 }
 }
 mw.hook('wikipage.content').add(makeCollapsibleMwCollapsible);

 /**
 	 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
 	 *
 	 * Maintainers: TheDJ
 	 */
 functionmwCollapsibleSetup($collapsibleContent){
 var$element,
 $toggle,
 autoCollapseThreshold=2;
 $.each($collapsibleContent,function(index,element){
 $element=$(element);
 if($element.hasClass('collapsible')){
 $element.find('tr:first > th:first').prepend($element.find('tr:first > * > .mw-collapsible-toggle'));
 }
 if($collapsibleContent.length>=autoCollapseThreshold&&$element.hasClass('autocollapse')){
 $element.data('mw-collapsible').collapse();
 }elseif($element.hasClass('innercollapse')){
 if($element.parents('.outercollapse').length>0){
 $element.data('mw-collapsible').collapse();
 }
 }
 // because of colored backgrounds, style the link in the text color
 // to ensure accessible contrast
 $toggle=$element.find('.mw-collapsible-toggle');
 if($toggle.length){
 // Make the toggle inherit text color
 if($toggle.parent()[0].style.color){
 $toggle.find('a').css('color','inherit');
 }
 }
 });
 }

 mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);

 /**
 	 * Magic editintros
 	 *
 	 * Appends `&editintro=Template:hogehoge` to the query parameters of edit links
 	 * on the page dynamically, referring to the categories that the page belongs to.
 	 */
 if(mw.config.get('wgNamespaceNumber')===0){

 /**
 		 * @param {string} title The template title without a namespace prefix.
 		 */
 constaddEditIntro=(title)=>{
 $('.mw-editsection, #ca-edit, #ca-ve-edit').find('a').each(function(_,el){
 el.href=$(this).attr('href')+'&editintro='+mw.util.wikiUrlencode('Template:'+title);
 });
 };

 /**
 		 * Mapping from category titles to template titles to use for editintro (both
 		 * with no namespace prefix).
 		 *
 		 * Note: Currently, MediaWiki supports addition of only one editintro, since query
 		 * parameters must be unique (see also [[phab:T390419]]). The order of registration
 		 * in this Map object determines which editintro should be prioritized than another.
 		 *
 		 * @type {Map<string, string>}
 		 */
 consteditintroMap=newMap([
 ['存命人物','BLP editintro'],
 ['YouTube personality','Infobox YouTube personality editintro'],
 ['学校記事','学校記事 editintro'],
 ['鉄道車両関連','RRS editintro']
 ]);
 constcategories=newSet(mw.config.get('wgCategories'));

 $(function(){
 // Hack: If the page belongs to both Category:存命人物 and Category:YouTube_personality,
 // load Template:BLP-YTP_editintro to simulate multiple editintros
 if(categories.has('存命人物')&&categories.has('YouTube personality')){
 addEditIntro('BLP-YTP editintro');
 return;
 }

 for(const[cat,temp]ofeditintroMap){
 if(categories.has(cat)){
 addEditIntro(temp);
 return;
 }
 }
 });

 }

 });

AltStyle によって変換されたページ (->オリジナル) /