MediaWiki:Common.js
From Tinkla: Tinkering with Tesla
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
var bb_openpilot_container = document.getElementById("bb_openpilot.cfg");
if (bb_openpilot_container)
loadCfg(bb_openpilot_container);
function loadCfg(bb_openpilot_container) {
var request = new XMLHttpRequest();
var url = "https://raw.githubusercontent.com/BogGyver/openpilot/tesla_devel/selfdrive/car/tesla/readconfig.py";
request.open('GET', url, true);
request.send(null);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
bb_openpilot_container.innerText = parseCfg(request.responseText);
} else {
bb_openpilot_container.innerText = "Error loading " + url;
}
}
}
}
function parseCfg(code) {
var cfgEntryPattern = /self\.read_config_entry\(([\s\S]*?)\r?\n?\s*?\)\r?\n\s*?file_changed/g;
var paramSeparatorPattern = /\s*\r?\n?\s*,\s*\r?\n?\s*/;
var cfg = "";
var m;
while (m = cfgEntryPattern.exec(code)) {
var cfgParams = m[1].split(paramSeparatorPattern);
var key = extractParamInfo(cfgParams[4]);
var defaultValue = extractParamInfo(cfgParams[6]);
var comment = extractParamInfo(cfgParams.splice(7, cfgParams.length).join(", "));
cfg += "# " + comment + "\n" + key + " = " + defaultValue + "\n\n";
}
return cfg;
}
function extractParamInfo(rawParam) {
var paramCleanupPattern = /(?:.*?=)?\s*?(.*?)\s*/;
rawParam = rawParam.replace(/(["''])(.*)\1/, "$2"); // strip surrounding single or double quotes
rawParam = rawParam.replace(/\\(['"])/, "$1") // unescape escaped quotes
rawParam = rawParam.replace(paramCleanupPattern, "$1");
return rawParam;
}