Old Proxomitron Forums

Proxomitron Filters - Discussions welcome => Cosmetic => Topic started by: hpguru on April 22, 2002, 08:22:27 PM

Title: Remove Image Borders
Post by: hpguru on April 22, 2002, 08:22:27 PM
This filter will remove image borders (sets them to border=0) while preserving most other img tag attributes. It works even if the border attribute is missing. This is an adaptation of an example from the help files.



Name = "Remove Image Borders"
Active = TRUE
Bounds = "<imgs*>"
Limit = 256
Match = "(*((align|alt|class|controls|dir|dynsrc|height|hspace|id|"
        "ismap|lang|longdesc|loop|lowsrc|name|onclick|ondblclick|"
        "onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|"
        "onmouseout|onmouseover|onmouseup|src|start|style|title|"
        "usemap|vspace|width)((=$AV(*))|) )#)+ *"
Replace = "<img @ border="0">"



If there are attributes missing that you need you'll have to add them. Remove any you don't want.


Title: Remove Image Borders
Post by: altosax on April 22, 2002, 10:28:48 PM

hi hpguru,
i'm puzzled: why to remove the border from an image you have to match all other attributes?

perhaps i haven't understood in deep your filter, please explain it to me.

in the meantime, i suggest
Bounds = "<im(g|age)s*>"

sincerely,
altosax.


 
Title: Remove Image Borders
Post by: hpguru on April 23, 2002, 12:38:22 AM
I tried several filters and that is the only single filter that worked reliably.
This filter pushes all the existant attributes listed onto the replacement stack when matched. Attributes not listed (such as border) are not matched so they don't get pushed to the stack and are lost in the subsequent replacement.
In the replacement "@" dumps all the attributes stored in the replacement stack to the replacement string and the desired border attribute is inserted. This way border is added only once whether it exists or not and irregardless of it's position within the img tag. It acomplishes what it took two filters to do before.

I don't use "<im(g|age)s*>" because I've never seen an "<image>" tag used anywhere. I can't find any documentation of such a tag.



Edited by - hpguru on 23 Apr 2002  02:04:16
Title: Remove Image Borders
Post by: Jor on April 23, 2002, 02:00:17 AM
<image> is a MicroSoft "innovation" which appeared on their website before they moved to XML. The probable reason: this way download buttons for patches were invisible in all non-IE browsers.

Alas it was taken up by some idiots, as Frontpage accepts it (and I believe some versions even use it instead of <img>). I've seen it a couple of times on other sites... fortunately it doesn't seem to be as wide-spread as other MS or NS "extensions" of HTML.

 
Title: Remove Image Borders
Post by: Jor on April 23, 2002, 02:11:55 AM
Wouldn't this filter:
Name = "Remove Image Borders"
Active = TRUE
Bounds = "<im(g|age)s*>"
Limit = 256
Match = "1 border=$AV(*) 2"
Replace = "1 border="0" 2"
work just as well? No need to add border="0" to all images... since the default is none.

 
Title: Remove Image Borders
Post by: hpguru on April 23, 2002, 02:31:13 AM
quote:

<image> is a MicroSoft "innovation"...


That's what I presumed but I couldn't find mention of it at

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp

I always investigate when I find an ad that wasn't blocked and this tag never showed up. Even if I do find it I doubt I'll modify my filters to accomidate it unless I think I'll be returning to the site frequently. Even then I may not do it since eDexter zaps almost all the ads. Even if I go *proxyless* I see no ads, just blank areas and a few outlines here and there.

Anyway this filter I posted is a little on the bulky side so when I find a better way to do it cleanly I'll post it.

 
Title: Remove Image Borders
Post by: hpguru on April 23, 2002, 02:35:37 AM
quote:

... since the default is none.


Yes but if the image is a link the browser draws a border. Err ahh IE and Netscape draw a border. Opera doesn't.

That filter won't match if the border attribute is missing.




Edited by - hpguru on 23 Apr 2002  03:44:47
Title: Remove Image Borders
Post by: Jor on April 23, 2002, 02:38:33 AM
It's never been documented, which adds to my suspicion it's only intended use was to disable users of other browsers from downloading critical bugfixes (patches, and service packs, as MS calls them).

BTW, can ANYONE open these MSDN urls from within Opera? No matter what config I try (Prox on, Prox off, Prox web bypassed, Prox headers bypassed, etc) I only see the following:
"Welcome to the MSDN Library
Component Development
Data Access
Development (General)
Enterprise Development
Graphics and Multimedia
Messaging and Collaboration
Mobile and Embedded Development
.NET Development
.NET Development
Networking and Directory Services
Office Solutions Development
Security
Security
Setup and System Administration
User Interface Design and Development
User Interface Design and Development
Visual Tools and Languages
Web Development
Windows Development
XML Web Services
XML Web Services
MSDN Library Archive"

These URLs are really the only sites I still need MSIE for.

Edited by - Jor on 23 Apr 2002  03:41:11
Title: Remove Image Borders
Post by: Jor on April 23, 2002, 02:40:34 AM
quote:

Yes but if the image is a link the browser draws a border.

It does? *L* Been a long while since I used MSIE as my default browser... Opera allows for full control over this. (Preferences -> Fonts and Colors -> My Link Style -> Always border on image links). I have it set for disabled.

 
Title: Remove Image Borders
Post by: pooms on April 23, 2002, 02:52:02 AM
I had that same problem with MSDN pages with IE6 as well. I ended
up putting msdn.microsoft.com in my bypass list temporarily to
make it work. I never got around to looking at their site to see
why that was happening.

 
Title: Remove Image Borders
Post by: pooms on April 23, 2002, 03:03:55 AM
I just checked why those MSDN pages don't load: it's the User-Agent
HTTP header value. Try changing Opera's Browser Identification value
to an MSIE value and I bet it works!

 
Title: Remove Image Borders
Post by: Jor on April 23, 2002, 03:13:12 AM
Thank you!

That's it... and MS also seems to accept Mozilla user agents. I've added it to my DumbSites list... and will send a complaint to them some time tomorrow ^.^

 
Title: Remove Image Borders
Post by: hpguru on April 23, 2002, 03:29:55 AM
quote:

I had that same problem with MSDN pages with IE6 as well. I ended
up putting msdn.microsoft.com in my bypass list temporarily to
make it work. I never got around to looking at their site to see
why that was happening.





