Add support for triggering a refresh in SplatNet 3 by pressing Cmd+R/Ctrl+R

This commit is contained in:
Samuel Elliott 2022-09-10 15:45:44 +01:00
parent e3b967a412
commit b6099a7d18
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@ const debug = createDebug('app:preload-webservice');
import './znca-js-api.js';
import './quirks/splatnet2.js';
import './quirks/nooklink.js';
import './quirks/splatnet3.js';
const style = window.document.createElement('style');

View File

@ -0,0 +1,28 @@
import createDebug from 'debug';
import { events, webservice } from '../ipc.js';
const debug = createDebug('app:preload-webservice:quirks:splatnet3');
const SPLATNET3_WEBSERVICE_ID = 4834290508791808;
if (webservice.id === SPLATNET3_WEBSERVICE_ID) {
events.on('window:refresh', () => {
const pulltorefresh_container = document.querySelector<HTMLElement>('[class*=PullToRefresh_container]');
debug('PullToRefresh container HTMLElement', pulltorefresh_container);
if (!pulltorefresh_container) return location.reload();
const keys = Object.keys(pulltorefresh_container) as (keyof typeof pulltorefresh_container)[];
const react_fiber: any = pulltorefresh_container[keys.find(k => k.startsWith('__reactFiber$'))!];
debug('PullToRefresh container React fiber', react_fiber);
if (!react_fiber) return location.reload();
try {
const props = react_fiber.return.return.memoizedProps;
debug('PullToRefresh root props', props);
props.onRefresh.call(null);
} catch (err) {
debug('Error triggering refresh, forcing full page reload', err);
location.reload();
}
});
}