Add Steam - Disable Auto Away script

This commit is contained in:
Christopher Puschmann 2021-08-09 16:53:03 +00:00
parent 6fd0816be5
commit 2afd81600e

View File

@ -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();