User:Philoserf/common.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* subpages */
$.when(mw.loader.using(["mediawiki.util"]), $.ready).done(function () {
mw.util.addPortletLink(
"p-tb",
mw.util.getUrl("Special:PrefixIndex/") + mw.config.get("wgPageName") + "/",
"Subpages",
"pt-mysubpages",
"Show your subpages",
null,
"#pt-preferences"
);
});
/* watchlist */
mw.loader.using("mediawiki.util", function () {
var showNotice = function () {
// Stick a "Watchlist update!" notice after the notification count
$("#pt-notifications-notice").after(
$("<li>")
.append(
$("<a>")
.text("Watchlist update!")
.css({
"background-color": "green",
color: "white",
"border-radius": "2px",
padding: "0.25em 0.45em 0.2em",
cursor: "pointer",
"font-weight": "bold",
transition: "background-color 0.5s",
})
.attr("href", "/wiki/Special:Watchlist")
.mouseover(updateNotice)
)
.attr("id", "watchlist-update-notice")
);
};
var updateNotice = function () {
// Lighten the background color so the user knows we're updating
$("#watchlist-update-notice a").css("background-color", "#7bff7b");
// Update the notice
$.getJSON(mw.util.wikiScript("api"), {
format: "json",
action: "query",
list: "watchlist",
wlshow: "unread",
wllimit: 1, // Because we're checking if there are *any* entries
}).done(function (data) {
if (!data.query) return;
if (data.query.watchlist.length) {
// There are new watchlist diffs to read, so show notice
if (!$("#watchlist-update-notice").length) {
// That is, if it isn't shown already
showNotice();
} else {
// There's already a notice, so change background
$("#watchlist-update-notice a").css("background-color", "green");
}
} else {
// No new watchlist diffs to read, so hide notice
$("#watchlist-update-notice").remove();
}
});
};
$(document).ready(function () {
updateNotice();
window.setInterval(updateNotice, 120000);
});
});
/* short tab titles */
var t = document.title;
if (t.substring(0, 5) === "User:") document.title = "U:" + t.substring(5);
else {
var m = t.substring(0, 9);
if (m === "Category:") document.title = "CAT:" + t.substring(9);
else {
var e = t.substring(0, 10);
if (e === "Traveller:") document.title = "T:" + t.substring(10);
else if (e === "User talk:") document.title = "UT:" + t.substring(10);
else {
var n = t.substring(0, 14);
if (n === "Category talk:") document.title = "CAT-T:" + t.substring(14);
else {
var s = t.substring(0, 15);
if (s === "Traveller talk:") document.title = "TT:" + t.substring(15);
}
}
}
}