Skip to content

Instantly share code, notes, and snippets.

@mashiro
Last active August 29, 2015 14:01
Show Gist options
  • Save mashiro/88c57d8eb141d6a74921 to your computer and use it in GitHub Desktop.
Save mashiro/88c57d8eb141d6a74921 to your computer and use it in GitHub Desktop.
function batch(f) {
var _altAlert = window.altAlert;
var _altConfirm = window.altConfirm;
var _refreshCarList = window.refreshCarList;
var _refreshTrainList = window.refreshTrainList;
window.altAlert = function() {};
window.altConfirm = function(m, f) { f(); };
window.refreshCarList = function() {};
window.refreshTrainList = function() {};
f();
window.altAlert = _altAlert;
window.altConfirm = _altConfirm;
window.refreshCarList = _refreshCarList;
window.refreshTrainList = _refreshTrainList;
window.refreshCarList();
window.refreshTrainList();
}
window._factory = window.factory;
window.factory = function(id) {
batch(function() {
var keys = [];
for (var i = 0; i < localStorage.length; ++i) {
keys.push(localStorage.key(i));
}
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
var data = window.readFromLocalStorage(key);
if (data.level == 1) {
window._factory(id);
window.carSelect(key);
console.log("" + id + " <= " + key);
}
}
});
};
function repeat(func, n) {
batch(function() {
for (var i = 0; i < n; ++i) {
func();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment