|
| User Javascript to block HTTP requests? |
 |
Wed, 05 Mar 2008 13:32:18 -000 |
I can write a script that removes external images from a site easily
enough, but is there a way to reliably prevent the HTTP requests from
occurring? This would be much the same as using preventDefault() on the
BeforeExternalScript event to stop scripts being loaded.
Perhaps the event should have been named BeforeExternalResource and
allowed to work on any file fetched from a web page (CSS, JS, images,
objects, etc) and then use the event object to work out what kind of file
is about to be requested and from what source?
Maybe something like dummy code:
// If e.element was a pointer to the DOM node then just use the DOM:
opera.addEventListener(
'BeforeExternalResource',
function(e){
if(e.element.tagName==='IMG') e.preventDefault()
},
false
)
...Or:
// A proprietary property for extra functionality:
opera.addEventListener(
'BeforeExternalResource',
function(e){
if(e.requestSource==='XMLHttpRequest') {
// Block AJAX
e.preventDefault()
// The HTTP request could be sniffed and/or rewritten.
}
else if(e.requestSource==='img') {
// Block image request and replace with encoded data
e.preventDefault()
e.element.src='data:image/png;base64,hf73h3ud8u3h3d=='
}
else if(
e.requestSource==='link' &&
e.element.href.match(/\.css$/)
) {
// Intercept stylesheet and do something to it
e.preventDefault()
e.element.text='body {background:#000;color:#fff;}'
}
else if(
e.requestSource==='object' &&
e.element.type==='application/x-shockwave-flash'
) {
// Intercept Flash request and remove from page
e.preventDefault()
e.element.parentNode.removeChild(e.element)
}
},
false
)
This would be equally useful on the mobile version, where a script could
be used as an advanced content blocker that would reduce unwanted data
|
| Post Reply
|
|
|
|
|
|
|
|
|
|