accept content warning automatically (#406)

Closes #404
This commit is contained in:
joaopjrn 2024-11-10 18:47:05 -03:00 • committed by GitHub
parent f5ef9bfe24
commit 5df7138b85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -95,7 +95,10 @@ abstract class VideoStoreBase with Store {
)
..setNavigationDelegate(
NavigationDelegate(
onPageFinished: (_) => initVideo(),
onPageFinished: (_) {
initVideo();
_acceptContentWarning();
},
),
);
@ -291,6 +294,45 @@ abstract class VideoStoreBase with Store {
}
}
Future<void> _acceptContentWarning() async {
try {
await videoWebViewController.runJavaScript('''
{
const asyncQuerySelector = (selector, timeout = undefined) => new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver((mutations) => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, { childList: true, subtree: true });
if (timeout) {
setTimeout(() => {
observer.disconnect();
resolve(undefined);
}, timeout);
}
});
(async () => {
const warningBtn = await asyncQuerySelector('button[data-a-target*="content-classification-gate"]', 10000);
if (warningBtn) {
warningBtn.click();
}
})();
}
''');
} catch (e) {
debugPrint(e.toString());
}
}
Future<void> _listenOnLatencyChanges() async {
try {
await videoWebViewController.runJavaScript('''