Showing posts with label Firefox. Show all posts
Showing posts with label Firefox. Show all posts

2009-08-14

Google Reader and Firefox's maximum popup limit

If you browse using Firefox and use the Google Reader keyboard v shortcut that I wrote in an earlier post, you may find that Firefox will eventually generate this message, Firefox prevented this site from opening a pop-up window, although you have added www.google.com to the Allowed Sites - Pop-ups dialog. This behaviour occurs because Firefox prevents any site from automatically opening too many popups.

According to Lifehacker's Increase Firefox's Maximum Pop-up Count, the number of pop-up windows a site is allowed to show is controlled by the dom.popup_maximum variable. By default, it is set to 20, so to avoid hitting the limit, I increased this value. Of course, now my browser is more vulnerable to a pop-up window attack or runaway script from all sites listed in the Allowed Sites.

Perhaps a better solution is to have a per-site limit?

2009-08-09

Read 'Times Online' article comments earliest first

The comments appearing after articles in the Times Online are displayed in reverse chronological order (latest first), which I find difficult to read, so I wrote this GreaseMonkey jQuery script to click the Oldest first link after the page is loaded:

// ==UserScript==
// @name         Timesonline.co.uk earliest comment first
// @namespace    kamhungsoh.com
// @description  Show an article's comments, earliest comment first.
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
// @include      http://*.timesonline.co.uk/*
// ==/UserScript==

var evt = document.createEvent('HTMLEvents');
evt.initEvent('click', true, true);

$("a:contains('Oldest first')").each(function() {
  this.dispatchEvent(evt);
});

The script is a little more complicated than I expected. Apparently jQuery cannot send events (see the last response in the thread) that it itself did not bind to objects, so my script has to create a click event object and send it to the link. Otherwise, I would written $("a:contains('Oldest first')").trigger('click');

Also, the script's a little hacky because it will send a click event to all links containing the text 'Oldest first', though it seems pretty unlikely that a page will have more than one link of that type in the first place.

2009-07-12

java.sun.com - improve online readability

Since I read a lot of Sun Java development documentation online, here is a more readable style. I only applied a small number of changes to avoid accidentally screwing up the site's presentation:

  1. Set text columns' maximum width to 30em. Elements which may be naturally wide, such as <img> (for images) and <pre> (for sample code), are not affected. Text is easier to scan if the columns aren't too wide.
  2. Set font family in <code> and <pre> (usually code samples) from Courier to Consolas or Courier New. Courier characters don't seem to get aliased (right term?) properly and look broken up on my notebook screen. Does anyone else have this problem? I chose Consolas because it matches the font I use in my IDEs sessions, and Courier New as a second choice because if Consolas is not available.
  3. Set <pre> background from gray to transparent. Sun marks up code samples in different ways, so it doesn't work in all pages.

Sun does not mark up all text in tags. For example, in javax.sql package summary, the text that follows <h2> headings cannot be styled since CSS cannot select text nodes. Might check if this a limitation of javadoc or whether API documentation writers have to explicitly mark up their paragraphs in <p> tags.

2009-07-05

Blogger full window width edit box

The text pane in Blogger's edit page is rather cramped and becomes full when you're writing more than a couple of paragraphs. After looking at Blogger Wide Screen Editor, I thought it should be possible to write a style to automatically fit the edit box in a browser's window.

My Blogger full window width edit box style just changes the width of <div> elements from fixed values to auto so the edit box can fill the width of the window. A bonus of this technique is that the tabs and controls automatically stay close to the right hand border when you resize your browser's window.

Just to avoid unplanned effects on the Blogger pages, I've set my style to only be applied to Blogger's post pages using url-prefix("http://www.blogger.com/post").

2009-06-28

CSS inheritance and selector specificity for max-width

While finding it easier to read text using narrower columns using my custom CSS definition, I noticed that it didn't work on pages that use table rows for grouping sections, such as the following structure:

table
  tbody
    tr
      td
        <headings>
        p …

Here's the CSS definition I was using:


@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain(java.sun.com)
{
  body {
    max-width : 35em;
  }
}

It appears that the max-width property defined in the <body> element property isn't inherited by the <p> elements within the <table>. My first fix was to select all the elements in the path between <body> and <p> and make them inherit the max-width property:


…
  table, tbody, tr, td {
    max-width : inherit;
  }

This isn't a nice solution because I would have to specify all the possible types (or elements) that could be in a table cell. It would be better the use the CSS universal selector, *, instead:


…
  * {
    max-width : inherit;
  }

Now the definition is even applied to some elements that we don't really want to limit in size. Elements that are naturally wider than max-width, such as images in <img> tags, are now squashed, while preformatted text in <pre> elements are displayed in boxes with horizontal scrollbars.

If the max-width property is set to none, then the width of an element is not limited. The solution is to have two rules, a universal selector and a type selector, and we have a CSS definition that limits the width of all elements except for <div>, <img> and <pre>:


@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain(java.sun.com)
{
  body {
    max-width : 35em;
  }
  * {
    max-width : inherit;
  }
  div, img, pre {
    max-width : none;
  }
}

This definition works because the universal selector is a less specific than a type selector, so the rules for <div>, <img> and <pre> override the universal selector's rule.

As usual when hacking code, I now realise that there's no longer any need to use inherit and I can simplify my CSS definition by specifying the max-width of every type using the universal selector.


@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain(java.sun.com)
{
  * {
    max-width : 35em;
  }
  div, img, pre {
    max-width : none;
  }
}

To see the effects of the different definitions, add the style to your Stylish add-in, visit this Sun Java page and observe what happens to the width of the navigation bar on the top of the page and the sequence diagram images.

2009-06-10

Localize dates in Scientific American

Scientific American formats dates in its pages as m/d/yy, while I prefer d/m/yy. Like an earlier post about formatting dates in Blogger's Dashboard, this Greasemonkey script uses a regular expression to find date strings in a page, and switches the month and day values.

// ==UserScript==
// @name           Scientific American localize dates
// @namespace      kamhungsoh.com
// @description    Convert dates from mm/dd/yy to dd/mm/yy format
// @require        http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js
// @include        http://www.scientificamerican.com/*
// ==/UserScript==

$('span').each(function() {
  var s = $(this).text().replace(/(.*)(\d+)\/(\d+)\/(\d+)/, '$1$3/$2/$4');
  $(this).text(s);
});

The script only works for the home page and I haven't figured out why I can't construct an expression to locate date strings in articles. Another thing to note is that jQuery's .text() function returns all the text values in a node, so some of the formatting, such as strong tags, are lost when the script replaces the text.

2009-06-07

Reformatting post dates in Blogger Dashboard

In the Blogger Dashboard, the posting date of your entries are in mm/dd/yy format and Google doesn't provide a way to localize it or choose a date format. Here's how you can use a Greasemonkey script to convert dates in Dashboard to dd/mm/yy format.

The dates in Dashboard have this structure:

<td class="date">
  <span>3/6/09</span>
</td>

The following script uses jQuery to iterate through all span nodes of td elements with a date class attribute, then applies the Javascript string replace() function to swap the first two numbers in the span node. To change the output string, just modify the second argument of the replace() function.

// ==UserScript==
// @name           blogger.com localize dashboard date
// @namespace      kamhungsoh.com
// @description    Convert date format from m/d/yy to d/m/yy.
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
// @include        http://www.blogger.com/posts.g*
// ==/UserScript==

$("td.date > span").each(function() {
  var s = $(this).text().replace(/(\d+)\/(\d+)/, '$2\/$1');
  $(this).text(s);
});

The first argument of the replace() function is a regular expression where \d is a meta-character for a digit, + matches one or more of the preceding character (e.g. 4 or 23) and the parentheses group the characters to be memorised. The forward slash has to be escaped, \/, to allow us to match it in the input string. In the second argument, the $2/$1 represents the second and first memorised strings.

2009-05-26

Read 'The Economist' article comments earliest first

