Diferencia entre revisiones de «MediaWiki:Common.js»
Ir a la navegación
Ir a la búsqueda
m (-> gadget) |
m (slim down to necessities) |
||
Línea 1: | Línea 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ |
/* Any JavaScript here will be loaded for all users on every page load. */ |
||
− | |||
− | /* |
||
− | wrapper for creating new html elements |
||
− | */ |
||
− | function ne(tag, attrs) { |
||
− | var _ = $(document.createElement(tag)); |
||
− | for (var i in attrs) |
||
− | _.attr(i, attrs[i]); |
||
− | return _; |
||
− | } |
||
/* replace "Coppermind:Welcome" with "Welcome to the Coppermind" */ |
/* replace "Coppermind:Welcome" with "Welcome to the Coppermind" */ |
||
$('h1:contains("Coppermind:Welcome")').text("Welcome to the Coppermind"); |
$('h1:contains("Coppermind:Welcome")').text("Welcome to the Coppermind"); |
||
− | |||
− | /* 2017-11 - protect roll back links */ |
||
− | $('.mw-rollback-link').attr('onclick', "return confirm('definitely roll back?')") |
||
/* 2014-04 |
/* 2014-04 |
||
Línea 39: | Línea 26: | ||
}) |
}) |
||
− | }); |
||
− | |||
− | /* 2015-01 |
||
− | add links to Brandon's site and the interview database to the sidebar |
||
− | */ |
||
− | jQuery(function () { |
||
− | |||
− | function ModifySidebar( action, section, name, link ) { |
||
− | /* from https://www.mediawiki.org/wiki/Manual:Interface/Sidebar#Add_or_remove_toolbox_sections_.28JavaScript.29 */ |
||
− | try { |
||
− | switch ( section ) { |
||
− | case 'languages': |
||
− | var target = 'p-lang'; |
||
− | break; |
||
− | case 'toolbox': |
||
− | var target = 'p-tb'; |
||
− | break; |
||
− | case 'navigation': |
||
− | var target = 'p-navigation'; |
||
− | break; |
||
− | default: |
||
− | var target = 'p-' + section; |
||
− | break; |
||
− | } |
||
− | |||
− | if ( action == 'add' ) { |
||
− | var node = document.getElementById( target ) |
||
− | .getElementsByTagName( 'div' )[0] |
||
− | .getElementsByTagName( 'ul' )[0]; |
||
− | |||
− | var aNode = document.createElement( 'a' ); |
||
− | var liNode = document.createElement( 'li' ); |
||
− | |||
− | aNode.appendChild( document.createTextNode( name ) ); |
||
− | aNode.setAttribute( 'href', link ); |
||
− | liNode.appendChild( aNode ); |
||
− | liNode.className = 'plainlinks'; |
||
− | node.appendChild( liNode ); |
||
− | } |
||
− | |||
− | if ( action == 'remove' ) { |
||
− | var list = document.getElementById( target ) |
||
− | .getElementsByTagName( 'div' )[0] |
||
− | .getElementsByTagName( 'ul' )[0]; |
||
− | |||
− | var listelements = list.getElementsByTagName( 'li' ); |
||
− | |||
− | for ( var i = 0; i < listelements.length; i++ ) { |
||
− | if ( |
||
− | listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name || |
||
− | listelements[i].getElementsByTagName( 'a' )[0].href == link |
||
− | ) |
||
− | { |
||
− | list.removeChild( listelements[i] ); |
||
− | } |
||
− | } |
||
− | } |
||
− | |||
− | } catch( e ) { |
||
− | // let's just ignore what's happened |
||
− | return; |
||
− | } |
||
− | } |
||
− | |||
− | if (!mw.config.get('wgIsArticle') || mw.config.get('wgCanonicalNamespace') !== '') |
||
− | return; |
||
− | if (mw.config.get('wgCategories').includes('Meta')) |
||
− | return; |
||
− | var title = mw.config.get('wgTitle'); |
||
− | ModifySidebar( 'add', 'toolbox', "Search Brandon's website for " + title, 'https://brandonsanderson.com/?s='+ title ); |
||
− | ModifySidebar( 'add', 'toolbox', 'Search Arcanum for '+ title, 'https://wob.coppermind.net/adv_search/?query='+ title ); |
||
}); |
}); |
Revisión del 09:21 4 ago 2019
/* Any JavaScript here will be loaded for all users on every page load. */ /* replace "Coppermind:Welcome" with "Welcome to the Coppermind" */ $('h1:contains("Coppermind:Welcome")').text("Welcome to the Coppermind"); /* 2014-04 augment actionpaths edits to LocalSetting.php */ $('[href*="title="]').attr('href', function (i, value) { const old_link = value //console.debug('was linking to:', value) value = value.replace(/\/wiki\/\?title=([^&]+)\&(.+)/, "/wiki/$1?$2") value = value.replace(/\/w\/index.php\?title=(.+?)\&(.+?)/, "/wiki/$1?$2") if (old_link != value) console.debug('now linking to:', value, 'not:', old_link) return value }) $(function() { document.querySelectorAll('form.mw-search').forEach(function(form) { form.setAttribute('action','/wiki/Special:Search') }) document.querySelectorAll('form#search').forEach(function(form) { form.setAttribute('action', '/wiki/Special:Search') }) document.querySelectorAll('form[action*="/w/index.php"]').forEach(function(form) { console.debug('changing form', form, 'with action', form.getAttribute('action'), 'to `?`') form.setAttribute('action', '?') }) });