Skip to content

Instantly share code, notes, and snippets.

@christopherthielen
Created February 4, 2021 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherthielen/3f954059ef0568f8e8f7d55cb1e2b811 to your computer and use it in GitHub Desktop.
Save christopherthielen/3f954059ef0568f8e8f7d55cb1e2b811 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Teamflow FPS tweak
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Adjust min/max FPS in Teamflow
// @author Chris Thielen
// @match https://app.teamflowhq.com/netflix*
// @grant none
// ==/UserScript==
(async function () {
"use strict";
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const waitUntilDefined = (callback, message) =>
Promise.resolve(callback()).then((value) => {
if (value !== undefined) return value;
console.log(`Waiting for ${message}`);
return wait(100).then(() => waitUntilDefined(callback, message));
});
const findJsonpCallback = () => {
const webpackJsonp = Object.keys(window).find((x) =>
x.startsWith("webpackJsonp")
);
if (webpackJsonp) {
console.log("Found webpack modules at " + webpackJsonp);
const jsonparray = window[webpackJsonp];
return jsonparray.push.bind(jsonparray);
}
};
// Returns promise that resolves to all installed modules
const getAllWebpackModules = (webpackJsonpCallback) =>
new Promise((resolve) => {
const id = "fakeModule_" + Math.random();
const fakeModule = {
[id]: function (module, exports, __webpack_require__) {
resolve(__webpack_require__.c);
}
};
webpackJsonpCallback([[], fakeModule, [[id]]]);
});
const webpackJsonpCallback = await waitUntilDefined(
() => findJsonpCallback(),
"webpackJsonpCallback"
);
const allModules = await waitUntilDefined(
() => getAllWebpackModules(webpackJsonpCallback),
"all modules"
);
window._webpackModules = allModules;
// find the pixi/ticker module
const tickerModule = await waitUntilDefined(() => {
return Object.values(allModules)
.map((x) => x.exports)
.find((x) => Object.keys(x || {}).some((y) => y.includes("Ticker")));
}, "ticker modules");
const sharedTicker = await waitUntilDefined(
() => tickerModule.Ticker._shared,
"shared ticker"
);
const netflixTitle = await waitUntilDefined(() => {
const paragraphs = [...document.querySelectorAll("p.chakra-text")];
return paragraphs.find((x) => x.innerText === "Netflix");
}, "Netflix title");
console.log("Max FPS set to 10");
sharedTicker.maxFPS = 10;
netflixTitle.innerHTML =
"Netflix<br><div>max fps: <input type=number value=10 id=fps></div>";
const fpsInput = document.getElementById("fps");
fpsInput.style.width = "100px";
fpsInput.style.border = "1px solid grey";
fpsInput.addEventListener('change', () => {
sharedTicker.maxFPS = fpsInput.value;
sharedTicker.minFPS = 1;
console.log(`Set maxFPS to ${fpsInput.value}`)
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment