Jump to content

User:AHollender (WMF)/minerva.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// 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);
}