Skip to content

Instantly share code, notes, and snippets.

@marianfoo
Last active January 29, 2025 18:55
// ==UserScript==
// @name SAP ExtLogin override
// @namespace http://tampermonkey.net/
// @version 2025-01-04
// @description Override the vs code link with cursor://
// @match https://*.applicationstudio.cloud.sap/remote-login.html*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
const checkExtLogin = setInterval(() => {
console.log("Tampermonkey script is alive, checking window.extLogin...");
if (window.extLogin && typeof window.extLogin.startFlow === 'function') {
clearInterval(checkExtLogin);
console.log("Overriding extLogin.startFlow now...");
// Save original for reference
const originalStartFlow = window.extLogin.startFlow;
// Override
window.extLogin.startFlow = function(isvscode) {
return window.fetch("/login?e=http://127.0.0.1:55532/ext-login")
.then(response => this.extractJwt(response))
.then((jwt) => {
if (isvscode) {
// Replaced with cursor://
window.open(`cursor://SAPOSS.app-studio-toolkit/login?jwt=${jwt}`, "_self");
} else {
// same as original
return window.fetch("http://127.0.0.1:55532/ext-login", {
method: "post",
body: JSON.stringify({ jwt }),
headers: { "Content-Type": "application/json" }
}).then(reponseData => reponseData.json());
}
});
};
}
}, 500); // check every 500ms
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment