Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed May 21, 2024
1 parent 6efd6e4 commit d806571
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 59 deletions.
8 changes: 4 additions & 4 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"qualityWhenRunningOnBattery":{
"message": "Quality, when running on battery"
},
"whenBatteryIslowDecreaseQuality":{
"message": "Low battery: Gradually decrease the quality!"
},
"pauseWhileIUnplugTheCharger":{
"message": "Pause when I unplug the charger!"
"message": "Pause when I unplug the charger"
},
"whenBatteryIslowDecreaseQuality":{
"message": "Low battery: Decrease the quality"
},
"analytics": {
"message": "Analytics"
Expand Down
8 changes: 4 additions & 4 deletions js&css/extension/www.youtube.com/general/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,24 @@ html[it-scroll-to-top='true'] #it-scroll-to-top:hover {
width: 96px !important;
}

html[it-hide-watched-videos='true']#dismissible:has(.it-mark-watched-videos[watched]) {
html[it-hide-watched-videos='true'] #dismissible:has(.it-mark-watched-videos[watched]) {
opacity: .45;
max-height: 4rem;
overflow: hidden;
transition: max-height 0.4s ease 0.1s;
}
html[it-hide-watched-videos='true']#dismissible:has(.it-mark-watched-videos[watched]) ytd-thumbnail {
html[it-hide-watched-videos='true'] #dismissible:has(.it-mark-watched-videos[watched]) ytd-thumbnail {
visibility: hidden;
max-width: 0;
transition: max-width 0.4s ease 0.1s;
}
html[it-hide-watched-videos='true']#dismissible:has(.it-mark-watched-videos[watched]):hover {
html[it-hide-watched-videos='true'] #dismissible:has(.it-mark-watched-videos[watched]):hover {
opacity: 1;
overflow: visible;
max-height: 120px;
transition: max-height 0.4s ease 1.1s;
}
html[it-hide-watched-videos='true']#dismissible:has(.it-mark-watched-videos[watched]):hover ytd-thumbnail {
html[it-hide-watched-videos='true'] #dismissible:has(.it-mark-watched-videos[watched]):hover ytd-thumbnail {
visibility: visible;
max-width: 220px;
transition: max-width 0.4s ease 1.1s;
Expand Down
86 changes: 37 additions & 49 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,56 +417,44 @@ ImprovedTube.playerQualityWithoutFocus = function () {
/*------------------------------------------------------------------------------
BATTERY FEATURES; PLAYER QUALITY BASED ON POWER STATUS
------------------------------------------------------------------------------*/
ImprovedTube.batteryFeatures = function () {
ImprovedTube.batteryFeatures = async function () {
if (ImprovedTube.storage.qualityWhenRunningOnBattery
|| ImprovedTube.storage.pauseWhileIUnplugTheCharger
|| ImprovedTube.storage.whenBatteryIslowDecreaseQuality) {
async function battery() {
try {
const battery = await navigator.getBattery();
if (battery) {
const updateQuality = () => {
if (!battery.charging) {
if (ImprovedTube.storage.qualityWhenRunningOnBattery) {
ImprovedTube.playerQuality(ImprovedTube.storage.qualityWhenRunningOnBattery);
}
if (ImprovedTube.storage.whenBatteryIslowDecreaseQuality) {
let quality;
if (battery.level > 0.11 || battery.dischargingTime > 900) {
quality = "large";
} else if (battery.level > 0.08 || battery.dischargingTime > 600) {
quality = "medium";
} else if (battery.level > 0.04 || battery.dischargingTime > 360) {
quality = "small";
} else {
quality = "tiny";
}
ImprovedTube.playerQuality(quality);
}
}
};
battery.addEventListener("levelchange", updateQuality);
if (ImprovedTube.storage.pauseWhileIUnplugTheCharger) {
battery.addEventListener("chargingchange", () => {
if (!battery.charging) {
ImprovedTube.elements.player.pauseVideo();
ImprovedTube.paused = true;
} else if (ImprovedTube.paused) {
ImprovedTube.elements.player.playVideo();
delete ImprovedTube.paused;
}
});
}
updateQuality();
} else {
console.log("No battery info - Desktop?");
}
} catch (error) {
console.error("Error accessing battery information:", error.message);
}
}
battery();
}
|| ImprovedTube.storage.pauseWhileIUnplugTheCharger
|| ImprovedTube.storage.whenBatteryIslowDecreaseQuality) {
const updateQuality = async (battery, charging) => {
if (battery) {
if (!battery.charging) {
if (ImprovedTube.storage.pauseWhileIUnplugTheCharger && charging) {
ImprovedTube.elements.player.pauseVideo();
ImprovedTube.paused = true;
}
if (ImprovedTube.storage.qualityWhenRunningOnBattery) {
ImprovedTube.playerQuality(ImprovedTube.storage.qualityWhenRunningOnBattery);
}
if (ImprovedTube.storage.whenBatteryIslowDecreaseQuality) {
let quality;
if (battery.level > 0.11 || battery.dischargingTime > 900) {
quality = "large";
} else if (battery.level > 0.08 || battery.dischargingTime > 600) {
quality = "medium";
} else if (battery.level > 0.04 || battery.dischargingTime > 360) {
quality = "small";
} else {
quality = "tiny";
}
ImprovedTube.playerQuality(quality);
}
} else if (charging && ImprovedTube.paused && ImprovedTube.storage.pauseWhileIUnplugTheCharger) {
ImprovedTube.elements.player.playVideo();
delete ImprovedTube.paused;
}
}
};
const battery = await navigator.getBattery();
battery.addEventListener("levelchange", () => updateQuality(battery));
battery.addEventListener("chargingchange", () => updateQuality(battery, true));
await updateQuality(battery);
}
};
/*------------------------------------------------------------------------------
FORCED VOLUME
Expand Down
9 changes: 7 additions & 2 deletions menu/skeleton-parts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,13 @@ extension.skeleton.main.layers.section.player.on.click = {
}
}
},
qualityWhenRunningOnBattery: {
component: 'switch',
/*
qualityWhenRunningOnBattery: {
component: 'select',
text: 'qualityWhenRunningOnBattery',
options: function () {
return extension.skeleton.main.layers.section.player.on.click.section_1.player_quality.options;
},
on: {
render: function () {
extension.skeleton.main.layers.section.player.on.click.section_1.player_quality.on.render.call(this);
Expand All @@ -763,6 +767,7 @@ extension.skeleton.main.layers.section.player.on.click = {
component: 'switch',
text: 'pauseWhileIUnplugTheCharger'
},
*/
mini_player: {
component: 'switch',
text: 'customMiniPlayer'
Expand Down

0 comments on commit d806571

Please sign in to comment.