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.innerHTML = parseCfg(request.responseText);
} else {
bb_openpilot_container.innerText = "Error loading " + url;
}
}
}
}
// Tables with class=zebra
$(document).ready(function() {
// the "className" includes all the classes so we must use re;
// CSS is case-sensitive anyway, so there is no point ignoring case:
var re = /\bzebra\b/,
t = document.getElementsByTagName("TABLE"),
n = t.length,
r, nr;
for (var i=0; i<n; i++) {
if ( re.test(t[i].className)) {
r = t[i].getElementsByTagName("TR");
nr = r.length;
for (var j=1; j < nr; j+=2) {
if (r[j].className) { r[j].className += " stripe";}
else r[j].className = "stripe";
}
}
}
});
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 += '<span class="c1"># ' + comment + "</span>\n" + key + " = " + defaultValue + "\n\n";
}
return cfg;
}
function extractParamInfo(rawParam) {
rawParam = rawParam.replace(/(?:.*?=)?\s*?(.*?)\s*/, "$1"); // strip param variable name if present
rawParam = rawParam.replace(/(["''])(.*)\1/, "$2"); // strip surrounding single or double quotes
rawParam = rawParam.replace(/\\(['"])/, "$1") // unescape escaped quotes
return rawParam;
}