User:Jdlrobson/readingList.js

mw.loader.impl(function{return["ext.gadget.readinglist.init@",{"main":"resources/ext.gadget.readinglist.init/main.js","files":{"resources/ext.gadget.readinglist.init/main.js":function(require,module,exports){/** * When re-generating this file use: * http://localhost:8888/w/load.php?modules=ext.gadget.readinglist&debug=true * and copy to https://en.wikipedia.org/w/index.php?title=User:Jdlrobson/readingList.js&action=edit */ // /** * @param {string} ownerName person who owns the list * @param {number} [id] of the list * @param {string} [title] of the list * @return {string} */ const getReadingListUrl = ( ownerName, id, title ) => {	const READING_LIST_HOST = 'https://meta.wikimedia.org';	let titlePath = 'ReadingLists';	if ( ownerName ) {		titlePath += `/${ownerName}`;	}	if ( id ) {		titlePath += `/${id}`;	}	const titleWithName = title ? `${titlePath}/${encodeURIComponent( title )}` : titlePath; try { return READING_LIST_HOST + (			new mw.Title( titleWithName, -1 )		).getUrl; } catch ( e ) { // Uncaught Error: Unable to parse title // e.g. Special:ReadingLists/1/ return READING_LIST_HOST + (			new mw.Title( titlePath, -1 )		).getUrl; } };

var loaded; function loadGadget { if ( loaded ) { return; }	mw.loader.using([		"mediawiki.api",		"mediawiki.user",		"vue",		"@wikimedia/codex",		"mediawiki.Title"	]).then(function {		window.READING_LIST_SHOW_OVERLAY = true;		if ( mw.loader.getState('ext.gadget.readinglist') ) {			mw.loader.using( 'ext.gadget.readinglist');		} else {			mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=User:Jdlrobson/rlNew.js&action=raw&ctype=text/javascript' );		}		loaded = true;	}) }

function addNewBookmarkLink { // add bookmark icon let li = mw.util.addPortletLink('p-views', '#', 'Bookmark', 'pt-bookmark'); if ( !li ) { li = mw.util.addPortletLink('page-actions', '#', 'Bookmark', 'pt-bookmark' ); }	if ( li ) { // Hack: no native support for vector icons. setTimeout( => {			li.classList.remove( 'vector-tab-noicon' );		}, 300 ); const link = li.querySelector( 'a' ); if ( link ) { link.classList.add(				'cdx-button--weight-quiet',				'cdx-button--fake-button',				'cdx-button--icon-only',				'cdx-button'			); }		li.addEventListener( 'click', function {			loadGadget;		} ); }	return li; }

mw.loader.using( 'mediawiki.user' ).then( function {	const READING_LIST_URL = getReadingListUrl( mw.user.getName );	const isSpecialReadingList = mw.config.get( 'wgTitle').indexOf('ReadingListz/') > -1 ||		 (mw.config.get( 'wgTitle').indexOf('ReadingList/') > -1 && !location.host.match(/(mediawiki.org|meta.wikimedia.org)/) );	if ( isSpecialReadingList ) {		loadGadget;	}	if ( !mw.user.isAnon ) {		mw.util.addPortletLink( 'p-personal', READING_LIST_URL, 'My reading lists', 'pt-readinglists', null, 'l', 'pt-watchlist' );		// reuse watchstar if possible.		let watchstar = document.querySelector( '#ca-unwatch, #ca-watch' );		const newLink = addNewBookmarkLink;		if ( watchstar ) {			if ( watchstar.tagName === 'A' ) {				watchstar = watchstar.parentNode;			}			watchstar.replaceWith( newLink );			const icon = newLink.firstChild;			icon.classList.add( 'ext-rl-icon-bookmark' );			return;		} } });

}}},{"css":}];});