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. |
$(document).ready( function () {
if( mw.config.get('wgNamespaceNumber') != -1 || mw.config.get('wgCanonicalSpecialPageName') !== "Special:Watchlist" ) {
// only operate in Special: namespace, on Special:Watchlist
return;
}
//Add a form to open multiple unread pages
var openUnread_form = '<hr><div id="openUnread-input">'+
'<button id="openUnread-go">Open unread pages</button>'+
'(Options: <input type="text" name="openUnread-number" id="openUnread-number" style="width:2em;" value="10"/> 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>)';
$("fieldset").append(openUnread_form);
// 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").find("a.mw-changeslist-title").map(function() {
return $( this ).attr("href");
}).get();
//remove duplicates
var seen = {};
var unique_unread = [];
var len = unread.length;
var j = 0;
for (var i = 0; i < len; i++) {
var item = a[i];
if(seen[item] !== 1) {
seen[item] = 1;
unique_unread[j++] = item;
}
}
// reverse if order is oldest first
if ( $('#openUnread-order').prop('checked') ) {
unique_unread.reverse();
}
// 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");
}
});
});