User:Danski454/unwatch.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:Danski454/unwatch. |
/*
* Based off Unwatch from watchlist
* @source https://www.mediawiki.org/wiki/Snippets/Unwatch_from_watchlist
* @author Krinkle
* @revision 2016-09-01
*/
$(document).ready(function(){
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Watchlist' || location.href.indexOf( '/edit' ) > 0 || location.href.indexOf( '/raw' ) > 0 ) {
return;
}
mw.hook( 'wikipage.content' ).add(function(){
$(".mw-changeslist-line-inner").each(function(){
var line = $(this);
if (line.find(".unwatch-link").length) {
return;//do not add infinite links
}
if (typeof unwatchAJAX !== "undefined" && unwatchAJAX) {// add window.unwatchAJAX = true; to appropriate code file to enable AJAX links
line.append(' <span class="unwatch-link">[<a href="#UNWATCH_PAGE" role="button">unwatch</a>]</span>');//add fake link
line.find(".unwatch-link a").click(function(){
var page = $(this).parent().parent().attr('data-target-page');//get page name
var api = new mw.Api();
api.unwatch(page).done(function(watch){//unwatch it
$('.mw-changeslist-line-inner[data-target-page="' + watch.title + '"] .unwatch-link').html("[<b>unwatched</b>]");//say page has been unwatched
//do the same for associated page
var titleObj = new mw.Title(watch.title);
if (titleObj.isTalkPage()) {
//console.log(titleObj.getSubjectPage().toText());
$('.mw-changeslist-line-inner[data-target-page="' + titleObj.getSubjectPage().toText() + '"] .unwatch-link')
.html("[<b>unwatched</b>]");//say assosciated page has been unwatched
} else if (titleObj.getTalkPage()) {//make sure it is not null
//console.log(titleObj.getTalkPage().toText());
$('.mw-changeslist-line-inner[data-target-page="' + titleObj.getTalkPage().toText() + '"] .unwatch-link')
.html("[<b>unwatched</b>]");//say assosciated page has been unwatched
}
});
});
} else {
var href = line.find(".mw-changeslist-history").attr("href");
if (href) {
href = href .replace("action=history", "action=unwatch");
line.append(' <span class="unwatch-link">[<a href="' + href + '">unwatch</a>]</span>');
}
}
});
});
});