// ==UserScript==
// @name         Python & Pip invoke commands
// @version      1
// @grant        none
// @author       Corentin Bettiol
// @description  This extension just replaces `python3` by `python3` and `python3 -m pip` by `python3 -m pip`.
// @homepageURL  https://gist.github.com/corentinbettiol/9cb4543c96ec94137bd0adb0452f1c34
// @match        *://*/*
// @run-at       document-end
// ==/UserScript==

// Thx https://stackoverflow.com/a/24419809/6813732

var replaceArry = [
    [/(?<!_)python(?!3|_)/g, 'python3'],
    [/(?<!python3 -m |_)pip(?!_)/g, 'python3 -m pip'],
];
var numTerms    = replaceArry.length;
var txtWalker   = document.createTreeWalker (
    document.body,
    NodeFilter.SHOW_TEXT,
    {   acceptNode: function (node) {
            //-- Skip whitespace-only nodes
            if (node.nodeValue.trim() )
                return NodeFilter.FILTER_ACCEPT;

            return NodeFilter.FILTER_SKIP;
        }
    },
    false
);
var txtNode     = null;

while (txtNode  = txtWalker.nextNode () ) {
    var oldTxt  = txtNode.nodeValue;

    for (var J  = 0;  J < numTerms;  J++) {
        oldTxt  = oldTxt.replace (replaceArry[J][0], replaceArry[J][1]);
    }
    txtNode.nodeValue = oldTxt;
}