Skip to content

Instantly share code, notes, and snippets.

@id-ilych
Last active July 8, 2025 18:22
Show Gist options
  • Select an option

  • Save id-ilych/a06253d3968e56992e630eb401ff9ae6 to your computer and use it in GitHub Desktop.

Select an option

Save id-ilych/a06253d3968e56992e630eb401ff9ae6 to your computer and use it in GitHub Desktop.
GDInvoker
sdk = function initSDK() {
// this particular action name is only used to detect actions registry
// and then guess the exec method name (for logs only, actual detection is performed on every execution)
var sampleActionName = "docs-bold"
function findRegistries(obj, depth, keyPrefix) {
if (depth <= 0) return;
var keys = []
var result = []
for ([k, v] of Object.entries(obj)) {
if (v && typeof v === "object" && sampleActionName in v) {
keys.push(keyPrefix + k)
result.push(v)
}
}
if (result.length > 0) {
console.log("[SDK] found actions registries: " + keys.join(", "))
return result
}
for ([k, v] of Object.entries(obj)) {
if (!v) continue
var r = findRegistries(v, depth-1, keyPrefix + k + ".")
if (r) return r;
}
}
function detectExecMethodName(action) {
// it seems that exec method is the only one with 3 arguments
var result = []
for ([k, v] of Object.entries(Object.getPrototypeOf(action))) {
if (v.length === 3) {
result.push(k)
}
}
if (result.length > 1) {
console.error("[SDK] multiple exec method candidates: " + result.join(", "))
return
}
if (result.length === 0) {
var methods = Object.keys(Object.getPrototypeOf(action))
console.error("[SDK] failed to detect exec method among methods: " + methods.join(", "))
return
}
return result[0]
}
var registries = findRegistries(KX_kixApp, 2, "KX_kixApp.")
function findAction(name) {
for (var r of registries) {
var a = r[name]
if (a) return a
}
console.error("[SDK] action not found: " + name)
}
var sampleAction = findAction(sampleActionName)
if (sampleAction) {
var sampleExecMethodName = detectExecMethodName(sampleAction)
if (sampleExecMethodName) {
console.log("[SDK] action exec method name: " + sampleExecMethodName)
}
}
var actions = new Set()
for (var r of registries) {
for (var k of Object.keys(r)) {
actions.add(k)
}
}
return {
actions: [...actions].sort(),
exec: function(actionName) {
var action = findAction(actionName)
if (action) {
var method = detectExecMethodName(action)
if (method) {
action[[method]]()
}
}
}
}
}()
// now you can exec actions (the list of actions available as sdk.action)
sdk.exec('docs-bold')
sdk.exec('docs-underline')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment