Skip to content

Commit

Permalink
Merge pull request #2 from VilleKokkarinen/master
Browse files Browse the repository at this point in the history
V 0.0.3
  • Loading branch information
VilleKokkarinen authored Sep 21, 2022
2 parents 9b13675 + dd025a6 commit 82ef344
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ExtensionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ $(document).ready(function() {
try{
var element = document.getElementById("input");

if(element != null)

if(v.amount == undefined || v.amount == null)
v.amount = 0;

if(element != null && element.value != null)
element.value = v.amount
else{
console.log("no input loaded");
Expand All @@ -18,7 +22,7 @@ $(document).ready(function() {

var element = document.getElementById("input");

if(element != null)
if(element != null && element.value != null)
element.value = v.amount
else{
console.log("no input loaded");
Expand Down
85 changes: 84 additions & 1 deletion PlayerCenterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ function waitFor(condition, callback) {

var players = [];
var booli = false;
var currentamount = null;

var CinemaOrFullScreen = {
aInternal: 1000,
aListener: function(val) {},
set value(val) {
this.aInternal = val;
this.aListener(val);
},
get value() {
return this.aInternal;
},
registerListener: function(listener) {
this.aListener = listener;
}
}

var interval = null;

Expand All @@ -20,10 +35,75 @@ var interval = null;
booli = true;
}
},500)
function AddModeListeners(){
var ModeButton = document.getElementsByClassName("ytp-size-button")[0]
var FSButton = document.getElementsByClassName("ytp-fullscreen-button")[0]


ModeButton.addEventListener("click", function() {
var cinemamode = false;

var players = document.getElementsByTagName("ytd-watch-flexy")

if(ModeButton.getAttribute("data-title-no-tooltip") != "Cinema mode"){
cinemamode = true;
}

if(cinemamode){
players[0]['style']['paddingLeft'] = currentamount+"vw";
CinemaOrFullScreen.value = false;
}else{
players[0]['style']['paddingLeft'] = 0+"vw";
CinemaOrFullScreen.value = true;
}

console.log("clicked modebutton" + cinemamode)

setTimeout(() => {
AddModeListeners();
}, 1000);

});

FSButton.addEventListener("click", function() {
var fsmode = false;
var players = document.getElementsByTagName("ytd-watch-flexy")

if(FSButton.getAttribute("data-title-no-tooltip") != "Full screen"){
fsmode = true;
}

if(fsmode){
players[0]['style']['paddingLeft'] = currentamount+"vw";
}else{
players[0]['style']['paddingLeft'] = 0+"vw";
CinemaOrFullScreen.value = true;
}

console.log("clicked fsbutton" + fsmode)
setTimeout(() => {
AddModeListeners();
}, 1000);

});
}

waitFor(()=> booli == true, () => {
waitFor(()=> booli == true, () => {
clearInterval(interval)
AddModeListeners();


var players = document.getElementsByTagName("ytd-watch-flexy")
if(players != null)
if(players[0] != null)
if(players[0].className =="style-scope ytd-page-manager hide-skeleton"
&& ( players[0].hasAttribute("theater") == true || players[0].hasAttribute("fullscreen") == true )
){
CinemaOrFullScreen.value = true;
}
else{
CinemaOrFullScreen.value = false;
}

chrome.storage.onChanged.addListener(function (changes, namespace) {
for (let [key, { oldValue, newValue }] of Object.entries(changes)) {
Expand All @@ -35,6 +115,9 @@ chrome.storage.onChanged.addListener(function (changes, namespace) {
var update = function(amount){
var players = document.getElementsByTagName("ytd-watch-flexy")
if(amount != null){
currentamount = amount;

if(CinemaOrFullScreen.value == false)
players[0]['style']['paddingLeft'] = amount+"vw";
}
}
Expand Down

0 comments on commit 82ef344

Please sign in to comment.