( function () { window.enom = {}; var enom = window.enom; var mw = window.mw; // console.log('enom: EditNoticesOnMobile loaded'); if ( !window.location.host.match( /(^|\.)m\./ ) && mw.config.get( 'skin' ) === 'minerva' ) { // desktop Minerva! The edit notice is here but it's playing hide-and-seek. child's play // console.log('enom: unhide notices on desktop Minerva'); mw.util.addCSS( '.content.fmbox,.content.tmbox {display:unset !important} .mw-editnotice * {display:unset !important}' ); // eslint-disable-next-line no-jquery/no-global-selector $( '.editnotice-page .fmbox,.editnotice-page .tmbox,.editnotice-page .tmbox-content' ).removeClass( [ 'fmbox', 'tmbox', 'tmbox-content' ] ); } else if ( mw.config.get( 'skin' ) === 'minerva' ) { // mobile Minerva, a bit more complicated. need to get the notice and create a popup // console.log('enom: you are on the mobile domain I think'); enom.time = Date.now(); enom.testValidJSON = function ( string ) { if ( string === null ) { return false; } try { JSON.parse( string ); } catch ( e ) { return false; } return true; }; enom.storeNotice = function ( notice ) { if ( window.localStorage && !enom.testValidJSON( window.localStorage.ENOM ) ) { window.localStorage.setItem( 'ENOM', '{}' ); } if ( window.localStorage && enom.testValidJSON( window.localStorage.ENOM ) ) { // not sure how all browsers behave if localStorage is unavailable, so to be safe, test validity enom.cachedNotices = JSON.parse( window.localStorage.ENOM ); enom.cachedNotices[ mw.config.get( 'wgPageName' ) ] = { text: notice, date: enom.time }; enom.cachedNoticesNew = JSON.stringify( enom.cachedNotices ); if ( enom.cachedNoticesNew.length > 1000000 ) { // it's quite unlikely a user would accumulate >1MB of edit notices, but if it somehow happens we purge all and start with a clean slate enom.cachedNoticesNew = '{}'; } window.localStorage.setItem( 'ENOM', enom.cachedNoticesNew ); } }; enom.getNotice = function () { if ( enom.trigger && enom.trigger.target && enom.trigger.target.href ) { enom.pageTitle = decodeURIComponent( enom.trigger.target.href.match( /.*title=([^&]*).*/ )[ 1 ] ); } else { enom.pageTitle = mw.config.get( 'wgPageName' ); } enom.newNotice = false; if ( window.localStorage && enom.testValidJSON( window.localStorage.ENOM ) ) { enom.cachedNotices = JSON.parse( window.localStorage.ENOM ); enom.update = false; for ( enom.cachedInt = 0; enom.cachedInt < Object.keys( enom.cachedNotices ).length; enom.cachedInt++ ) { enom.checkEntry = enom.cachedNotices[ Object.keys( enom.cachedNotices )[ enom.cachedInt ] ]; if ( enom.checkEntry.date < enom.time - 43200000 ) { // entry >12 hours (43200000ms) old // console.log('enom: removed '+Object.keys(enom.cachedNotices)[enom.cachedInt]+' from locally cached notices'); delete enom.cachedNotices[ Object.keys( enom.cachedNotices )[ enom.cachedInt ] ]; enom.update = true; } if ( enom.update ) { window.localStorage.setItem( 'ENOM', JSON.stringify( enom.cachedNotices ) ); } } if ( enom.cachedNotices[ mw.config.get( 'wgPageName' ) ] ) { enom.noticeText = enom.cachedNotices[ mw.config.get( 'wgPageName' ) ].text; // console.log('enom: found cached notice'); enom.popupNotice( enom.noticeText, false ); return; } } enom.editNoticeParams = { format: 'json', action: 'visualeditor', paction: 'metadata', page: enom.pageTitle, formatversion: '2' }; mw.loader.using( [ 'mediawiki.api' ], function () { // console.log('enom: download notice'); enom.newNotice = true; var api = new mw.Api(); api.post( enom.editNoticeParams ).done( function ( data ) { enom.parsednotices = '