"use strict";
-Array.prototype.firstWhere = function (callback, thisArg) {
- for (var i = 0; i < this.length; ++i)
- if (callback.call(thisArg, this[i]))
- return this[i];
-};
-
Array.prototype.contains = function (o) {
return this.indexOf(o) >= 0;
};
return os[Math.floor(os.length * Math.random())];
}
-function category (item) {
- return Object.keys(ACNL_WEARABLES).firstWhere(function (type) {
- return ACNL_WEARABLES[type].contains(item);
- });
-}
+var flatten1 = Array.prototype.concat.apply.bind(Array.prototype.concat, []);
-function notLewd (outfit) {
- var categories = outfit.map(category);
- return (categories.contains("wetsuits")
- || categories.contains("dresses")
- || categories.containsSubset(["tops", "bottoms"]));
+function get (attr) {
+ return this[attr];
}
-function buildArray (a, l) {
- return (a || []).concat(l);
+var category = get.bind(ACNL_WEARABLES_CATEGORY);
+var wearables = get.bind(ACNL_WEARABLES);
+
+function isLewd (outfit) {
+ return ![["wetsuits"], ["dresses"], ["tops", "bottoms"]].some(
+ Array.prototype.containsSubset, outfit.map(category));
}
-function impossibilities (categories) {
- return categories.map(function (c) { return BLOCKS[c]; }
- ).reduce(buildArray, []);
+function impossibilities (outfit) {
+ return flatten1(outfit.map(category).map(get, BLOCKS));
}
function possibilities (outfit) {
- return Object.keys(ACNL_WEARABLES
- ).filter(Array.prototype.lacks, impossibilities(outfit.map(category))
- ).map(function (k) { return ACNL_WEARABLES[k] }
- ).reduce(buildArray, []);
+ return Object.keys(ACNL_WEARABLES).filter(
+ Array.prototype.lacks, impossibilities(outfit));
}
-function isFinished(outfit) {
- return notLewd(outfit) && Math.random() > 0.5;
+function outfit () {
+ var ps = [];
+ while (isLewd(ps))
+ ps.push(choice(flatten1(possibilities(ps).map(wearables))));
+ return ps;
}
-function nextItem (outfit) {
- return !isFinished(outfit) && choice(possibilities(outfit));
+function isPosessive (item) {
+ return item[0].toUpperCase() === item[0] && item.indexOf("'s") >= 0;
}
-function outfit () {
- var ps = [];
- var next;
- while (next = nextItem(ps))
- ps.push(next);
- return ps;
+function isPlural (item) {
+ return item.substr(-8) === "headgear"
+ || (item.substr(-1) === "s"
+ && item.substr(-2) !== "ss"
+ && item.substr(-6) !== "cosmos"); // :(
}
function article (item) {
if (item[0].toUpperCase() === item[0] && item.indexOf("'s") >= 0)
return "";
- else if (item.substr(-1) === "s" && item.substr(-2) !== "ss"
- && item.substr(-6) !== "cosmos") // :(
+ else if (isPlural(item))
return "";
else if ("aeiouAEIO".indexOf(item[0]) >= 0
|| ("FHLMNRSX".indexOf(item[0]) >= 0
return names.join(names.length == 2 ? " " : ", ");
}
-function litanizeElement (eid, tid) {
+function updateTime () {
+ var date = new Date();
+ document.documentElement.className = "month" + date.getMonth()
+ document.body.className = "hour" + date.getHours();
+ if (window.navigator.standalone)
+ document.body.className += " standalone";
+}
+setInterval(updateTime, 20 * 60 * 1000);
+
+function update () {
var o = outfit();
- document.getElementById(eid).innerHTML = litanize(o, true) + "?";
+ var wearing = document.getElementById('wearing');
+ wearing.innerHTML = litanize(o, true) + "?";
// TODO: This often generates > 140 characters. Do I care?
// Maybe pick shorter prefixes if it would help.
- var t = document.getElementById(tid);
- t.href = t.href.replace(
+ var twitter = document.getElementById('twitter');
+ twitter.href = twitter.href.replace(
/&text=[^&]+/, "&text=" + encodeURIComponent(
choice(["Going out in ",
"Labelle suggested ",
"I'll wear "]) + litanize(o, false) + "."));
+
+ var buttons = document.getElementById("buttons");
+ buttons.className = "";
+ setTimeout(function () {
+ buttons.className = "open";
+ }, 300);
+ updateTime();
}
+
+window.addEventListener("DOMContentLoaded", update);
+
+window.addEventListener('load', function () {
+ if (typeof FastClick !== "undefined")
+ FastClick.attach(document.body, { tapDelay: 50 });
+
+ if (applicationCache && applicationCache.status) {
+ applicationCache.update();
+ applicationCache.addEventListener('updateready', function () {
+ if (applicationCache.status === applicationCache.UPDATEREADY) {
+ applicationCache.swapCache();
+ }
+ });
+ }
+});