User:AHollender (WMF)/minerva.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. |
The accompanying .css page for this skin is at User:AHollender (WMF)/minerva.css. |
// Full stylesheet url
mw.loader.load( '/wiki/User:AHollender_(WMF)/story.css?action=raw&ctype=text/css', 'text/css' );
console.log('hello from user script land');
var pageTitle;
var urlString = 'User%3AAHollender_(WMF)%2Fstory%2F';
var storyHtml;
// remove Talk tab
$('.minerva__tab-container a:nth-child(2)').remove();
// add Visual story tab
$('.minerva__tab-container').append('<a id="storyTab" class="minerva__tab" onclick="openStory()">Summary</a>');
// get page title
pageTitle = urlString + /[^/]*$/.exec(window.location.pathname)[0];
// get visual story HTML
$.get( 'https://en.wikipedia.org/api/rest_v1/page/html/' + pageTitle, function ( data ) {
console.log( 'getting page...' );
var htmlDoc = new DOMParser().parseFromString( data, 'text/html' );
storyHtml = htmlDoc.getElementsByTagName('section');
} );
// add story container to overlay container
setTimeout(function(){
$('.mw-overlays-container').append('<div id="storyContainer" class="overlay view-border-box overlay-ios"><div id="storyContent">');
$('#storyContent').append(storyHtml);
$('#storyContainer').append('<div id="closeOverlay" onclick="closeOverlay()"> <img src="https://mobile-stories-96b31.web.app/img/close.svg"> <p>Close');
}, 1000);
// open story modal
function openStory() {
console.log('open the story modal');
$('#storyContainer').addClass('visible');
}
// close story modal
function closeOverlay() {
console.log('close the story modal');
$('#storyContainer').removeClass('visible');
window.scrollTo(0, 0);
}