I'm new to BAS. I want to block all resource consuming factors such as images etc.
It is explained in the forum that it can be done with request mask deny in the Network, but there is no request mask deny setting in the latest version I use.
I thought of it myself and blocked images and the like by writing a code in the Execute On Every Page Load in Browser section. However, the images are loaded at the first opening of the pages and then blocked. How do I ensure that images and videos never load or open?
The Code I wrote:
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
cleanNode(node);
}
});
});
});
function cleanNode(root) {
const selectors = [
'img',
'video',
'audio',
'source',
'iframe',
'embed',
'object',
'canvas',
'svg',
'picture',
'style',
'link[rel="stylesheet"]',
'script',
'[class*="ad"]',
'[id*="ad"]',
'[class*="banner"]',
'[id*="banner"]',
'[class*="sponsor"]',
'[id*="sponsor"]'
];
selectors.forEach(selector => {
const elements = root.querySelectorAll(selector);
elements.forEach(el => el.remove());
});
}
// Sayfa ilk yüklendiğinde temizle
document.addEventListener('DOMContentLoaded', function() {
cleanNode(document);
observer.observe(document.body, {
childList: true,
subtree: true
});
});