diff --git a/Dotnet/AppApi/AppApiVr.cs b/Dotnet/AppApi/AppApiVr.cs index 1a04a27e..b17b88b2 100644 --- a/Dotnet/AppApi/AppApiVr.cs +++ b/Dotnet/AppApi/AppApiVr.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Globalization; +using System.IO; using CefSharp; namespace VRCX @@ -70,5 +71,18 @@ public string CurrentCulture() { return CultureInfo.CurrentCulture.ToString(); } + + /// + /// Returns the file path of the custom user js file, if it exists. + /// + /// The file path of the custom user js file, or an empty string if it doesn't exist. + public string CustomVrScriptPath() + { + var output = string.Empty; + var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VRCX\\customvr.js"); + if (File.Exists(filePath)) + output = filePath; + return output; + } } } \ No newline at end of file diff --git a/html/src/vr.js b/html/src/vr.js index 174711a6..8a0804ef 100644 --- a/html/src/vr.js +++ b/html/src/vr.js @@ -197,6 +197,7 @@ Vue.component('marquee-text', MarqueeText); currentTime: new Date().toJSON(), cpuUsage: 0, pcUptime: '', + customInfo: '', config: {}, onlineFriendCount: 0, nowPlaying: { @@ -230,6 +231,7 @@ Vue.component('marquee-text', MarqueeText); mounted() { workerTimers.setTimeout(() => AppApiVr.VrInit(), 1000); if (this.appType === '1') { + this.refreshCustomScript(); this.updateStatsLoop(); } } @@ -403,6 +405,21 @@ Vue.component('marquee-text', MarqueeText); } }; + $app.methods.refreshCustomScript = function () { + if (document.contains(document.getElementById('vr-custom-script'))) { + document.getElementById('vr-custom-script').remove(); + } + AppApiVr.CustomVrScriptPath().then((customScript) => { + var head = document.head; + if (customScript) { + var $vrCustomScript = document.createElement('script'); + $vrCustomScript.setAttribute('id', 'vr-custom-script'); + $vrCustomScript.src = `file://${customScript}?_=${Date.now()}`; + head.appendChild($vrCustomScript); + } + }); + }; + $app.methods.updateStatsLoop = async function () { try { this.currentTime = new Date() diff --git a/html/src/vr.pug b/html/src/vr.pug index 89f74f48..45cb4e90 100644 --- a/html/src/vr.pug +++ b/html/src/vr.pug @@ -523,7 +523,7 @@ html br span(style="float:right") {{ currentTime }} span(v-if="config && !config.hideCpuUsageFromFeed" style="display:inline-block;margin-right:5px") {{ $t('vr.status.cpu') }} {{ cpuUsage }}% - span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }} + span(style="display:inline-block") {{ $t('vr.status.online') }} {{ onlineFriendCount }} ‎{{ customInfo }} template(v-else) svg(class="np-progress-circle") circle(class="np-progress-circle-stroke" cx="60" cy="60" stroke="white" r="30" fill="transparent" stroke-width="60")