Content deleted Content added
MusikAnimal (talk | contribs) patch |
MusikAnimal (talk | contribs) load CSS with full URL so this can be used outside enwiki; per Special:Permalink/870580632#Code updates |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1:
// customWatchlists.js
// version 0.1.
$(function() {
$("head").append(
var addCwLinkListener = function() {
Line 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 23 ⟶ 24:
var generateListItem = function(data) {
var
var pageUrl = "/w/index.php?title="+mwName.getNamespacePrefix()+mwName.getMain().replace(/'/g, "%27"),
editDate = new Date(data.timestamp);
if(data.newlen) {
Line 105 ⟶ 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 115 ⟶ 118:
data = argName;
} else {
pageName = mw.config.get('wgPageName');
}
var customWatchlists = data ? JSON.parse(data.split("\n")[0]) : {};
Line 220 ⟶ 223:
api.postWithToken( "edit", {
action: "edit",
title: "User:"+mw.config.get('wgUserName')+"/watchlists",
summary: "updating [[User:MusikAnimal/customWatchlists|custom watchlists]]",
text: stringifiedCw
Line 250 ⟶ 253:
};
if(mw.config.get('wgRelevantPageName') === "Special:Watchlist") {
getCustomWatchlists().then(function(data) {
var customWatchlists = JSON.parse(data.split("\n")[0]);
Line 299 ⟶ 302:
});
addCwLinkListener();
} else if(mw.config.get('wgNamespaceNumber') >= 0) {
mw.util.addPortletLink(
'p-cactions',
Line 311 ⟶ 314:
});
}
}
|