Last active
October 25, 2018 15:07
-
-
Save kou1okada/c964ea53b93315d3c5fac8ebaf63dafe to your computer and use it in GitHub Desktop.
Moodle hacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get route of current page. | |
* \return Hash object which has keys (module, controller and any optionals) and values. | |
* module is like "course", "assign", "data", etc... | |
* controller is like "view", "modedit", "edit", etc... | |
* optionals are like "add", "course", "section", "mode", etc... | |
*/ | |
function getroute() { | |
let route = {}; | |
if (location.href.match(/\/([^/]+)\/([^/]+)\.php(\?(.*))/)) { | |
route = {module: RegExp.$1, controller: RegExp.$2}; | |
RegExp.$4.split("&").forEach(m=>{ | |
m = m.split("="); | |
route[m[0]] = decodeURIComponent(m[1]); | |
}); | |
} | |
return route; | |
} | |
/** | |
* Get fields at "edit" controller on "data" module. | |
* \return Hash object which has keys (field names) and values (HTML elements). | |
*/ | |
function data_edit_getfields() { | |
return [].reduce.call(document.querySelectorAll('[for]'), (r, e) => (r[e.textContent] = document.querySelector("#"+e.getAttribute("for")), r),{}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment