Skip to content

Commit

Permalink
Automatic soft to hard replace switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Jan 18, 2025
1 parent 19ee5ee commit 81dfee0
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions chrome/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@

if (softReplace) {
for (let i = 1; i <= 8; i++) {
setTimeout(() => {
updateReplacedPlayers();
}, i * 250);
((i) => {
setTimeout(() => {
updateReplacedPlayers(i == 4 ? pobj : null);
}, i * 250);
})(i);
}
}

Expand All @@ -322,6 +324,17 @@
return true;
}

function makeSoftIntoHard(pobj) {
const {iframe, old} = pobj;
if (!pobj.softReplace) {
return;
}

showSoft(old);
old.remove();
pobj.softReplace = false;
}

function handleWindowedFullscreen(request, sender, sendResponse) {
const iframeObj = iframeMap.get(request.frameId);
if (!iframeObj) {
Expand Down Expand Up @@ -766,7 +779,7 @@
player.style.display = '';
}

function updateReplacedPlayers() {
function updateReplacedPlayers(convert = null) {
iframeMap.forEach((iframeObj) => {
if (iframeObj.replacedData) {
const {iframe, old, softReplace} = iframeObj.replacedData;
Expand All @@ -777,7 +790,12 @@
updateReplacedPlayer(old, placeholder, softReplace);
placeholder.style.setProperty('background-color', 'black', 'important');
} else {
updateReplacedPlayer(old, iframe, softReplace);
const final_size = updateReplacedPlayer(old, iframe, softReplace);
if (convert == iframeObj.replacedData &&final_size <= 100 && softReplace) {
console.log('converting to hard', iframeObj);
makeSoftIntoHard(iframeObj.replacedData);
updateReplacedPlayer(old, iframe, false);
}
}
} else if (iframeObj.miniplayerState.active) {
updateMiniPlayer(iframeObj);
Expand All @@ -788,16 +806,18 @@
function updateReplacedPlayer(old, iframe, softReplace) {
const parent = iframe.parentNode;
iframe.style.display = 'none';
let final_size;
if (softReplace) {
showSoft(old);
transferStyles(old, iframe, true);
final_size = transferStyles(old, iframe, true);
hideSoft(old);
} else {
parent.insertBefore(old, iframe);
transferId(iframe, old);
transferStyles(old, iframe, false);
final_size = transferStyles(old, iframe, false);
parent.removeChild(old);
}
return final_size;
}

function pauseOnPlay() {
Expand Down Expand Up @@ -882,6 +902,8 @@
iframe.style.border = styles.border;
iframe.style.borderRadius = styles.borderRadius;
iframe.style.boxShadow = styles.boxShadow;

return rect.width * rect.height;
}

function transferId(from, to) {
Expand Down

0 comments on commit 81dfee0

Please sign in to comment.