Line 25: |
Line 25: |
| | | |
| ==Script== | | ==Script== |
− | This tiny script generates the template call when run from the parent page. | + | This script generates the template call when run from the parent page. |
| <source lang="javascript"> | | <source lang="javascript"> |
− | var entries = $("#mod-list .mod:not([data-beta-status='abandoned'], [data-beta-status='obsolete'])");
| + | (function() { |
− | var ok = entries.filter("[data-beta-status='ok'], [data-beta-status='optional']").length;
| + | // group mods by status |
− | var workaround = entries.filter("[data-beta-status='workaround'], [data-beta-status='unofficial']").length;
| + | let counts = { ok: 0, workaround: 0, soon: 0, broken: 0, total: 0 }; |
− | var soon = entries.filter("[data-beta-status='broken'][data-github], [data-beta-status='broken'][data-custom-source]").length;
| + | let invalidMods = []; |
− | var broken = entries.filter("[data-beta-status='broken']:not([data-github], [data-custom-source])").length;
| + | $("#mod-list .mod").each(function(i, entry) { |
− | var total = ok + workaround + soon + broken;
| + | entry = $(entry); |
| + | let status = entry.attr("data-beta-status") || entry.attr("data-status"); |
| + | let hasSource = entry.is("[data-github], [data-custom-source]"); |
| + | |
| + | switch(status) { |
| + | // ignore obsolete mods |
| + | case "abandoned": |
| + | case "obsolete": |
| + | break; |
| | | |
− | if (total != entries.length) {
| + | // compatible |
− | var unknown = entries.filter(":not([data-beta-status='ok'], [data-beta-status='optional'], [data-beta-status='workaround'], [data-beta-status='unofficial'], [data-beta-status='obsolete'], [data-beta-status='broken'], [data-beta-status='abandoned'])");
| + | case "ok": |
− | console.log("found entries with unknown status:", unknown);
| + | case "optional": |
− | throw 'script failed';
| + | counts.ok++; |
− | }
| + | counts.total++; |
| + | break; |
| | | |
− | ` | + | // workaround |
− | {{/barchart | + | case "workaround": |
− | |ok = ${ok}
| + | case "unofficial": |
− | |workaround = ${workaround}
| + | counts.workaround++; |
− | |soon = ${soon}
| + | counts.total++; |
− | |broken = ${broken}
| + | break; |
− | |total = ${total}
| + | |
− | }} | + | // soon/broken |
− | ` | + | case "broken": |
| + | if (hasSource) |
| + | counts.soon++; |
| + | else |
| + | counts.broken++; |
| + | counts.total++; |
| + | break; |
| + | |
| + | default: |
| + | invalidMods.push(mods); |
| + | break; |
| + | } |
| + | }); |
| + | |
| + | // show results |
| + | if (invalidMods.length) { |
| + | console.log("found entries with unknown status:", invalidMods); |
| + | throw 'script failed'; |
| + | } |
| + | |
| + | console.log(` |
| + | {{/barchart |
| + | |ok = ${counts.ok} |
| + | |workaround = ${counts.workaround} |
| + | |soon = ${counts.soon} |
| + | |broken = ${counts.broken} |
| + | |total = ${counts.total} |
| + | }} |
| + | `.replace(/^ /mg, '')); |
| + | })(); |
| </source> | | </source> |
| | | |
| [[Category:Modding]]</noinclude> | | [[Category:Modding]]</noinclude> |