Skip to content

Commit

Permalink
updates for youtube, small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aminomancer committed Jun 24, 2021
1 parent d3b5e6c commit a8b14a0
Show file tree
Hide file tree
Showing 7 changed files with 465 additions and 657 deletions.
50 changes: 25 additions & 25 deletions WNPCListener.uc.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
// ==UserScript==
// @name WebNowPlaying Companion Listener
// @version 1.1
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Listen for updates from the WebNowPlaying Companion Addon, and set background timeout prefs based on whether a video is currently playing or not. If a video is playing, the min timeout values are minimized so that status updates will be sent from the addon to rainmeter as quickly as possible. This way there isn't a lag in the rainmeter skin's pause status after pausing a video. If a video is not playing, min timeout values are increased to conserve computational resources and reduce power consumption.
// ==/UserScript==

(() => {
function wInit() {
const options = {
attributes: true,
attributeFilter: ["label"],
},
observer = new MutationObserver(prefToggle);
var node = CustomizableUI.getWidget("wnpc_aminomancer-browser-action").forWindow(window)
.node;
const prefs = [
"dom.min_background_timeout_value",
"dom.min_background_timeout_value_without_budget_throttling",
];

function wInit() {
function xpSet(int) {
Services.prefs.setIntPref("dom.min_background_timeout_value", int),
Services.prefs.setIntPref(
"dom.min_background_timeout_value_without_budget_throttling",
int
);
prefs.forEach((pref) => Services.prefs.setIntPref(pref, int));
}

function xpGet() {
return Services.prefs.getIntPref("dom.min_background_timeout_value");
}

function prefToggle(mutationsList) {
for (let mutation of mutationsList) {
mutation.target.label === "Connected to media"
xpSet(2000);
new MutationObserver((mus) => {
for (let mu of mus)
mu.target.label === "Connected to media"
? xpGet() == 50 || xpSet(50)
: xpGet() == 2000 || xpSet(2000);
}).observe(
CustomizableUI.getWidget("wnpc_aminomancer-browser-action").forWindow(window).node,
{
attributeFilter: ["label"],
}
}

xpSet(2000);
observer.observe(node, options);
);
}

if (gBrowserInit.delayedStartupFinished) {
setTimeout(wInit, 5000);
} else {
if (gBrowserInit.delayedStartupFinished) setTimeout(wInit, 5000);
else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
Expand Down
Loading

0 comments on commit a8b14a0

Please sign in to comment.