A simple GreaseMonkey script using jQuery to show the comments to articles in The Economist, from earliest first. Basically, this script looks for <a> tags with specific text in their href attribute and appends &sort=asc. It's shorter and easier to read than the original plain Javascript version.

See Also

2009-05-25

CSS @media for Firefox Stylish Add-in

In an earlier entry, I wrote about using the @media print rule in a CSS file to insert the value of URLs in the print version of a web page. If the webmaster of the site didn't provide this rule, can you still print the URLs?

If you are using the Firefox Stylish add-in, you can provide your own CSS file to apply to a web site. I tried this:

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("www.gamedev.net") {
  @media print {
    a:after { content:" (" attr(href) ")"; }
  }
}

… but it didn't work. It seems that the Mozilla / Firefox @-moz-document rule doesn't allow @-rules within it (see the Mozilla links below).

If you move the @media print outside of @-moz-document rule, as below, then any page that you print will include URL strings in the output.

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("www.gamedev.net") {}

@media print {
  a:after { content:" (" attr(href) ")"; }
}

The only way to manage this behaviour is to disable that stylesheet in Firefox's User Styles page of the Add-ons dialog.

See Also

2009-05-08

Modify URL to Read Comments From Beginning

When I read responses or comments to articles, I prefer to read them from the earliest to the latest. Some sites order comments in reverse (that is, latest to earliest). If a site's comment link can take an 'order' argument, just modify that URL to specify your preferred order and save yourself an extra click. Below is a sample GreaseMonkey script that can specify the order of comments in The Economist, which are ordered from latest to earliest, by default.

var pattern = 'mode=comment';
var sortOrder = '&sort=asc';
var links = document.getElementsByTagName('a');
for (var i = links.length - 1; i >= 0; --i) {
  var link = links[i];
  var url = link.getAttribute('href');
  if (url.search(pattern) != -1) {
    link.setAttribute('href', url.replace(pattern, pattern + sortOrder));
  }
}

To use it on other sites that have similar URLs, just modify the values of pattern and sortOrder.

2009-04-22

Make Columns Narrower with GreaseMonkey or Stylish

It is hard to read a lot of text in a wide browser window, so below are two GreaseMonkey scripts to make the text columns narrower. They both work by changing an element's CSS width to a percentage of the window width.

If the text is within a known element tag (e.g. p), try the following script, which iterates through the collection of elements and sets the elements CSS width.

for each (e in document.getElementsByTagName('p')) {
  e.style.width = '60%';
}

If all the text is all within a single containing element, such as the body element, then the script can be shortened to …

document.getElementsByTagName('body')[0].style.width = '60%';.

If you want to also centre the text in the window, just change move the left margin by adding e.style.marginLeft = '20%';. marginLeft is the Javascript equivalent of CSS' margin-left property.

Later … I realised that since we're only changing CSS properties, it's a lot easier to use the Stylish add-in. Just add a style sheet like this:

  body {
    margin-left : 20%;
    width : 60%;
  }

See also

2009-02-05

Firefox most popular browser

Unbelievable. The browser statistics for W3 Schools show that in January '09, Firefox was more popular than all versions of MSIE combined: 45.5% vs 44.8%. Also, there are more visits with browsers that support SVG (Firefox, Chrome, Opera and Safari) than with browsers that don't (MSIE family): 54.7% versus 44.8%.

Yes, it's only one site frequented by web developers, not representative of the average user, yada yada, …

2009-01-24

Beginning Firefox Ubiquity

Been playing with Firefox Ubiquity add-in for the past month and found myself using these commands:

define (def) word
Gives definition of a word in Ubiquity popup.
map <location>
Shows Google Map in Ubiquity popup. If you press Enter, it opens Google Maps in a new tab.
tab <tab name>
Displays the named tab. For example, tab gmail would display the Gmail tab. Useful if when I open too many tabs and can't see tabs that are off-screen.
translate (tr)
Translate selected text to English in Ubiquity popup. I browse Malaysian news sites but my BM is rusty, so I like to check that I read some text correctly. The translation fails if there are proper names in the start of the text, so I still have to visit a translation site.
twitter (tw)
Update your Twitter status. You have to provide Firefox with your Twitter user name and login to send the update.

2009-01-22

Firefox spell check requires dictionary

Maria H.'s version of Firefox didn't highlight misspelt words in multi-line fields, although the Check my spelling as I type option is checked. I found that I had a English / United States dictionary installed (probably from a previous installation) while she didn't, so the spell check worked on my PC but not on hers. It seems that the Firefox spell checker only works after you install a dictionary; another one of those things that are obvious in hindsight.

2008-11-28

Theme a site with Greasemonkey and Stylish

Motivated by Gmail's Terminal theme, I hacked a similar theme for an internal Web site using Firefox's Greasemonkey and Stylish add-ins. My approach was to write some small Greasemonkey scripts to touch up different parts of all pages independently, then use Stylish to apply style definitions (the theme) from one CSS file. If you want to create another theme for this site, just create a new CSS file.

  1. First, I identified logical components of each web page, for example navigation bar, header, footers, forms and tables.
  2. Wrote a Greasemonkey script for each logical component that:
    1. Removed any physical formatting such as border or bgcolor.
    2. Labelled each component with an ID and / or a class name.
  3. When naming each script, prefixed each script name with the site name to make them easy to find in Greasemonkey's Manage User Scripts dialog.
  4. Configured Greasemonkey's Included and Excluded pages to call each script as required.
  5. Wrote a site-wide CSS file, using the IDs and class names that were previously defined.
  6. Added the CSS file to Stylish. The CSS file name is prefixed with the site and theme name.

Instant theme!

See Also

2008-10-25

Reusing Custom Page Styles With @-moz-document

After using the Firefox Stylish add-in to increase the contrast between the text and background colours of domains, I wanted to apply the same rule to different domains. In this case, I want to reuse the text colour of P elements in two or more domains.

Open a Stylish script and note that it has a sequence of @-moz-document definitions, for example:

@-moz-document domain(addons.mozilla.org) {
  p { color : black; }
}

@-moz-document domain(msdn.com) {
  p { color : black; }
}

The @-moz-document rule can accept a comma-separated URL list, so I can re-use my style definition like this:

@-moz-document domain(addons.mozilla.org), domain(msdn.com) {
  p { color : black; }
}

See Also

2008-09-30

Black Text, Please

It makes my eyes water to read grey text on a white background, so much so that I was motivated to learn how to use the Greasemonkey Ain't It Readable script to set text in <p> elements to black. Using Greasemonkey just to set a single CSS attribute was an overkill, so I turned it off and wrote this rule for the Stylish add-in: p { color:black; }.

See Also

2008-08-15

Firefox Unexpectedly Popular

Falls in the use of older versions of MSIE are always offset by rises in use of newer versions and some rise in the use for other browsers. The July 08 browser statistics for W3 Schools show that the use of all versions of MSIE fell 2.0% while use of Firefox rose 1.6% (and Opera gains 0.2%). Has the use of MSIE7 peaked? (Insert usual caveats about selective audience of this site, monthly fluctuations, rounding errors, yada yada.)

2008-07-05

Browser Usage Forecast

W3Schools Browser Statistics page shows that in June 2008, 41% of hits came from developers using Firefox and 53.5% from developers using MSIE7 or MSIE6.

What would the list be like at the end of this year? IE7 should cross 30%, IE6 to be about 22% and IE5 may disappear from the list. Unlike IE5, Moz could be barely be on the list because the number of hits is declining slower than IE5. FF may cross 43%, after the jump caused by the release of FF3 in June has been absorbed. Opera and Safari will noodle along at about 5% in total.

Enough crystal ball gazing …

2008-06-27

Firefox 3 SVG Performance Improvement

I did a quick check of my SVG Game of Life demonstration with Firefox 3 and found that it ran much faster compared to Adobe's ancient SVG Viewer 3.03 (ASV). The performance ratio used to be roughly 3:2 in favour of Firefox. Now, it's close to 5:1!

The raw numbers on the same computer: 24-27 fps on Firefox 3, 5-6 fps for MSIE6 + ASV.