Same here. I need the info more than I need to pick their site apart so they are in the bypass. :( Realistically though, MS didn't write those pages for any other browser but IE and unfortunately that is the only browser that will render them correctly.

 
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 05:17:46 AM
I made a few changes to my new Remove Image Borders filter and decided to move it here.


Name = "Remove Image Borders v2.1"
Active = TRUE
Multi = TRUE
URL = "$TYPE(htm)"
Bounds = "<imgs*>"
Limit = 300
Match = "((border=$AV(0)>)1)|((border=$AV(0)s)1 2)"
        "|((border=$AV([#1:10])>)$SET(1=border="0")$SET(2=>))"
        "|((border=$AV([#1:10])s)$SET(1=border="0" ) 2)"
        "|(>)$SET(1= border="0")$SET(2=>)"
Replace = "12"


Can anyone think of a way to make it fail to match in the bounds match if border="0" already exists?

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: altosax on August 22, 2002, 10:27:03 AM
hi hp,
why not the filter jor proposed?

also, read my post in the if-then-else thread.

altosax.

 
Title: Remove Image Borders
Post by: altosax on August 22, 2002, 11:04:52 AM
hi hp,
i'm sorry, but i hadn't read first your answer to jor. so you need both to replace the border attribute when different from 0 and add border=0 when missing.
well, your filter works as expected but you can merge some option to make it simpler:

Name = "Remove Image Borders v2.2"
Active = TRUE
Multi = TRUE
URL = "$TYPE(htm)"
Bounds = "<im(g|age)s*>"
Limit = 300
Match = "border=$AV(*)2$SET(1=border="0")"
        "|>$SET(1= border="0">)"
Replace = "12"

altosax.

 
Title: Remove Image Borders
Post by: TEggHead on August 22, 2002, 12:52:23 PM
quote:
Match = "border=$AV(*)2$SET(1=border="0")|>$SET(1= border="0">)"


Aren't we overlooking a small thing here? this type of filters may follow a common logic, but that is certainly not the if-then-else logic but rather a no-matter-what logic, not? I mean, this is simply a case of
if it matches, fine, replace it, otherwise fine too, just insert it, so both branches end up doing the same thing, very atypical for an if-then-else structure, in fact quite the opposite, this looks more like an assertion

basically, the filter will need to always match (no matter if the attribute is there, the replacement is always inserted) so we do not need to complicate the match with all kinds of exceptions coz there's only one exception basically, the attribute not being present...

based on that I found the following format to always work

Match = "<TAG( ATTRIBUTE=$AV(*)|) 1>"
Replace = "<TAG ATTRIBUTE=MyValue 1>"

HPGuru
quote:

Can anyone think of a way to make it fail to match in the bounds match if border="0" already exists?


This would be the same test to exclude a replacement from being matched by the filter again...something like

Bounds = "<TAG(^*ATTRIBUTE=MyValue)*>"




Edited by - TEggHead on 22 Aug 2002  14:06:14
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 05:47:37 PM
Thank you altosax and tegghead. Those filters are a lot better and I learned a few tricks in the procces. What I've opted for however is to globally set the border attribute to "0" via my injected style sheet.

quote:

Aren't we overlooking a small thing here? this type of filters may follow a common logic, but that is certainly not the if-then-else logic but rather a no-matter-what logic, not?



Actually the implied logical structure is very similar to the IF-THEN-ELSE stuctures used in high level computer languages or like a CASE structure which is

CASE
(IF) test-clause_1 THEN true-clause_1
(IF) test-clause_2 THEN true-clause_2
...
(IF) test-clause_n THEN true-clause_n
default-clause
END

This runs through the (IF)-THEN tests till it finds a true result. If all tests are false it can process an optional default-clause or just fail the entire series of tests and exit without doing anything.

Years ago I wrote assembler code for HPs advanced scientific calculators such as the HP48 SX and GX series. Saturn Assembler being a low level machine language had no higher level branching structures but you could roll your own. It all depended on how you manipulated register/stack data and how you employed gotos and gosubs following simple bit and flag tests. So an IF-THEN-ELSE structure could be constructed as an implied meta structure but it wasn't actually there. Even so the code behaved as if it was there. This filter I posted has the same sort of *implied meta structure* that isn't really there but you get the same result you would if it was present.

Facing each other,
a thousand miles apart.


Edited by - hpguru on 22 Aug 2002  18:48:40
Title: Remove Image Borders
Post by: altosax on August 22, 2002, 06:37:06 PM
tegghead wrote:

quote:

based on that I found the following format to always work

Match = "<TAG( ATTRIBUTE=$AV(*)|) 1>"
Replace = "<TAG ATTRIBUTE=MyValue 1>"




using a slightly modified code, i think this structure could be used EVERY TIME we need to replace or set an attribute value:

Bounds = "<tags*>"
Match = "(1attribute=$AV(*)|1)2"
Replace = "1attribute="my_value"2"

i had need to modify a little the tegghead structure to take in account all variations, with a particular attention to spaces between attributes.
the variable is just to consume parens when the attribute we are searching for is not present.

altosax.

 
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 06:51:45 PM
Altosax,

That filter will place the desired attribute outside the tag in the event the attribute was missing.

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: altosax on August 22, 2002, 06:57:39 PM
you are right, this fix it:

Bounds = "<tags*>"
Match = "(1attribute=$AV(*)|1)2>"
Replace = "1attribute="my_value"2>"

altosax.

 
Title: Remove Image Borders
Post by: altosax on August 22, 2002, 07:01:49 PM
a better way:

Bounds = "<tags*>"
Match = "1(attribute=$AV(*)2|)>"
Replace = "1attribute="my_value"2>"

i think this is the state of the art for this kind of filters

altosax.

 
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 07:12:22 PM
That along with teggheads bounds match so the filter won't match if the desired attribute value already exists.

<TAG(^*ATTRIBUTE="MY_VALUE")*>

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 07:17:46 PM
And here is an improvement on that.

<TAG(^*ATTRIBUTE=("|)MY_VALUE("|))*>

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 07:21:54 PM
Better still

<TAG(^*ATTRIBUTE=$AV(MY_VALUE))*>

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: hpguru on August 22, 2002, 07:40:26 PM
May I recommend this replacement instead?

Replace = "1 attribute="my_value"2>"

Facing each other,
a thousand miles apart.
Title: Remove Image Borders
Post by: TEggHead on August 23, 2002, 12:15:24 AM
quote:

i think this structure could be used EVERY TIME we need to replace or set an attribute value:


It is just another form of the basic test for 'something or nothing' as described in "Tips And Tricks.html" ;)