User:MusikAnimal/customWatchlists.js: Difference between revisions

Content deleted Content added
No edit summary
load CSS with full URL so this can be used outside enwiki; per Special:Permalink/870580632#Code updates
 
(10 intermediate revisions by the same user not shown)
Line 1:
// customWatchlists.js
(function() {
// version 0.1.3
$("head").append(importStylesheet("User:MusikAnimal/customWatchlists.css"));
$(function() {
$("head").append(mw.loader.load( 'https://en.wikipedia.org/w/index.php?title=User:MusikAnimal/customWatchlists.css&action=raw&ctype=text/css', 'text/css' ));
var addCwLinkListener = function() {
Line 12 ⟶ 14:
var getCustomWatchlists = function() {
return Promise.resolve($.get("/wiki/User:"+mw.config.get('wgUserName')+"/watchlists?action=raw"));
};
var formatDate = function(dateObj) {
// TODO: replace monthNames with wgMonthNames
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
return (dateObj.getHours()+100).toString().slice(-2)+":"+(dateObj.getMinutes()+100).toString().slice(-2)+", "+(dateObj.getUTCDate()+100).toString().slice(-2)+" "+monthNames[dateObj.getUTCMonth()]+" "+dateObj.getUTCFullYear();
Line 21 ⟶ 24:
var generateListItem = function(data) {
var pageUrlmwName = "/w/indexnew mw.php?title="+Title(data.title,);
var pageUrl = "/w/index.php?title="+mwName.getNamespacePrefix()+mwName.getMain().replace(/'/g, "%27"),
editDate = new Date(data.timestamp);
if(data.newlen) {
Line 68 ⟶ 72:
$(".mw-changeslist").html(newHtml);
addCwLinkListener();
mw.hook( 'wikipage.content' ).fire($('.mw-changeslist'));
});
} else {
Line 96 ⟶ 101:
$(".mw-changeslist").html(newHtml);
addCwLinkListener();
mw.hook( 'wikipage.content' ).fire($('.mw-changeslist'));
});
}
Line 101 ⟶ 107:
var showCustomWatchlistsForm = function(appendHtml) {
console.log("testing");
var html = "<form id='custom_watchlist_form'><fieldset>" +
"<legend>Custom watchlists (<a href='//en.wikipedia.org/w/index.php?title=User:MusikAnimal/customWatchlists'>documentation</a>)</legend>" + appendHtml;
Line 111 ⟶ 118:
data = argName;
} else {
pageName = mw.config.get('wgPageName');
}
var customWatchlists = data ? JSON.parse(data.split("\n")[0]) : {};
Line 118 ⟶ 125:
for(var wl in customWatchlists) {
if(customWatchlists[wl].indexOf(pageName.replace("_talk:",":").replace("Talk:",":")) !== -1) {
inWatchlists.push(wl);
}
Line 215 ⟶ 223:
api.postWithToken( "edit", {
action: "edit",
title: "User:"+mw.config.get('wgUserName')+"/watchlists",
summary: "updating [[User:MusikAnimal/customWatchlists|custom watchlists]]",
text: stringifiedCw
Line 245 ⟶ 253:
};
if(mw.config.get('wgRelevantPageName') === "Special:Watchlist") {
getCustomWatchlists().then(function(data) {
var customWatchlists = JSON.parse(data.split("\n")[0]);
Line 294 ⟶ 302:
});
addCwLinkListener();
} else if(mw.config.get('wgNamespaceNumber') >= 0) {
mw.util.addPortletLink(
'p-cactions',
Line 303 ⟶ 311:
$("#ca-add-to-cw").click(function() {
if($("#cw-overlay")[0]) return false;
getCustomWatchlists().then(setupCactionInterface,setupCactionInterface.bind(this, null, null));
});
}
}());