Fixing AA in OS X Safari using Javascript (9)

1 Name: binhqx 2006-02-19 21:13 ID:Heaven

I was having trouble viewing the AA Bar in Safari because I did not want to set my default font to Mona. I wrote a little Javascript that adjusted the CSS of the page to use the Mona font and display properly. Take a look at it:

javascript:
var main_doc = parent.frames["main"].document;
for(i=0;i<main_doc.styleSheets.length;i++){
for(j=0;j<main_doc.styleSheets[i].cssRules.length;j++){
if(main_doc.styleSheets[i].cssRules[j].selectorText.match(/\.replytext/){
main_doc.styleSheets[i].cssRules[j].style.setProperty('font-family','Mona',null);
}}}

In Safari, copy the script to a single line and past it into the URL bar. It will change the font of all elements in the class "replytext" to Mona. Note that Monafont must be installed to do this.

Can anyone think of a cleaner, more robust way of doing this?

2 Post deleted by moderator.

3 Name: Albright!LC/IWhc3yc 2006-02-20 04:04 ID:GwQhU2AD

I don't have Mona, so I can't test it, but what's wrong with just defining a stylesheet like:

 .replytext{font-family:Mona;}

saving it somewhere, then telling Safari to use it in the Advanced section of the preferences?

4 Name: binhqx 2006-02-20 07:45 ID:Heaven

Sure, that is the easy way to do it.

Here is another method I came up with. Run this script, and the next html element clicked on will switched to the mona font.

function display(e){

e.target.style.fontFamily = 'Mona';

var doc_array = parent.frames;
if(doc_array.length <= 1)
doc_array = new Array(window);
for(i=0;i<doc_array.length;i++)
{
doc_array[i].document.releaseEvents(Event.MOUSEUP);
doc_array[i].document.onmouseup = null
}
}

var doc_array = parent.frames;
if(doc_array.length <= 1)
doc_array = new Array(window);
for(i=0;i<doc_array.length;i++){

doc_array[i].document.captureEvents(Event.MOUSEUP);
doc_array[i].document.onmouseup = display;

}

It works by assigning a onmouseup event to the window that changes the target element's fontFamily. After the event happens, the onmouseup event is removed. The only tricky bit is determining where to put the event hander if there are frames being used. Each frame is treated as a different window and needs its own hander assigned. The script works just about everywhere. The exception being on 2ch where the frames are directed at different domains. When a script attempts to run across a different domain then the main window a security error is generated. The workaround is to open the content frame in a new window.

5 Post deleted by moderator.

6 Post deleted by moderator.

7 Post deleted by moderator.

8 Name: sage 2006-02-21 01:03 ID:2YBkW1cq

Holy stealth thread, Batman!

9 Name: binhqx 2006-02-21 01:03 ID:Heaven

I guess someone did not like it...

This thread has been closed. You cannot post in this thread any longer.