Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raszpl patch 2 #1671

Merged
merged 12 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions js&css/satus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,8 +1107,15 @@ satus.components.modal = function(component, skeleton) {
component.scrim = component.createChildElement('div', 'scrim');
component.surface = component.createChildElement('div', 'surface');

component.close = function() {
component.close = function(outside) {
var component = this;

//try calling cancel when clicked outside of modal dialog
if (outside) {
//not sure if bug free so better trap this for now
try { if (skeleton.actions.cancel.on.click) skeleton.actions.cancel.on.click(); }
catch(err){console.log(err);}
}

this.classList.add('satus-modal--closing');

Expand All @@ -1120,7 +1127,8 @@ satus.components.modal = function(component, skeleton) {
};

component.scrim.addEventListener('click', function() {
this.parentNode.close();
//this is someone clicking outside of modal dialog
this.parentNode.close(true);
});

if (satus.isset(skeleton.content)) {
Expand Down
87 changes: 45 additions & 42 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ var ImprovedTube = {
/*--------------------------------------------------------------
CODEC || 30FPS
----------------------------------------------------------------
Do not move, needs to be on top of first injected content
file to patch HTMLMediaElement before YT player uses it.
Do not move, needs to be on top of first injected content
file to patch HTMLMediaElement before YT player uses it.
--------------------------------------------------------------*/
if (localStorage['it-codec'] || localStorage['it-player30fps']) {
function overwrite(self, callback, mime) {
if (localStorage['it-codec']) {
var re = new RegExp(localStorage['it-codec']);
// /webm|vp8|vp9/av01/
if (re.test(mime)) return '';
}
if (localStorage['it-player30fps']) {
var match = /framerate=(\d+)/.exec(mime);
if (match && match[1] > 30) return '';
}
if (localStorage['it-codec']) {
var re = new RegExp(localStorage['it-codec']);
// /webm|vp8|vp9|av01/
if (re.test(mime)) return '';
}
if (localStorage['it-player30fps']) {
var match = /framerate=(\d+)/.exec(mime);
if (match && match[1] > 30) return '';
}
return callback.call(self, mime);
}
};

if (window.MediaSource) {
var isTypeSupported = window.MediaSource.isTypeSupported;
Expand Down Expand Up @@ -151,38 +151,41 @@ document.addEventListener('it-message-from-extension', function () {

if (message.action === 'storage-loaded') {
ImprovedTube.storage = message.storage;

if (ImprovedTube.storage.player_h264) {
localStorage['it-codec'] = "/webm|vp8|vp9|av01/";
} else {
localStorage.removeItem('it-codec');
}
if (!ImprovedTube.storage.player_60fps) {
localStorage['it-player30fps'] = true;
} else {
localStorage.removeItem('it-player30fps');
}

if (ImprovedTube.storage.block_vp9 || ImprovedTube.storage.block_av1 || ImprovedTube.storage.block_h264) {
let atlas = {block_vp9:'vp9|vp09', block_h264:'avc1', block_av1:'av01'}
localStorage['it-codec'] = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all?all+'|':'') + atlas[key]) : all}, '');
} else {
localStorage.removeItem('it-codec');
}
if (!ImprovedTube.storage.player_60fps) {
localStorage['it-player30fps'] = true;
} else {
localStorage.removeItem('it-player30fps');
}

// FEEDBACK WHEN THE USER CHANGED A SETTING
// FEEDBACK WHEN THE USER CHANGED A SETTING
ImprovedTube.init();
} else if (message.action === 'storage-changed') {
var camelized_key = message.camelizedKey;

ImprovedTube.storage[message.key] = message.value;
if(message.key==="player_h264"){
if (ImprovedTube.storage.player_h264) {
localStorage['it-codec'] = "/webm|vp8|vp9|av01/";
} else {
localStorage.removeItem('it-codec');
}
}
if(message.key==="player_60fps"){
if (!ImprovedTube.storage.player_60fps) {
localStorage['it-player30fps'] = true;
} else {
localStorage.removeItem('it-player30fps');
}
}
if(['block_vp9', 'block_h264', 'block_av1'].includes(message.key)){
let atlas = {block_vp9:'vp9|vp09', block_h264:'avc1', block_av1:'av01'}
localStorage['it-codec'] = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all?all+'|':'') + atlas[key]) : all}, '');
if (!localStorage['it-codec']) {
localStorage.removeItem('it-codec');
}
}
if(message.key==="player_60fps"){
if (!ImprovedTube.storage.player_60fps) {
localStorage['it-player30fps'] = true;
} else {
localStorage.removeItem('it-player30fps');
}
}
if(ImprovedTube.storage[message.key]==="when_paused"){
ImprovedTube.whenPaused();
};
Expand All @@ -195,20 +198,20 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.setTheme();
} else if (camelized_key === 'description') {
if (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.description === "classic_expanded" )
{try{document.querySelector("#more").click() || document.querySelector("#expand").click() ;} catch{} }
{try{document.querySelector("#more").click() || document.querySelector("#expand").click() ;} catch{} }
if (ImprovedTube.storage.description === "normal" || ImprovedTube.storage.description === "classic" )
{try{document.querySelector("#less").click() || document.querySelector("#collapse").click();} catch{}}
ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer();
}
else if (camelized_key === 'transcript') {
if (ImprovedTube.storage.transcript === true) {try{document.querySelector('*[target-id*=transcript]').removeAttribute('visibility');}catch{}
else if (camelized_key === 'transcript') {
if (ImprovedTube.storage.transcript === true) {try{document.querySelector('*[target-id*=transcript]').removeAttribute('visibility');}catch{}
} if (ImprovedTube.storage.transcript === false){try{document.querySelector('*[target-id*=transcript] #visibility-button button').click();}catch{}}
}
else if (camelized_key === 'chapters') {
if (ImprovedTube.storage.chapters === true){try{document.querySelector('*[target-id*=chapters]').removeAttribute('visibility');}catch{}
} if (ImprovedTube.storage.chapters === false){try{document.querySelector('*[target-id*=chapters] #visibility-button button').click();}catch{}}
}
else if (camelized_key === 'commentsSidebar') {
else if (camelized_key === 'commentsSidebar') {
if(ImprovedTube.storage.comments_sidebar === false)
{document.querySelector("#below").appendChild(document.querySelector("#comments"));
document.querySelector("#secondary").appendChild(document.querySelector("#related")); }
Expand Down
22 changes: 21 additions & 1 deletion js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,19 @@ ImprovedTube.playerAutofullscreen = function () {
QUALITY
------------------------------------------------------------------------------*/
ImprovedTube.playerQuality = function () {
function closest (num, arr) {
let curr = arr[0];
let diff = Math.abs (num - curr);
for (let val = 0; val < arr.length; val++) {
let newdiff = Math.abs (num - arr[val]);
if (newdiff < diff) {
diff = newdiff;
curr = arr[val];
}
}
return curr;
};

var player = this.elements.player,
quality = this.storage.player_quality;

Expand All @@ -384,7 +397,14 @@ ImprovedTube.playerQuality = function () {

if (quality && quality !== 'auto') {
if (available_quality_levels.includes(quality) === false) {
quality = available_quality_levels[0];
let label = ['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'];
let resolution = ['144', '240', '360', '480', '720', '1080', '1440', '2160', '2880', '4320'];
let availableresolutions = available_quality_levels.reduce(function (array, elem) {
array.push(resolution[label.indexOf(elem)]); return array;
}, []);

quality = closest (resolution[label.indexOf(quality)], availableresolutions);
quality = label[resolution.indexOf(quality)];
}

player.setPlaybackQualityRange(quality);
Expand Down
Loading