From 2afd81600e17f5e56c6d22e879502f7ef0163c3a Mon Sep 17 00:00:00 2001 From: Christopher Puschmann Date: Mon, 9 Aug 2021 16:53:03 +0000 Subject: [PATCH] Add `Steam - Disable Auto Away` script --- Steam - Disable Auto Away.user.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Steam - Disable Auto Away.user.js diff --git a/Steam - Disable Auto Away.user.js b/Steam - Disable Auto Away.user.js new file mode 100644 index 0000000..d5bbcb3 --- /dev/null +++ b/Steam - Disable Auto Away.user.js @@ -0,0 +1,32 @@ +// ==UserScript== +// @name Steam - Disable automatic 'Away' +// @namespace steam +// @description Suppresses function to automatically set user as Away in Steam browser chat +// @include http://steamcommunity.com/* +// @include https://steamcommunity.com/* +// @version 1.0 +// @grant unsafeWindow +// @run-at document-start +// ==/UserScript== + +function inject() { + // Override method which calculates the idle time using `eval` + // We've to use eval, since we cannot create new functions in the original window. This would + // cause scripts to crash, since they have no access to functions from other windows. + unsafeWindow.eval(`window.g_FriendsUIApp.m_IdleTracker.__proto__.GetUserIdleTime = () => 1;`); + + unsafeWindow.console.clear(); + unsafeWindow.console.log('%c Code injected! ', 'background: green; color: white'); +} + +// A normal event listener wouldn't do the job here, since the Steam Chat uses a combination +// of React and jQuery to dynamically fetch content in the virtual DOM. So we've to do this +// terribleness ... +function ready() { + if (unsafeWindow.g_FriendsUIApp !== undefined && unsafeWindow.g_FriendsUIApp.m_bReadyToRender) { + inject(); + return; + } + setTimeout(ready, 1000); +} +ready(); \ No newline at end of file