Back to Repository

JKO BOT

0 upvotes
By joshuachristian2271@gmail.com
Manual (context menu)

Match Pattern

<all_urls>

Script Code

(function markComplete() {
  function findAPI(win) {
    var attempts = 0;
    while (win && attempts < 10) {
      if (win.API_1484_11) return { api: win.API_1484_11, version: "2004" };
      if (win.API) return { api: win.API, version: "1.2" };
      if (win.parent && win.parent !== win) win = win.parent;
      else if (win.opener && win.opener !== win) win = win.opener;
      else break;
      attempts++;
    }
    return null;
  }

  var found = findAPI(window);
  if (!found) {
    console.warn("SCORM API not found");
    return;
  }

  var api = found.api;

  function set(key, value) {
    try {
      var result = api.SetValue(key, String(value));
      if (String(result) === "false" && api.GetLastError) {
        var err = api.GetLastError();
        console.warn("SetValue failed", key, err, api.GetErrorString && api.GetErrorString(err));
      }
    } catch (e) {
      console.warn("SetValue threw", key, e);
    }
  }

  if (found.version === "2004") {
    set("cmi.completion_status", "completed");
    // set("cmi.success_status", "passed");
  } else {
    set("cmi.core.lesson_status", "completed");
    // set("cmi.core.lesson_status", "passed");
  }

  try {
    if (api.Commit) api.Commit("");
  } catch (e) {
    console.warn("Commit failed", e);
  }

  try {
    var frames = document.getElementsByName("courseheader");
    var header = frames && frames[0];
    var doc = header && (header.contentDocument || (header.contentWindow && header.contentWindow.document));
    var form = doc && doc.getElementById("c");
    if (form && typeof form.submit === "function") form.submit();
  } catch (e) {}
})();
Install requires the InjectJS Chrome extension. Scripts run only on sites matching the pattern above. Review code before installing any community script.