MediaWiki:Monobook.js
Jump to navigation
Jump to search
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 users using the MonoBook skin */ // Comments are important. function main() { // Do the thing. $('div#mw-content-text pre').map(transform); } function transform(i, node) { // Do the things to each thing. var txt = node.innerHTML; node.innerHTML = $.map(txt.split(/\r?\n/), transform_line).join('\n'); } var assembly_line = /^([0-9A-Fa-f]{8}: [0-9A-Fa-f]{8} )(\w+)(\s.*)?$/; function transform_line(s) { var match = assembly_line.exec(s); if (match == null) { //no asm detected return s; } var prefix = match[1]; var opname = match[2]; var suffix = match[3]? match[3]: ''; var link = $("<a></a>", { href: "/wiki/R3000_instruction_set#" + opname, title: desc[opname], }).text(opname); if (opname == 'jal') { suffix = transform_call(suffix) } console.log(prefix, opname, suffix, link); return prefix + link[0].outerHTML + suffix; } var transform_call_re = /^( (?:0x ?)?)(\w{8})(.*)$/; function transform_call(s) { var match = transform_call_re.exec(s); if (match == null) { return s; } var prefix = match[1]; var addr = match[2]; var suffix = match[3]; var fname = known_functions[addr] || addr; var link = $("<a></a>", { href: "/wiki/" + fname.replace(' ', '_'), title: fname, }).text(addr); return prefix + link[0].outerHTML + suffix; } var desc = { 'add': "Add: add $d,$s,$t", 'addu': "Add unsigned: addu $d,$s,$t", 'sub': "Subtract: sub $d,$s,$t", 'subu': "Subtract unsigned: subu $d,$s,$t", 'addi': "Add immediate: addi $t,$s,C", 'addiu': "Add immediate unsigned: addiu $t,$s,C", 'mult': "Multiply: mult $s,$t", 'multu': "Multiply unsigned: multu $s,$t", 'div': "Divide: div $s, $t", 'divu': "Divide unsigned: divu $s, $t", 'lw': "Load word: lw $t,C($s)", 'lh': "Load halfword: lh $t,C($s)", 'lhu': "Load halfword unsigned: lhu $t,C($s)", 'lb': "Load byte: lb $t,C($s)", 'lbu': "Load byte unsigned: lbu $t,C($s)", 'sw': "Store word: sw $t,C($s)", 'sh': "Store half: sh $t,C($s)", 'sb': "Store byte: sb $t,C($s)", 'lui': "Load upper immediate: lui $t,C", 'mfhi': "Move from high: mfhi $d", 'mflo': "Move from low: mflo $d", 'mfcZ': "Move from Control Register: mfcZ $t, $d", 'mtcZ': "Move to Control Register: mtcZ $t, $d", 'and': "And: and $d,$s,$t", 'andi': "And immediate: andi $t,$s,C", 'or': "Or: or $d,$s,$t", 'ori': "Or immediate: ori $t,$s,C", 'xor': "Exclusive or: xor $d,$s,$t", 'nor': "Nor: nor $d,$s,$t", 'slt': "Set on less than: slt $d,$s,$t", 'slti': "Set on less than immediate: slti $t,$s,C", 'sll': "Shift left logical immediate: sll $d,$t,shamt", 'srl': "Shift right logical immediate: srl $d,$t,shamt", 'sra': "Shift right arithmetic immediate: sra $d,$t,shamt", 'sllv': "Shift left logical: sllv $d,$t,$s", 'srlv': "Shift right logical: srlv $d,$t,$s", 'srav': "Shift right arithmetic: srav $d,$t,$s", 'beq': "Branch on equal: beq $s,$t,C", 'bne': "Branch on not equal: bne $s,$t,C", 'j': "Jump: j C", 'jr': "Jump register: jr $s", 'jal': "Jump and link: jal C", 'nop': "No operation (do nothing)", }; var known_functions = {} main();