User:The Transhumanist/ViewAnnotationToggler.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:The Transhumanist/ViewAnnotationToggler. |
/* anno.js: Adds a tab menu item and hot key to toggle annotations in lists.
Based on: https://en.wikipedia.org/w/index.php?title=User:PleaseStand/hide-vector-sidebar.js&oldid=580854231
and https://en.wikipedia.org/wiki/User:Thespaceface/MetricFirst.js */
The hot key is Shift-Alt-a.
I ran into trouble with local scope, and solved it by reinitializing variables locally and creating a local 2nd clone.
There is probably a much more efficient method than this. If you happen to know of one, please let me know.
(The Transhumanist)
Currently, it is being tested on the use of regex within the ID element 'mw-content-text'.
Improvements needed:
Anchor regexes on <li> element delimiters
Find/replace annotations of other formats
nbsp;
comma
Find/replace annotations of lead list entries (without bullets)
Test on many pages of every page type
Toggle the script based on setting, rather than for each article
That is, make it so the script doesn't reset upon loading each page
Have it remember its toggle position
(WikEd has this feature, and a checkbox too)
( function ( mw, $ ) {
var annoSwitch;
var cont = document.getElementById('mw-content-text');
var orig = cont.cloneNode(true);
function annoHide() {
var cont = document.getElementById('mw-content-text');
var whattohide = cont.innerHTML.replace(/
whattohide = cont.innerHTML.replace(/
cont.innerHTML = whattohide;
// document.getElementById( 'bodyContent' ).style.visibility = 'hidden';
if ( annoSwitch ) {
annoSwitch.parentNode.removeChild(annoSwitch);
}
annoSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Show anno', 'ca-anno', 'Show the annotations', 'a' );
$( annoSwitch ).click( function ( e ) {
e.preventDefault();
annoShow();
} );
}
function annoShow() {
var cont = document.getElementById('mw-content-text');
var orig2 = orig.cloneNode(true);
$(cont).replaceWith(orig2);
// bodyContent.replaceChild(orig, cont);
// document.getElementById( 'bodyContent' ).style.visibility = '';
if ( annoSwitch ) {
annoSwitch.parentNode.removeChild(annoSwitch);
}
annoSwitch = mw.util.addPortletLink( 'p-cactions', '#', 'Hide anno', 'ca-anno', 'Hide the annotations', 'a' );
$( annoSwitch ).click( function ( e ) {
e.preventDefault();
annoHide();
} );
}
// Only activate on Vector skin
if ( mw.config.get( 'skin' ) === 'vector' ) {
$( function() {
// Change this if you want to show annotations by default
annoHide();
} );
}
}( mediaWiki, jQuery ) );