Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active August 15, 2018 04:54
Show Gist options
  • Save oshliaer/4af2eb6ebfc548a737ed13289fcdccb7 to your computer and use it in GitHub Desktop.
Save oshliaer/4af2eb6ebfc548a737ed13289fcdccb7 to your computer and use it in GitHub Desktop.
function updateMenu_(menu, items) {
var menuIterator = makeIterator_(items);
while (true) {
menu.addItem(menuIterator.get().name, menuIterator.get().fn);
if (menuIterator.next().done) break;
};
}
function getScriptFunctionsAsMenuItems_(context) {
return Object.keys(context).filter(function (key) { return key.slice(-1) !== "_" && key !== "onOpen" && typeof this[key] === "function" }, context).map(function (item) {
return { name: item, fn: item };
});
}
function L() {
Browser.msgBox("L");
}
function f1() {
Browser.msgBox("f1");
}
function makeIterator_(array) {
var nextIndex = 0;
return {
next: function () {
nextIndex++;
return nextIndex < array.length ?
{ value: array[nextIndex], done: false } :
{ done: true };
},
get: function () {
return nextIndex < array.length ? array[nextIndex] : undefined;
}
};
}
function onOpen() {
var self = this;
var menu = SpreadsheetApp.getUi().createMenu("All script functions");
updateMenu_(menu, getScriptFunctionsAsMenuItems_(self));
menu.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment