Skip to content

Commit

Permalink
v4.72.32
Browse files Browse the repository at this point in the history
code fix
  • Loading branch information
cyfung1031 committed May 26, 2024
1 parent ce3e06b commit af1cb0f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 27 deletions.
26 changes: 20 additions & 6 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ if (typeof window === 'object') {
const elementNextSibling = fxOperator(Element.prototype, 'nextElementSibling');
// const elementPrevSibling = fxOperator(Element.prototype, 'previousElementSibling');

const _setAttribute = Element.prototype.setAttribute;

/** @type {PromiseConstructor} */
const Promise = __Promise__; // YouTube hacks Promise in WaterFox Classic and "Promise.resolve(0)" nevers resolve.

Expand Down Expand Up @@ -300,7 +298,11 @@ if (typeof window === 'object') {
const dm = _dm;
dm._setAttribute = _setAttribute;
let j = 0;
const attributeName = `dm-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`;
let attributeName_;
while (dm.hasAttribute(attributeName_ = `dm-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`)) {
// none
}
const attributeName = attributeName_;
let qr = null;
const mo = new MutationObserver(() => {
if (qr !== null) {
Expand Down Expand Up @@ -783,14 +785,13 @@ if (typeof window === 'object') {


/** @type { (str: string) => (HTMLElement | null) } */
const querySelectorFromAnchor = HTMLElement.prototype.querySelector; // nodeType==1 // since 2022/07/12
const querySelectorFromAnchor = HTMLElement.prototype.__shady_native_querySelector || HTMLElement.prototype.querySelector; // nodeType==1 // since 2022/07/12

/** @type { (str: string) => (NodeList) } */
const querySelectorAllFromAnchor = HTMLElement.prototype.querySelectorAll; // nodeType==1 // since 2022/07/12
const querySelectorAllFromAnchor = HTMLElement.prototype.__shady_native_querySelectorAll || HTMLElement.prototype.querySelectorAll; // nodeType==1 // since 2022/07/12
const closestDOM = HTMLElement.prototype.closest;
//const elementRemove = HTMLElement.prototype.remove;
//const elementContains = HTMLElement.prototype.contains; // since 2022/07/12
const elementAppend = HTMLElement.prototype.appendChild; // necessary for yt custom elements; due to Waterfox classic and https://greasyfork.org/en/scripts/428651-tabview-youtube/discussions/174437

const querySelectorFromAnchorX = function (parent, childSelector) {
if (!(parent instanceof HTMLElement)) return null;
Expand All @@ -801,6 +802,19 @@ if (typeof window === 'object') {
return closestDOM.call(child, parentSelector) || null;
}


const { elementAppend, _setAttribute } = (() => {
let elementAppend = HTMLElement.prototype.appendChild;
try {
elementAppend = ShadyDOM.nativeMethods.appendChild;
} catch (e) { }
let _setAttribute = Element.prototype.setAttribute;
try {
_setAttribute = ShadyDOM.nativeMethods.setAttribute;
} catch (e) { }
return { elementAppend, _setAttribute };
})();

/**
*
* @param {number} f bit flag
Expand Down
90 changes: 71 additions & 19 deletions js/injection_script_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ function injection_script_1() {
})(HTMLVideoElement.prototype.pause);


const querySelectorFromAnchor = HTMLElement.prototype.querySelector;
const querySelectorAllFromAnchor = HTMLElement.prototype.querySelectorAll;
const querySelectorFromAnchor = HTMLElement.prototype.__shady_native_querySelector || HTMLElement.prototype.querySelector;
const querySelectorAllFromAnchor = HTMLElement.prototype.__shady_native_querySelectorAll || HTMLElement.prototype.querySelectorAll;
const closestFromAnchor = HTMLElement.prototype.closest;
const elementAppend = HTMLElement.prototype.appendChild; // necessary for yt custom elements; due to Waterfox classic and https://greasyfork.org/en/scripts/428651-tabview-youtube/discussions/174437

const { elementAppend, _setAttribute } = (() => {
let elementAppend = HTMLElement.prototype.appendChild;
try {
elementAppend = ShadyDOM.nativeMethods.appendChild;
} catch (e) { }
let _setAttribute = Element.prototype.setAttribute;
try {
_setAttribute = ShadyDOM.nativeMethods.setAttribute;
} catch (e) { }
return { elementAppend, _setAttribute };
})();

/** @type {globalThis.requestAnimationFrame} */
const $requestAnimationFrame = (window.webkitRequestAnimationFrame || window.requestAnimationFrame).bind(window);
Expand Down Expand Up @@ -143,6 +154,46 @@ function injection_script_1() {
})();


const getDMHelper = () => {
let _dm = document.getElementById('d-m');
if (!_dm) {
_dm = document.createElementNS('http://www.w3.org/2000/svg', 'defs');
_dm.id = 'd-m';
document.documentElement.insertBefore(_dm, document.documentElement.firstChild);
}
const dm = _dm;
dm._setAttribute = _setAttribute;
let j = 0;
let attributeName_;
while (dm.hasAttribute(attributeName_ = `dm-${Math.floor(Math.random() * 314159265359 + 314159265359).toString(36)}`)) {
// none
}
const attributeName = attributeName_;
let qr = null;
const mo = new MutationObserver(() => {
if (qr !== null) {
if (j > 8) j = 0;
qr = (qr(), null);
}
});
mo.observe(document, { childList: true, subtree: true, attributes: true });
return (resolve) => {
if (!qr) dm._setAttribute(attributeName, ++j);
return qr = resolve;
// return qr = afInterupter = resolve;
};
};
const dmPN = getDMHelper();


let _dmPromise = null;
const getDMPromise = () => {
return (_dmPromise || (_dmPromise = (new Promise(dmPN)).then(() => {
_dmPromise = null;
})))
};


const ytChatFrameSetup = new PromiseExternal();
const ceHackDone = new PromiseExternal();
let tabviewFixPopupRefitFn = null;
Expand Down Expand Up @@ -1623,10 +1674,8 @@ function injection_script_1() {
let btn = document.querySelector('[tyt-tab-content="#tab-info"]:not(.active)');
if (btn) {
btn.click();
await new Promise(r => setTimeout(r, 40));
} else {
await new Promise(r => setTimeout(r, 1));
}
await getDMPromise();

if (p instanceof HTMLElement) {
if (!document.fullscreenElement) p.scrollIntoView();
Expand Down Expand Up @@ -1728,18 +1777,21 @@ function injection_script_1() {
const tid = ++awh;
getRAFPromise().then(() => {
if (tid !== awh) return;
if (this.isAttached === true && this.url && this.collapsed === false) {
const chatframe = this.chatframe || (this.$ || 0).chatframe;
const url = `${this.url}`;
if (!chatframe || !url) return;
let loc = '';
try {
loc = chatframe.contentDocument.location.href
} catch (e) { }
if (loc === 'about:blank') {
this.urlChanged();
getDMPromise().then(()=>{
if (tid !== awh) return;
if (this.isAttached === true && this.url && this.url.includes('live_') && this.collapsed === false) {
const chatframe = this.chatframe || (this.$ || 0).chatframe;
const url = `${this.url}`;
if (!chatframe || !url) return;
let hostname = '';
try {
hostname = chatframe.contentDocument.location.hostname || ''
} catch (e) { }
if (!hostname.endsWith('youtube.com')) {
this.urlChanged();
}
}
}
});
});
return r;
}
Expand Down Expand Up @@ -2956,11 +3008,11 @@ function injection_script_1() {
if (!description) return;
let button = description.querySelector('#collapse[role="button"]:not([hidden]), #expand[role="button"]:not([hidden])');
if (!button) return;
setTimeout(() => { //setTimeout / raf required - js event issue
getDMPromise().then(() => { //setTimeout / raf required - js event issue
button.click();
// if (isTrusted && document.fullscreenElement !== null) description.scrollIntoView(true);
button = null;
}, 30);
});
evt.preventDefault();
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"host_permissions": [
"https://www.youtube.com/*"
],
"version": "4.72.31",
"version": "4.72.32",
"web_accessible_resources": [{
"resources": ["images/*.png", "js/injection*.js", "js/content.js", "css/style_*.css"],
"matches": ["https://www.youtube.com/*"]
Expand Down
2 changes: 1 addition & 1 deletion version.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.72.31
4.72.32

0 comments on commit af1cb0f

Please sign in to comment.