Misplaced Pages

User:NQ/WatchlistResetConfirm.js

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:NQ

This is an old revision of this page, as edited by NQ (talk | contribs) at 09:20, 1 November 2016 (convert to OOjs-UI thanks to the excellent mediawiki documentation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 09:20, 1 November 2016 by NQ (talk | contribs) (convert to OOjs-UI thanks to the excellent mediawiki documentation)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Misplaced Pages:Bypass your cache.
//Adds a confirmation dialogue to the Watchlist Reset button
//https://en.wikipedia.org/search/?title=Misplaced Pages:Village_pump_(technical)&oldid=746997333#Watchlist:_.22Are_you_sure_you_want_to_mark_all_pages_as_visited.3F.22

 /* ############################################################################
$(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.loader.using(, 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();

  $watchlistReset.submit(function(event) {
    event.preventDefault();

    windowManager.openWindow(messageDialog, {
      title: 'Confirm',
      message: 'Mark all pages as visited?',
      actions:  },
               { action: 'reset', label: 'Confirm', flags: }]
    }).then(function(opened) {
      opened.then(function(closing, data) {
        if (data && data.action === 'reset') {
        	
/* Uses ] to reset the watchlist without refreshing the page */
             
          // Code adapted from ]
          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');
          });
          
        } 
      });
    });
  });
});