| 1 |
const controller = require( './controller.js' ), |
| 2 |
url = new URL( location.href ); |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
mw.dt = {}; |
| 9 |
|
| 10 |
mw.dt.initState = { |
| 11 |
firstLoad: true |
| 12 |
}; |
| 13 |
|
| 14 |
if ( url.searchParams.get( 'dtrepliedto' ) ) { |
| 15 |
|
| 16 |
|
| 17 |
mw.dt.initState.repliedTo = url.searchParams.get( 'dtrepliedto' ); |
| 18 |
mw.dt.initState.tempUserCreated = url.searchParams.has( 'dttempusercreated' ); |
| 19 |
url.searchParams.delete( 'dtrepliedto' ); |
| 20 |
url.searchParams.delete( 'dttempusercreated' ); |
| 21 |
window.history.replaceState( {}, '', url ); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
mw.dt.init = function ( $container ) { |
| 30 |
function reallyInit( $node ) { |
| 31 |
controller.init( $node, mw.dt.initState ); |
| 32 |
mw.dt.initState = {}; |
| 33 |
|
| 34 |
|
| 35 |
$( document.documentElement ).addClass( 'ext-discussiontools-init-ready' ); |
| 36 |
} |
| 37 |
|
| 38 |
ge |
| 39 |
|
| 40 |
if ( $container.is( '#mw-content-text' ) || $container.find( '#mw-content-text' ).length ) { |
| 41 |
|
| 42 |
reallyInit( $( '#mw-content-text' ) ); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
if ( !$container.closest( 'html' ).length ) { |
| 48 |
setTimeout( () => { |
| 49 |
if ( $container.closest( 'html' ).length ) { |
| 50 |
mw.dt.init( $container ); |
| 51 |
} |
| 52 |
} ); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
const livePreviewSelectors = '#wikiPreview, .ext-WikiEditor-realtimepreview-preview'; |
| 60 |
if ( $container.parent().is( livePreviewSelectors ) ) { |
| 61 |
reallyInit( $container ); |
| 62 |
return; |
| 63 |
} |
| 64 |
}; |
| 65 |
|
| 66 |
if ( url.searchParams.get( 'dtdebug' ) ) { |
| 67 |
mw.loader.load( 'ext.discussionTools.debug' ); |
| 68 |
} else { |
| 69 |
|
| 70 |
mw.hook( 'wikipage.content' ).add( mw.dt.init ); |
| 71 |
} |
| 72 |
|
| 73 |
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'TopicSubscriptions' ) { |
| 74 |
const topicSubscriptions = require( './topicsubscriptions.js' ); |
| 75 |
topicSubscriptions.initSpecialTopicSubscriptions(); |
| 76 |
} |
| 77 |
|
| 78 |
if ( mw.config.get( 'wgAction' ) === 'history' ) { |
| 79 |
const topicSubscriptions = require( './topicsubscriptions.js' ); |
| 80 |
topicSubscriptions.initNewTopicsSubscription(); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
mw.requestIdleCallback( () => { |
| 87 |
try { |
| 88 |
for ( const key in localStorage ) { |
| 89 |
if ( key.startsWith( 'reply/' ) ) { |
| 90 |
localStorage.removeItem( key ); |
| 91 |
localStorage.removeItem( '_EXPIRY_' + key ); |
| 92 |
} |
| 93 |
} |
| 94 |
} catch ( err ) {} |
| 95 |
} ); |
| 96 |
|
| 97 |
module.exports = { |
| 98 |
controller: controller, |
| 99 |
Parser: require( './Parser.js' ), |
| 100 |
parserData: require( './parser/data.json' ), |
| 101 |
modifier: require( './modifier.js' ), |
| 102 |
ThreadItem: require( './ThreadItem.js' ), |
| 103 |
HeadingItem: require( './HeadingItem.js' ), |
| 104 |
CommentItem: require( './CommentItem.js' ), |
| 105 |
utils: require( './utils.js' ), |
| 106 |
config: require( './config.json' ) |
| 107 |
}; |