User:NQ/WatchlistResetConfirm.js
Appearance
< User:NQ
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:NQ/WatchlistResetConfirm. |
/*Adds a confirmation dialogue to the Watchlist Reset button
https://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_(technical)&oldid=746997333#Watchlist:_.22Are_you_sure_you_want_to_mark_all_pages_as_visited.3F.22
* Licensed under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. See the
* GNU General Public License for more details.
* A copy of the GPL is available at https://www.gnu.org/licenses/gpl-2.0.txt
/* ############################################################################
$(function() {
$watchlistReset = $('#mw-watchlist-resetbutton');
$watchlistReset.css('display', 'inline'); //already hidden in css
$watchlistReset.on('click', function(event) {
if (!confirm('Are you sure you want to mark all pages as visited?' )) {
event.preventDefault();
}
});
}); ############################################################################ */
/* Using [[:mw:OOjs_UI/Windows/Message_Dialogs]] */
mw.loader.using(['mediawiki.api', 'oojs-ui'], function() {
$watchlistReset = $('#mw-watchlist-resetbutton');
$watchlistReset.css('display', 'inline'); //if already hidden in css; recommended
var messageDialog = new OO.ui.MessageDialog();
var windowManager = new OO.ui.WindowManager();
$('body').append(windowManager.$element);
windowManager.addWindows([messageDialog]);
$watchlistReset.submit(function(event) {
event.preventDefault();
windowManager.openWindow(messageDialog, {
title: 'Confirm',
message: 'Mark all pages as visited?',
actions: [{ action: 'reject', label: 'Cancel', flags: ['safe', 'destructive'] },
{ action: 'reset', label: 'Confirm', flags: ['primary', 'progressive']}]
}).then(function(opened) {
opened.then(function(closing, data) {
if (data && data.action === 'reset') {
/* Uses [[:mw:API:SetNotificationTimestamp]] to reset the watchlist without refreshing the page */
// Code adapted from [[User:HueSatLum/common.js]]
new mw.Api().post({
action: 'setnotificationtimestamp',
entirewatchlist: '',
token: mw.user.tokens.get('editToken')
}).done(function() {
$('.mw-changeslist-line-watched').removeClass('mw-changeslist-line-watched').addClass('mw-changeslist-line-not-watched');
});
}
});
});
});
});