This extension just replaces python
by python3
and pip
by python3 -m pip
.
Last active
April 20, 2023 11:33
-
-
Save corentinbettiol/9cb4543c96ec94137bd0adb0452f1c34 to your computer and use it in GitHub Desktop.
Python & Pip invoke commands as a *monkey extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment