| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
( function () { |
| 5 |
function trimStart( s ) { |
| 6 |
return s.replace( /^ /, '' ); |
| 7 |
} |
| 8 |
|
| 9 |
function trimEnd( s ) { |
| 10 |
return s.endsWith( ' ' ) ? s.slice( 0, s.length - 1 ) : s; |
| 11 |
} |
| 12 |
|
| 13 |
$( () => { |
| 14 |
const api = new mw.Api(); |
| 15 |
const $resetForm = $( '#mw-watchlist-resetbutton' ); |
| 16 |
let $progressBar; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
$resetForm.on( 'submit', ( event ) => { |
| 22 |
const $button = $resetForm.find( 'input[name=mw-watchlist-reset-submit]' ); |
| 23 |
|
| 24 |
event.preventDefault(); |
| 25 |
|
| 26 |
|
| 27 |
$button.prop( 'disabled', true ); |
| 28 |
|
| 29 |
if ( !$progressBar ) { |
| 30 |
$progressBar = new OO.ui.ProgressBarWidget( { progress: false } ).$element; |
| 31 |
$progressBar.css( { |
| 32 |
position: 'absolute', width: '100%' |
| 33 |
} ); |
| 34 |
} |
| 35 |
|
| 36 |
$resetForm.append( $progressBar ); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
api.postWithToken( 'csrf', { |
| 41 |
formatversion: 2, action: 'setnotificationtimestamp', entirewatchlist: true |
| 42 |
} ).done( () => { |
| 43 |
|
| 44 |
$button.prop( 'disabled', false ); |
| 45 |
|
| 46 |
$button.css( 'visibility', 'hidden' ); |
| 47 |
$progressBar.detach(); |
| 48 |
$( '.mw-changeslist-line-watched' ) |
| 49 |
.removeClass( 'mw-changeslist-line-watched' ) |
| 50 |
.addClass( 'mw-changeslist-line-not-watched' ); |
| 51 |
} ).fail( () => { |
| 52 |
|
| 53 |
|
| 54 |
$resetForm.off( 'submit' ).trigger( 'submit' ); |
| 55 |
} ); |
| 56 |
} ); |
| 57 |
|
| 58 |
|
| 59 |
if ( mw.user.options.get( 'watchlistreloadautomatically' ) ) { |
| 60 |
|
| 61 |
$( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', () => { |
| 62 |
|
| 63 |
$( '#mw-watchlist-form' ).trigger( 'submit' ); |
| 64 |
} ); |
| 65 |
} |
| 66 |
|
| 67 |
if ( mw.user.options.get( 'watchlistunwatchlinks' ) ) { |
| 68 |
|
| 69 |
. |
| 70 |
. |
| 71 |
|
| 72 |
$( '.mw-changeslist' ).on( 'click', '.mw-unwatch-link, .mw-watch-link', function ( event ) { |
| 73 |
const $unwatchLink = $( this ), |
| 74 |
$watchlistLine = $unwatchLink.closest( 'li, table' ) |
| 75 |
.find( '[data-target-page]' ), |
| 76 |
pageTitle = String( $watchlistLine.data( 'targetPage' ) ), |
| 77 |
isTalk = mw.Title.newFromText( pageTitle ).isTalkPage(); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
function forEachMatchingTitle( title, callback ) { |
| 82 |
|
| 83 |
const titleObj = mw.Title.newFromText( title ), |
| 84 |
associatedTitleObj = titleObj.isTalkPage() ? titleObj.getSubjectPage() : titleObj.getTalkPage(), |
| 85 |
associatedTitle = associatedTitleObj.getPrefixedText(); |
| 86 |
$( '.mw-changeslist-line' ).each( function () { |
| 87 |
const $line = $( this ); |
| 88 |
|
| 89 |
$line.find( '[data-target-page]' ).each( function () { |
| 90 |
const $this = $( this ), rowTitle = String( $this.data( 'targetPage' ) ); |
| 91 |
if ( rowTitle === title || rowTitle === associatedTitle ) { |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
const $row = |
| 98 |
$this.closest( |
| 99 |
'li, .mw-enhancedchanges-checkbox + table.mw-changeslist-log td[data-target-page], table' ); |
| 100 |
const $link = $row.find( '.mw-unwatch-link, .mw-watch-link' ); |
| 101 |
|
| 102 |
callback( rowTitle, $row, $link ); |
| 103 |
} |
| 104 |
} ); |
| 105 |
} ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
mw.loader.load( 'mediawiki.notification' ); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
if ( $unwatchLink.hasClass( 'mw-unwatch-link' ) ) { |
| 115 |
api.unwatch( pageTitle ) |
| 116 |
.done( () => { |
| 117 |
forEachMatchingTitle( pageTitle, |
| 118 |
( rowPageTitle, $row, $rowUnwatchLink ) => { |
| 119 |
$rowUnwatchLink |
| 120 |
.text( mw.msg( 'watchlist-unwatch-undo' ) ) |
| 121 |
.attr( 'title', mw.msg( 'tooltip-ca-watch' ) ) |
| 122 |
.attr( 'href', |
| 123 |
mw.util.getUrl( rowPageTitle, { action: 'watch' } ) ) |
| 124 |
.removeClass( 'mw-unwatch-link loading' ) |
| 125 |
.addClass( 'mw-watch-link' ); |
| 126 |
$row.find( |
| 127 |
'.mw-changeslist-line-inner, .mw-enhanced-rc-nested' ) |
| 128 |
.addBack( '.mw-enhanced-rc-nested' ) |
| 129 |
.addClass( 'mw-changelist-line-inner-unwatched' ); |
| 130 |
} ); |
| 131 |
|
| 132 |
mw.notify( |
| 133 |
mw.message( isTalk ? 'removedwatchtext-talk' : 'removedwatchtext', |
| 134 |
pageTitle ), { tag: 'watch-self' } ); |
| 135 |
} ); |
| 136 |
} else { |
| 137 |
api.watch( pageTitle ) |
| 138 |
.then( () => { |
| 139 |
forEachMatchingTitle( pageTitle, |
| 140 |
( rowPageTitle, $row, $rowUnwatchLink ) => { |
| 141 |
$rowUnwatchLink |
| 142 |
.text( mw.msg( 'watchlist-unwatch' ) ) |
| 143 |
.attr( 'title', mw.msg( 'tooltip-ca-unwatch' ) ) |
| 144 |
.attr( 'href', |
| 145 |
mw.util.getUrl( rowPageTitle, { action: 'unwatch' } ) ) |
| 146 |
.removeClass( 'mw-watch-link loading' ) |
| 147 |
.addClass( 'mw-unwatch-link' ); |
| 148 |
$row.find( '.mw-changelist-line-inner-unwatched' ) |
| 149 |
.addBack( '.mw-enhanced-rc-nested' ) |
| 150 |
.removeClass( 'mw-changelist-line-inner-unwatched' ); |
| 151 |
$row.find( '.mw-changesList-watchlistExpiry' ).each( function () { |
| 152 |
|
| 153 |
const $expiry = $( this ); |
| 154 |
$expiry.next( '.mw-changeslist-separator' ) |
| 155 |
.addClass( 'mw-changeslist-separator--semicolon' ) |
| 156 |
.removeClass( 'mw-changeslist-separator' ); |
| 157 |
|
| 158 |
this.nextSibling.nodeValue = trimStart( this.nextSibling.nodeValue ); |
| 159 |
this.previousSibling.nodeValue = trimEnd( this.previousSibling.nodeValue ); |
| 160 |
|
| 161 |
$expiry.remove(); |
| 162 |
} ); |
| 163 |
} ); |
| 164 |
|
| 165 |
mw.notify( |
| 166 |
mw.message( isTalk ? 'addedwatchtext-talk' : 'addedwatchtext', |
| 167 |
pageTitle ), { tag: 'watch-self' } ); |
| 168 |
} ); |
| 169 |
} |
| 170 |
|
| 171 |
event.preventDefault(); |
| 172 |
event.stopPropagation(); |
| 173 |
$unwatchLink.trigger( 'blur' ); |
| 174 |
} ); |
| 175 |
} |
| 176 |
} ); |
| 177 |
|
| 178 |
}() ); |