User:Evad37/Watchlist-openUnread.js
Appearance
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:Evad37/Watchlist-openUnread. |
/* Add any or all of these lines after the importScript line to set various options (the default values are shown):
var openUnread_maxnum = "10"; // Preset value for max number of pages
var openUnread_oldest = false; // Preset state of checkbox "oldest first". Set to true for checked, or false for unchecked
var openUnread_diff = false; // Preset state of checkbox "show diffs". Set to true for checked, or false for unchecked
*/
$(document).ready( function () {
if( mw.config.get('wgNamespaceNumber') != -1 ) {
// only operate in Special: namespace, on Special:Watchlist
return;
}
// Set default options for any that haven't been set
if ( window[openUnread_maxnum] === undefined ) { window[openUnread_maxnum] = "10"; }
if ( window[openUnread_oldest] === undefined ) { window[openUnread_oldest] = false; }
if ( window[openUnread_diff] === undefined ) { window[openUnread_diff] = false; }
//Add a form to open multiple unread pages
var openUnread_form = '<div id="openUnread-input" style="margin:5px 0;">'+
'<button id="openUnread-go">Open unread pages</button> '+
'(Options: <input type="text" name="openUnread-number" id="openUnread-number" style="width:2em;" value=' + openUnread_maxnum + ' /> pages max / '+
'<span class="mw-input-with-label"><input name="openUnread-order" id="openUnread-order" type="checkbox"> <label for="openUnread-order">oldest first</label></span> / '+
'<span class="mw-input-with-label"><input name="openUnread-diff" id="openUnread-diff" type="checkbox"> <label for="openUnread-diff">show diffs</label></span>)'+
'</div><hr>';
$("form#mw-watchlist-form").after(openUnread_form);
$("fieldset#mw-watchlist-options").css("margin-bottom", "0");
if (openUnread_oldest) {
$("#openUnread-order").prop( "checked", "true" );
}
if (openUnread_diff) {
$("#openUnread-diff").prop( "checked", "true" );
}
// Button clicked
$("#openUnread-go").click(function() {
// get form options
var maxnum = parseInt( $('#openUnread-number').val() );
if (isNaN(maxnum) || maxnum < 1) {
return; // error - zero, negative, or not a number
}
// get unread title links as array
var unread = $("li.mw-changeslist-line-watched, table.mw-changeslist-line-watched").find("a.mw-changeslist-title").map(function() {
return $( this ).attr("href");
}).get();
// reverse if order is oldest first
if ( $('#openUnread-order').prop('checked') ) {
unread.reverse();
}
//do we show diffs?
var urlquery;
if ( $('#openUnread-diff').prop('checked') ) {
urlquery = "?diff=cur&oldif=prev";
} else {
urlquery = "";
}
//remove duplicates
var seen = {};
var unique_unread = [];
var len = unread.length;
var j = 0;
for (var i = 0; i < len; i++) {
var item = unread[i];
if(seen[item] !== 1) {
seen[item] = 1;
unique_unread[j++] = item + urlquery;
}
}
// number of links to open
if (unique_unread.length < maxnum) {
maxnum = unique_unread.length;
}
// open links in new tabs/windows
for (var ii=0; ii < maxnum; ii++) {
window.open(unique_unread[ii], "_blank");
}
});
});