提问人:Atti 提问时间:10/21/2023 更新时间:10/21/2023 访问量:12
有什么更好的方法来禁用所有cookie同意复选框/滑块吗?
Any better way to disable all the cookie consent checkboxes / sliders?
问:
从欧洲,此页面 https://www.britannica.com/place/British-Virgin-Islands 将显示 cookie 同意对话框。
要快速拒绝所有cookie,必须选择“管理设置”,然后选择供应商。所有行似乎都已停用,但是,仔细检查,包含“i”工具提示的行将在其中激活“合法权益”。
要使下面的脚本正常工作,由于 cookie 对话框是一个 iframe,因此在显示供应商时,首先必须检查 iframe 中的任何内容。之后,可以将以下代码复制到控制台中,并通过按 ENTER 运行。
注意:iframe 中的某些 HTML 元素可能会随着时间的推移而更改,querySelector 可能需要更新。
tooltips = document.querySelectorAll('div[_ngcontent-ng-c2192111456][role="tooltip"]');
end = tooltips.length;
stopAction = false;
for ( let i=0; i<end && !stopAction; i++ ) {
console.log("Progress: " + i + " / " + (end-1));
// as soon as the loop finishes and moves on to the next cycle, the tooltips variable
// looses the references? so, initiate it again every time
tooltips = document.querySelectorAll('div[_ngcontent-ng-c2192111456][role="tooltip"]');
row = tooltips[i].parentNode;
if ( (tooltips.length>0) && tooltips[i] && row ) {
row.click();
// wait 100ms for the page elements to "surely" be present?
await new Promise(resolve => setTimeout(resolve, 100));
switchBox = document.querySelector('span[role="checkbox"][aria-checked="true"]');
if ( switchBox ) {
switchBox.click();
//wait 150 ms to see the checkbox/slider animation
await new Promise(resolve => setTimeout(resolve, 150));
}
backButton = document.querySelector('span[_ngcontent-ng-c2083334920]');
if ( backButton ) {
backButton.click();
// wait 300 ms so that the IFrame's content get's changed?
await new Promise(resolve => setTimeout(resolve, 300));
}
} else {
console.log("row not found --> " + i);
}
}
如果未在 Cookie 对话框中检查“供应商”页上的元素,则 querySelectors 将不会返回预期的元素(从浏览器控制台)。
答: 暂无答案
评论