View Full Version : JavaScript arrays & Pacfiles
Bethrezen
04-20-2007, 03:21 AM
hi all
don't know if anyone will be able to help with this but i'll ask anyway is it possible use a pacfile to selectively remove elements from a page ???
would it be possible to write an array that would allow the selective removal of ad related iframes from a page ??
for instance when i login to hotmail i see an ad banner loaded in an iframe at the top of the page here is the code
<IFRAME
FRAMEBORDER=0
SCROLLING=NO
MARGINHEIGHT=0
MARGINWIDTH=0
WIDTH=728
HEIGHT=90
SRC="http://rad.msn.com/ADSAdClient31.dll?GetAd=&PG=HOTJ42&TF=_NEW&AP=1011" tabindex="-1">
</IFRAME>
now presently the ad in question is blocked by the host file but I'm left with a large area of white space where the ad should be and I'd like to know if its possible to remove this white space by having the pacfile remove the iframe much the same way the Greasemonkey iframe killer script does ??
jscheuer1
04-20-2007, 05:24 AM
This is thin ice around here as we are not allowed to discuss removing any ad that is required by a TOS* agreement. If it is for your personal use only, I believe there are several browsers that will do this for you.
Now, so long as this is not for public use, what is a pacfile?
*TOS - Terms of Service
Bob90
04-20-2007, 09:59 AM
There is a Firefox addon for what you want. It is called Adblock.
If it is for private use, use adblock, go to the page, rightclick the image and remove it.
It is great for dial-up as it stops the advert from loading!
Bethrezen
04-21-2007, 01:05 AM
This is thin ice around here as we are not allowed to discuss removing any ad that is required by a TOS* agreement. If it is for your personal use only, I believe there are several browsers that will do this for you.
fair enough
Now, so long as this is not for public use, what is a pacfile?
have a read of this it should give a reasonable explanation of what a pacfile is
http://en.wikipedia.org/wiki/Proxy_auto-config
and this link gives a short Lists of some predefined functions available for use
http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
now as it happens the pacfile contains a couple of useful functions which allow us to do content filtering in a similar fashion to a host file only a pacfile is more powerful as it can use regular expressions shell expressions and arrays which allows us to be much more selective
where a host file can only block whole domains a pacfile can be much more specific and block only specific contents such as scripts that might be trying to do questionable things like tracking
now in this case I'm trying to block the loading of iframes partly for content filtering purposes but also for security purposes as i have been made aware of some security problems with iframes that could be exploited that would allow execution of malicious code on my computer
now so far as i am aware there is only 2 ways to deal with this disable java which isn't an option or disable the use of iframes now opera offers a function like that but other browsers don't which is why I'm trying to find out if there is some code i could add to my pacfile that can do this across all browsers
now as for ad block this is a fine tool but problem is that it only works for firefox I'm looking for something that works across browsers which is why I'm using a pacfile coz this will work with any modern browser
in any event back to the question at hand is it possible to code an array that would allow me to prevent the loading of iframes ?? there by preventing any security problems and also removing white space created by empty iframes
now the following Greasemonkey user script does precisely this
// ==UserScript==
// @namespace http://javascript.about.com
// @author Stephen Chapman
// @name iframe killer
// @description deletes all iframes from a web page
// @include http://example.com/
// ==/UserScript==
while((el=document.getElementsByTagName('iframe')).length){el[0].parentNode.removeChild(el[0]);}
now what I'm wondering is if this could be made to work inside of a pacfile ?? unfortunately my attempts at this have thus far proven unsuccessful i assume however this is purely due to my lack of javascript knowledge
A PAC script has access to only the URL and the host, and can only modify the proxy used to access the resource. In order to alter the page somehow, you would need to have access to the page requested, as well as be able to supply an altered page to the browser. To do that, you'd need not only to be able to specify the proxy, but also to be the proxy: this sort of on-the-fly modification can only be performed by a proxy. Have a look at Privoxy's filtering capabilities (http://www.privoxy.org/user-manual/filter-file.html).
Dear gods, it's approaching 0300 again. Pardon me for what sounds in my head (I can't concentrate enough to actually read it) like a ramble.
Bethrezen
04-21-2007, 03:58 AM
hi
if its not possible to actually remove an element from a page would it be possible to at least modify a given element allowing me to perform content hiding the way adblock does ??
so if there was a large area of white space created by an empty iframe coz i'd blocked its contents would it be possible to resize that iframe to 0x0 pixels
also just out of curiosity how precisely does that iframe killing script work ??
No, there is no way to alter the contents of the page at all using a PAC file. You'd need to have either a client-side script running with access to the page or a proxy.
GreaseMonkey scripts work by altering the page once it has already been downloaded to the user's computer. That particular one simply goes through each <iframe> in the DOM and removes its association with its parent node, effectively deleting it.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.