User:Mike Dillon/Scripts/recentpages.js: Difference between revisions

Content deleted Content added
mNo edit summary
No edit summary
Line 2:
 
/* <pre><nowiki> */
 
var pageHistoryCookieName;
var pageHistoryCookieItemCount;
 
addOnloadHook(function () {
// Set defaults for variables
if (!pageHistoryCookieName) pageHistoryCookieName = "pageHistory";
if (!pageHistoryCookieItemCount) pageHistoryCookieItemCount = 10;
 
// Create portlet
with (easyDom) {
Line 17 ⟶ 24:
toolboxPortlet.parentNode.insertBefore(historyPortlet, toolboxPortlet);
 
// Extract previous history from cookie
/*
var historyhistoryItems = readCookie("recentpageHistory")[];
var historyCookie = readCookie(pageHistoryCookieName);
if (historyhistoryCookie) {
var cookieItems = historyCookie.split(",");
for (var n in cookieItems) {
historyItems.push(decodeURIComponent(cookieItems[i]));
}
/*}
 
// Build out the history list
with (easyDom) {
if (historyItems.length == 0) {
historyList.appendChild(li(em("No page history")));
} else {
for (var n in historyItems) {
var itemUrl = wgArticlePath.replace(/\$1/,
encodeURIComponent(historyItems[i]));
historyList.appendChild(li(
a({ href: itemUrl, title: historyItems[i] },
historyItems[i])));
}
*/ }
}
 
// Prepend the current page to the list, remove duplicates, and control item count
var currentPage = wgPageName.replace("_", " ");
historyItems.unshift(currentPage);
for (var n = 1; n < historyItems.length; n++) {
if (historyItems[n] == currentPage) {
historyItems.splice(n, 1);
}
}
while (historyItems.length > pageHistoryCookieItemCount) {
historyItems.pop();
}
 
// Write out the updated cookie
historyCookie = "";
for (var n in historyItems) {
if (n > 0) historyCookie += ",";
historyCookie += encodeURIComponent(historyItems[n]);
}
writeCookie(pageHistoryCookieName, historyCookie);
*/
});