Optimizes animation calls for lower GPU/CPU consumption
< Feedback on Youtube Player perf
And any visual impact for enabling this script?
updating base.js is YouTube's engineer daily routine.
I would suggest you to loop all the keys of _yt_player
to find the requested function automatically.
fnIntegrity
might helps you. const fnIntegrity = (f, d) => {
if (!f || typeof f !== 'function') {
console.warn('f is not a function', f);
return;
}
let p = f + "", s = 0, j = -1, w = 0;
for (let i = 0, l = p.length; i < l; i++) {
const t = p[i];
if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
if (j < i - 1) w++;
j = i;
} else {
s++;
}
}
let itz = `${f.length}.${s}.${w}`;
if (!d) {
return itz;
} else {
return itz === d;
}
}
I am not sure whether I am correct or not. Base on my guess,
(2023.08.12)
const PLAYER_CONSTRUCTOR = "nV";
const ATTR_UPDATE = "yo";
const UPDATE_INTERNAL = "v";
Then,
fnIntegrity(ytp[UPDATE_INTERNAL])
fnIntegrity(ytp[PLAYER_CONSTRUCTOR])
fnIntegrity(ytp[ATTR_UPDATE])
1.56.36
2.1083.609
3.57.36
if the fnIntegrity(ytp[key])
equals to 1.56.36
=> UPDATE_INTERNAL
if the fnIntegrity(ytp[key])
equals to 2.1083.609
=> PLAYER_CONSTRUCTOR
if the fnIntegrity(ytp[key])
equals to 3.57.36
=> ATTR_UPDATE
Of course in this approach, you still need to update but not that frequent
P.S. better to have a check for this.update
as well. It might change later by YouTube's engineer. This current function version is 1.36.25
If you have GitHub repo I can help you with PR.
let PLAYER_CONSTRUCTOR = "???";
let ATTR_UPDATE = "???";
let UPDATE_INTERNAL = "???";
const fnIntegrity = (f, d) => {
if (!f || typeof f !== 'function') {
console.warn('f is not a function', f);
return;
}
let p = f + "", s = 0, j = -1, w = 0;
for (let i = 0, l = p.length; i < l; i++) {
const t = p[i];
if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
if (j < i - 1) w++;
j = i;
} else {
s++;
}
}
let itz = `${f.length}.${s}.${w}`;
if (!d) {
return itz;
} else {
return itz === d;
}
}
function checks(ytp) {
// .u
// updating method
for (const [key, value] of Object.entries(_yt_player)) {
if (key.length <= 2 && typeof value === 'function') {
const fi = fnIntegrity(ytp[key]);
if (fi === '1.56.36') UPDATE_INTERNAL = key;
else if (fi === '2.1083.609') PLAYER_CONSTRUCTOR = key;
else if (fi === '3.57.36') ATTR_UPDATE = key;
}
}
return ytp[UPDATE_INTERNAL] && ytp[PLAYER_CONSTRUCTOR] && ytp[ATTR_UPDATE];
}
The Polymer constructor will depends on the language content.
ja_JP
( https://www.youtube.com/s/player/3cd2d050/player_ias.vflset/ja_JP/base.js
)else if (fi === '2.1083.609') PLAYER_CONSTRUCTOR = key;
en_US
( https://www.youtube.com/s/player/3cd2d050/player_ias.vflset/en_US/base.js
)else if (fi === '2.1058.597') PLAYER_CONSTRUCTOR = key;
else if (fi === '2.1083.609' || fi === '2.1058.597') PLAYER_CONSTRUCTOR = key;
revised version to ignore "aria-label" to make it language independent.
let PLAYER_CONSTRUCTOR = "???";
let ATTR_UPDATE = "???";
let UPDATE_INTERNAL = "???";
const fnIntegrity = (f, d) => {
if (!f || typeof f !== 'function') {
console.warn('f is not a function', f);
return;
}
let p = f + "", s = 0, j = -1, w = 0;
if (p.includes('"aria-label"')) p = p.replace(/([{,])"aria-label":"[^"]*"([,}])/g, '$1$2');
for (let i = 0, l = p.length; i < l; i++) {
const t = p[i];
if (((t >= 'a' && t <= 'z') || (t >= 'A' && t <= 'Z'))) {
if (j < i - 1) w++;
j = i;
} else {
s++;
}
}
let itz = `${f.length}.${s}.${w}`;
if (!d) {
return itz;
} else {
return itz === d;
}
}
function checks(ytp) {
// .u
// updating method
for (const [key, value] of Object.entries(_yt_player)) {
if (key.length <= 2 && typeof value === 'function') {
const fi = fnIntegrity(ytp[key]);
if (fi === '1.56.36') UPDATE_INTERNAL = key;
else if (fi === '2.1051.593') PLAYER_CONSTRUCTOR = key;
else if (fi === '3.57.36') ATTR_UPDATE = key;
}
}
return ytp[UPDATE_INTERNAL] && ytp[PLAYER_CONSTRUCTOR] && ytp[ATTR_UPDATE];
}
didnt expect to see you here lol, that would be a great collab
further update on function checks(ytp){...}
function checks(ytp) {
// .u
// updating method
let pcPrev = -1;
let pcRes = null;
for (const [key, value] of Object.entries(_yt_player)) {
if (key.length <= 2 && typeof value === 'function') {
const fi = fnIntegrity(ytp[key]);
if (fi === '1.56.36') UPDATE_INTERNAL = key;
// else if (fi === '2.1051.593') PLAYER_CONSTRUCTOR = key;
else if (fi === '3.57.36') ATTR_UPDATE = key;
else if (fi && typeof fi === 'string' && fi.length > 7 && fi.startsWith('2.')) {
let m = /\b\d{3,4}\b/.exec(fi);
m = m ? +m[0] : 0;
if (m && m > pcPrev + 150 && (value + "").indexOf('this.') >= 0) {
pcPrev = m;
pcRes = key;
}
}
}
}
if (pcPrev < 0) return false;
PLAYER_CONSTRUCTOR = pcRes;
return ytp[UPDATE_INTERNAL] && ytp[PLAYER_CONSTRUCTOR] && ytp[ATTR_UPDATE];
}
i see that CY Fung working on this script as well.
cant wait for more updates!
i see that CY Fung working on this script as well.
cant wait for more updates!
Similar JS Engine fixing is now added in YouTube JS Engine Tamer
I am not using the same way as what nopeless did. My approach might not have the great effect as this script, but I just want to ensure everything runs smoothly without issues.
Just curious.
If the cursor is not hovering over the video, will there be any difference for enabling this script?
When the cursor is hovering over the video, without this script, it keeps requesting animationframes??