Created
July 16, 2025 22:10
-
-
Save crftr/fcfad612ff4e2d315dd66270f2e124ab to your computer and use it in GitHub Desktop.
A bookmarklet to remain logged-in to a SuiteCommerce Advanced site.
This file contains hidden or 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
| javascript: (function yo() { | |
| if (typeof SC === "undefined" || !SC.ENVIRONMENT) { | |
| alert("Error: Not in SCA environment. SC.ENVIRONMENT not found."); | |
| return; | |
| } | |
| /* if you must comment, DON't use // ... use multiblock instead (like this comment) */ | |
| var baseUrl = SC.ENVIRONMENT.baseUrl; | |
| var companyId = SC.ENVIRONMENT.companyId; | |
| var newTabUrl = SC.SESSION.touchpoints.customercenter; | |
| var pingTarget = 'services/SOME-SERVICE-THAT-USES-CUSTOMER-API.Service.ss'; /* *** REPLACE THIS *** */ | |
| var keepAliveUrl = | |
| baseUrl.replace('{{file}}', pingTarget) + `?c=${companyId}&n=2`; | |
| function createKeepAliveFunction(keepAliveUrlParam) { | |
| var intervalId; | |
| var pingCount = 0; | |
| var startTime = new Date().getTime(); | |
| var pingIntervalStr = '30 seconds'; | |
| var pingInterval = 30 * 1000; | |
| var timeLimitStr = '6 hours'; | |
| var timeLimit = 6 * (60 * 60 * 1000); | |
| function pingServer() { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open("GET", keepAliveUrlParam, true); | |
| xhr.onreadystatechange = function () { | |
| if (xhr.readyState === 4) { | |
| pingCount++; | |
| var elapsedTime = Math.floor( | |
| (new Date().getTime() - startTime) / 1000 | |
| ); | |
| console.log( | |
| "SCA KeepAlive: Ping #" + | |
| pingCount + | |
| " at " + | |
| elapsedTime + | |
| "s - Status: " + | |
| xhr.status | |
| ); | |
| window.document.title = `SCA KeepAlive #${pingCount}`; | |
| if (new Date().getTime() - startTime > timeLimit) { | |
| clearInterval(intervalId); | |
| window.document.title = 'SCA KeepAlive FIN!'; | |
| console.log(`SCA KeepAlive: Stopped after ${timeLimitStr}`); | |
| } | |
| } | |
| }; | |
| xhr.send(); | |
| } | |
| pingServer(); | |
| intervalId = setInterval(pingServer, pingInterval); | |
| console.log( | |
| "SCA KeepAlive: Started pinging " + | |
| keepAliveUrlParam + | |
| ` every ${pingIntervalStr} for ${timeLimitStr}` | |
| ); | |
| } | |
| /* Open new tab */ | |
| var newWindow = window.open(newTabUrl, "_blank"); | |
| if (newWindow) { | |
| newWindow.document.title = "SCA KeepAlive"; | |
| setTimeout(function () { | |
| try { | |
| newWindow.document.title = "SCA KeepAlive"; | |
| var keepAliveCode = | |
| "(" + | |
| createKeepAliveFunction.toString() + | |
| ')("' + | |
| keepAliveUrl + | |
| '");'; | |
| newWindow.eval(keepAliveCode); | |
| } catch (e) { | |
| console.error("SCA KeepAlive: Error setting up in new window:", e); | |
| /* Fallback: run in current window */ | |
| createKeepAliveFunction(keepAliveUrl); | |
| } | |
| }, 2000); | |
| } else { | |
| /* Fallback if popup was blocked */ | |
| alert("Popup blocked. Running SCA KeepAlive in current window."); | |
| createKeepAliveFunction(keepAliveUrl); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment