Monday 1 October 2007

Preventing javascript redirection

For some reason, I wasted a lot of time this afternoon trying to make use of Firefox customisability in order to avoid having to log into Gamasutra in order to view the articles. I have no idea why, the article I was trying to get to, I didn't find interesting when I eventually got to see it. But I feel obliged to document the process for future reference.

When you visit an article on Gamasutra, it loads the page you want to see and in the process executes some javascript which checks if you have a cookie set and if not redirects you to its login page. I wanted to do something to disable this redirection.

var login_link = "https://www.gamasutra.com/php-bin/login.php...

//if the Gama Demo string does not exist, send them to login screen
if (pos == -1)
location.href = login_link
else {
My first attempt was in installing Greasemonkey. This seems to get invoked after the page has been loaded, at which point the redirection is already in progress. I could change the document.location value back to what it was being redirected from, but this just resulted in an infinite loop of redirection. I could catch the unload event and tell the browser to stop with window.stop(), but it seemed to stop after the redirection had started giving a blank page. Unless there is a formal way to stop what a previous assignment to document.location starts, Greasemonkey doesn't get invoked soon enough to help here.

The next attempt was with something I stumbled across when googling for "redirection". Firefox security policies. These have no user interface, but seem to be fully implemented. They enable you to do things like disable javascript for all sites or specified sites. Or disable access to various parts of the DOM, like document.location.

These lines would be added to a user's "prefs.js" file ("nogo" is just the random name I gave the profile myself):
user_pref("capability.policy.nogo.location.set", "noAccess");
user_pref("capability.policy.nogo.sites", "http://www.gamasutra.com");
user_pref("capability.policy.policynames", "nogo");
However, I could see myself wondering why the Gamasutra website wasn't working properly, so I just went with disabling javascript instead:
user_pref("capability.policy.nogo.javascript.enabled", "noAccess");
user_pref("capability.policy.nogo.sites", "http://www.gamasutra.com");
user_pref("capability.policy.policynames", "nogo");
More information on customising Firefox security policies can be found here.

Sunday 30 September 2007

Vista explorer fixes

I use the explorer to browse directories a lot and in Vista which I had no choice but to get with my laptop, this is horribly broken.

There are two symptoms I see:

  • When I enter a directory it has reverted away from the Details view to whatever the icon default view is (not one I find usable).
  • When I enter a directory the files slowly appear one by one over the course of up to half a minute. While this is happening, a gray progress bar fills out in the address field at the top of the window and the disk is hammered with activity. I can abort this activity by pressing escape, but then I do not see whatever files haven't been listed yet.
I have finally found a partial solution for the former and a full solution for the latter in this forum post:
Set the list view for a folder that's using the 'All Items' template, then
use 'Apply to Folders'. Then override content-sniffing with my 'AllFolders'
regedit:

Copy the text between the lines below into notepad & save as a .reg file.
Watch out for line wrap -- [HKEY_CURRENT_USER\...\Shell] is all one line,
there is a space between 'Local' and 'Settings'.

--------------------------------------------------
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Local
Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell]
"FolderType"="NotSpecified"
--------------------------------------------------

Merging the .reg file will set the 'All Items' template for any folders that
don't currently have a view saved with a different template. You can clear
all saved views by deleting the

"HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags"

key BEFORE merging the .reg file. If any folders open with a different
template after clearing the 'Bags' key & merging the .reg file, they most
likely have a template specified via their desktop.ini file.
Basically there is some mechanic which determines what kind of folder a directory is considered to be. If it is a folder for a kind of media, it will go through and read in all the files in that folder extracting information you do not know or care about so that it can be ready in the event you do. If you have the Windows Search indexing enabled, it might not do this every time explorer views the directory. But let's face it, search functionality in Windows never seemed to find what I want and in my experience with Vista it still doesn't. Enabling something which does nothing worthwhile is a choice I choose not to make.

When I select some directories I still see the wrong view, but it is much less often.

I only hope I can find fixes for all the other aspects of explorer which obstruct usability.