2019-10-24 14:38:31 +00:00
|
|
|
var
|
2020-07-20 21:15:03 +00:00
|
|
|
Parser = require( 'ext.discussionTools.init' ).Parser,
|
2020-12-12 12:52:28 +00:00
|
|
|
modifier = require( 'ext.discussionTools.init' ).modifier,
|
|
|
|
utils = require( 'ext.discussionTools.init' ).utils,
|
2022-03-01 14:18:07 +00:00
|
|
|
debugHighlighter = require( './debughighlighter.js' ),
|
2022-02-19 06:31:34 +00:00
|
|
|
parser = new Parser( require( 'ext.discussionTools.init' ).parserData ),
|
|
|
|
result = parser.parse(
|
2022-01-11 15:50:44 +00:00
|
|
|
document.getElementById( 'mw-content-text' ),
|
|
|
|
mw.Title.newFromText( mw.config.get( 'wgRelevantPageName' ) )
|
|
|
|
),
|
2022-02-19 06:31:34 +00:00
|
|
|
comments = result.getCommentItems(),
|
|
|
|
threads = result.getThreads(),
|
2020-12-12 12:52:28 +00:00
|
|
|
timestampRegexps = parser.getLocalTimestampRegexps(),
|
2022-03-29 21:25:21 +00:00
|
|
|
debug = +( new URL( location.href ).searchParams.get( 'dtdebug' ) ),
|
2020-12-12 12:52:28 +00:00
|
|
|
DEBUG_HIGHLIGHT = 1,
|
|
|
|
DEBUG_VOTE = 2,
|
|
|
|
DEBUG_VOTE_PERMISSIVE = 4;
|
2019-10-24 14:38:31 +00:00
|
|
|
|
2020-12-12 12:52:28 +00:00
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
if ( debug & DEBUG_HIGHLIGHT ) {
|
2022-03-01 14:18:07 +00:00
|
|
|
debugHighlighter.markThreads( threads );
|
2019-10-24 14:38:31 +00:00
|
|
|
|
2020-12-12 12:52:28 +00:00
|
|
|
comments.forEach( function ( comment ) {
|
|
|
|
comment.signatureRanges.forEach( function ( signatureRange ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var node = signatureRange.endContainer;
|
|
|
|
var match = parser.findTimestamp( node, timestampRegexps );
|
2020-12-12 12:52:28 +00:00
|
|
|
if ( !match ) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-04 15:44:14 +00:00
|
|
|
var signature = parser.findSignature( node ).nodes;
|
2021-04-08 13:46:09 +00:00
|
|
|
var emptySignature = signature.length === 1 && signature[ 0 ] === node;
|
2020-12-12 12:52:28 +00:00
|
|
|
// Note that additional content may follow the timestamp (e.g. in some voting formats), but we
|
|
|
|
// don't care about it. The code below doesn't mark that due to now the text nodes are sliced,
|
|
|
|
// but we might need to take care to use the matched range of node in other cases.
|
2022-03-01 14:18:07 +00:00
|
|
|
debugHighlighter.markTimestamp( parser, node, match );
|
2020-12-12 12:52:28 +00:00
|
|
|
if ( !emptySignature ) {
|
2022-03-01 14:18:07 +00:00
|
|
|
debugHighlighter.markSignature( signature );
|
2020-12-12 12:52:28 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
if ( ( debug & DEBUG_VOTE ) || ( debug & DEBUG_VOTE_PERMISSIVE ) ) {
|
|
|
|
threads.forEach( function ( thread ) {
|
2021-04-08 13:46:09 +00:00
|
|
|
var firstComment = thread.replies[ 0 ];
|
2020-12-12 12:52:28 +00:00
|
|
|
|
|
|
|
if ( firstComment && firstComment.type === 'comment' ) {
|
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
if ( !( debug & DEBUG_VOTE_PERMISSIVE ) && firstComment.level <= 1 ) {
|
|
|
|
// Not in permissive vote mode, and first reply was not indented
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var firstVote = firstComment.level === 1 ?
|
2020-12-12 12:52:28 +00:00
|
|
|
// In permissive mode, the first vote is the replies to the OP
|
|
|
|
firstComment.replies[ 0 ] :
|
|
|
|
firstComment;
|
|
|
|
|
|
|
|
if ( !firstVote ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var lastReply;
|
|
|
|
var level = firstVote.level;
|
2020-12-12 12:52:28 +00:00
|
|
|
firstVote.parent.replies.forEach( function ( reply ) {
|
|
|
|
if ( reply.type === 'comment' && reply.level <= level ) {
|
|
|
|
lastReply = reply;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-04-08 13:46:09 +00:00
|
|
|
var listItem = modifier.addSiblingListItem(
|
2020-12-12 12:52:28 +00:00
|
|
|
utils.closestElement( lastReply.range.endContainer, [ 'li', 'dd', 'p' ] )
|
|
|
|
);
|
|
|
|
if ( listItem && listItem.tagName.toLowerCase() === 'li' ) {
|
|
|
|
$( listItem )
|
|
|
|
// Hide bullet/number
|
|
|
|
.css( 'list-style', 'none' )
|
|
|
|
.append(
|
|
|
|
'[ ',
|
|
|
|
$( '<a>' ).text( 'add comment' ),
|
|
|
|
' ]'
|
|
|
|
);
|
|
|
|
}
|
2020-12-12 12:50:14 +00:00
|
|
|
}
|
|
|
|
} );
|
2020-12-12 12:52:28 +00:00
|
|
|
}
|