Arena - blog

Los amigos del barrio pueden desaparecer, pero los dinosaurios van a desaparecer

Subscribe to RSS feed

Posts tagged with "userjs"

UserJS fix for Yahoo images search

, ,

Some time ago I wrote a script to "fix" links in AlltheWeb Image search results pages. Yahoo has exactly the same problem (namely, unreadable links) so I wrote another UserJS for this case. It also makes the links to context pages clickable and, most importantly, removes the horizontal scrollbar (and the need to scroll horizontally, of course smile). For anyone who's interested:

fix-yahoo-images-search
Btw, there's another script in this "series" available on userjs.org: Google Image frame bypasser by GreyWyvern

Driving directions: departure address

, , , ...

I do have a car, but I don't have a navigation system. I therefore use one of the many online services to get driving directions, but I don't always use the same service. That's because the one I usually prefer (Map24) sometimes crashes Opera and doesn't know new roads. For example, not so long ago it would still let you follow the Belgian coast to go from Amsterdam to Brest even though taking the A29 through Amiens would save you lots of kilometres. Moreover, their new beta doesn't work in Opera 8.54 and doesn't show maps in Opera 9. So I'm forced to switch to anwb.nl, mappy.com, viamichelin.com or one of many similar sites.

When getting driving directions from such a website, I mostly use my home address as the departure address, so I figured it would be nice to have the site remember that info. A cookie set by the website wouldn't work too well because I delete cookies when I close Opera. UserJS was my next option.

After examining a few dozens of route planners, I found out they all use code similar to this:
<label for="startStreet">Street:</label> <input type="text" name="startStreet">
<label for="startCity">City:</label> <input type="text" name="startCity">
<label for="startZip">Zip:</label> <input type="text" name="startZip">
<label for="startCountry">Country:</label> <select type="text" name="startCountry">...</select>

Of course, they all use different names for their elements; some sites use the id attribute instead. Some let you enter a State or Province (using either an <input type="text"> or a <select>); others ask for the house number and street name separately.
In short, there's little the route planners agree on.

And then there was another problem I had to solve if I wanted to write a script that would work with them all: in The Netherlands, the house number comes after the street name; in the US, they're reversed. In France, they put a comma between them. Furthermore, a French route planner may know what "Norvège" is, but a British one can only work with "Norway".

Finally, this is what I've done:

I have written a JS function that will figure out which element types have been used to contain the address info. Its input parameters are the names or id's of these elements. The function will get the correct information from an array that stores the street name, house number, zip code, city, state and country separately. The country is again an array consisting of several equivalents (in different languages, for instance). The user also sets what the right street address notation is (which can be overridden for specific sites)

Once I completed the function, it was relatively easy to make it work on the following sites (note that some pages simply use some other site's route planning service):
1bis
411.info
9292ov.nl
The AA Route Planner
Abacho.de
Allianz Routenplanung
Anwb.nl
AOL Travel
Aral Routenplaner
Auskunft.ch
Autobahn Tank & Rast
Autoroutes.fr
Autostadtplan.de
Bayerninfo.de
bottin.fr
BP The Netherlands
BP Route Finder
CNN Driving Directions
CompuServe Routeplanner
Deutscher Stadtplandienst
Drive Alive! Route Planner
Expedia
Fahrinfo Berlin
Falk.de Routenplaner
Free.fr Itinéraires
Freetrip.com
Google Maps
Green Flag Route Planning
Guia Campsa
InfoSpace
Iti.fr
KataWeb.it Mappe
klickTel.de
LeasePlan Nederland
Letsmove.be (also in French)
Lycos.de Routenplaner
Lycos.nl Routeplanner
Map24
Maporama.com
Mappy.com
MapQuest.com
Maps.com
Maps On Us
MSN Mappoint / Mapblast
Multimap.com
Onde Estou.br
Opel Route Planner
Planet.nl
QDQ.com
RAC Route Planner
Rand McNally Maps & Directions
RATP.fr
Reiseplanung.de / Routenplanung.de
Routemaster.nl
Routenet.nl / Routenet.be
Routenplaner-online.com
Routenplaner24.de
Routeplannerplaza.nl
Strassenroutenplaner.de / Strassenkarten-Europa.de
SuperPages.com / BigBook.com
T-Mobile Routenplaner
Terra.es Callejero
Touring.be (also in French)
Travelmate.com.au
VanAnaarB.nl
Veturo.com
Vialys.fr
ViaMichelin.com
Volkswagen.de Routenplaner
VTB/VAB.be (also in French)
Wanadoo.fr
Wanadoo.nl
Wannahaves.nl
Web.de
Yahoo! Deutschland Routenplaner
Yahoo! Driving Directions
Yahoo! France

T-Mobile.nl says it doesn't support Opera

, ,

T-Mobile.nl redirects Opera users to a page saying that other browsers than IE5.01, IE5.5 and Netscape 6 are not supported. This warning will only be given once, so you can return to the main page (by modifying the address in the address field or by clicking on the logo - there's no obvious link on the page) and continue browsing without any problems.
A cookie remembers whether you've seen the error page before. So if you are not interested in keeping t-mobile's cookies, you'll be redirected more often than necessary. Here's a little UserJS that wil always skip that page:

if (window.location.href.indexOf('http://www.t-mobile.nl/global/htdocs/page/browser_not_supported.asp')>-1){
    window.location.replace('http://www.t-mobile.nl/')
}

UserJS - Skip Hotmail's Today page

, ,

This script immediately redirects the user to Hotmail's Mail tab (the inbox page) when he signs in. This way the Hotmail Today page (the regular "front page" that tells you how many messages you have) is skipped.

if (window.location.href.match(/http:\/\/(\w+\.){0,2}hotmail(\.msn)?\.com\/cgi-bin\/hmhome\?/)){
    if (document.referrer=='' || document.referrer.match(/http:\/\/login.passport.net\/uilogin/))
        location.href=location.href.replace('hmhome','HoTMaiL');
}



If referrer logging is enabled in Opera, the script will redirect the user only when he logs in; Opera Today can then be visited by clicking on the appropriate link. If referrer logging is disabled, Opera Today becomes virtually unreachable, as clicking on the link will automatically send the user to his inbox. All information displayed on that page is available elsewhere on Hotmail, though.

UserJS: Disable OperaShow

, ,

This script will "convert" OperaShow into Fullscreen mode, i.e. ignore stylesheets for media='projection' when you enter Fullscreen mode.

document.addEventListener(
  'load',
  function(){
    var l=document.getElementsByTagName('link'); 
    var s=document.getElementsByTagName('style');

    for (var i=0; i<s.length; i++){
      if (s[i[b][/b]].hasAttribute('media')){
        if (s[i[b][/b]].getAttribute('media').indexOf('screen')>-1 && s[i[b][/b]].getAttribute('media').indexOf('projection')==-1)
          s[i[b][/b]].setAttribute('media',s[i[b][/b]].getAttribute('media')+',projection'); 
        if (s[i[b][/b]].getAttribute('media').indexOf('projection')>-1 && s[i[b][/b]].getAttribute('media').indexOf('screen')==-1) 
          s[i[b][/b]].setAttribute('media',s[i[b][/b]].getAttribute('media').replace('projection','OperaShow'));
      } 
    }

    for (i=0; i<l.length; i++){
      if (l[i[b][/b]].hasAttribute('rel') && l[i[b][/b]].hasAttribute('media')){
        if (l[i[b][/b]].getAttribute('rel')=='stylesheet' && l[i[b][/b]].getAttribute('media').indexOf('screen')>-1 && l[i[b][/b]].getAttribute('media').indexOf('projection')==-1)
          l[i[b][/b]].setAttribute('media',l[i[b][/b]].getAttribute('media')+',projection');
        if (l[i[b][/b]].getAttribute('rel')=='stylesheet' && l[i[b][/b]].getAttribute('media').indexOf('projection')>-1 && l[i[b][/b]].getAttribute('media').indexOf('screen')==-1) 
          l[i[b][/b]].setAttribute('media',l[i[b][/b]].getAttribute('media').replace('projection','OperaShow'));
      }
    }
  },
  false
); 

AllTheWeb images search

, ,

When I do image searches with AllTheWeb, the status field displays a long url starting with http://av.rds.yahoo.com/ when I hover over the thumbnails and links. There's no way to see where the link will eventually lead to, even though the links all have an onmouseover attribute like this: "self.status='http://www.blezer.tmfweb.nl/trip2%27;return true".
I guess that Opera ignores that status text for security reasons, but as I said, it makes it impossible to know where you'll end up. I've written some UserJS (and looked at GwenWyvern's Google Image frame bypasser for an example) to fix this:

if (window.location.href.match(/http:\/\/www.alltheweb.com\/search.+cat=img/)) {
  window.opera.addEventListener(
    'AfterEventListener.load',
    function(){var s=document.getElementsByTagName('a');for (var i=0; i<s.length; i++){if (s[i[b][/b]].className=='thumbnail'){s[i[b][/b]].href=s[i[b][/b]].getAttribute('onmouseover').replace(/self\.status='(.+)';return true/,'$1');}}}, 
    false); 
}

Sony.com menu fix

, ,

EDIT: Sony have updated their Ultimate Dropdown Menu to version 4.42 and now support Opera 8.x.

Sony.com uses the Ultimate Dropdown Menu, but unfortunately they haven't upgraded it to the latest version supporting Opera 8. Therefore, I wrote the following UserJS fix:

if (window.location.href.indexOf('http://www.sony.com')>-1){
    window.opera.addEventListener(
        'BeforeScript',
        function(ev){if(ev.element.text.indexOf('um.o7=')>-1){ev.element.text=ev.element.text.replace(/um\.o7\)\{.*?\}/,'um.o7){um.o75=true;um.o73=true;um.o71=false;}')}},
        false);
}

UserJS for regional newspapers

, ,

When one publisher owns a couple of regional newspapers, it is to be expected that all related sites will use the same methods to annoy Opera users. The script to fix the issue is shorter than the list of sites to which it applies smile
I haven't been able to get it working using the easiest method to list the relevant websites, namely

// ==UserScript==
// @include...
// ==/UserScript==

But the script below does the trick anyway:

if (window.location.href.indexOf('http://www.leidschdagblad.nl')>-1 || window.location.href.indexOf('http://www.limburgsdagblad.nl/')>-1 || window.location.href.indexOf('http://www.telegraafholding.nl')>-1 || window.location.href.indexOf('http://www.hdcmedia.nl')>-1 || window.location.href.indexOf('http://www.limburgadverteren.nl')>-1 || window.location.href.indexOf('http://www.nhd.nl/')>-1 || window.location.href.indexOf('http://www.gooieneemlander.nl/')>-1 || window.location.href.indexOf('http://www.haarlemsdagblad.nl/')>-1 || window.location.href.indexOf('http://www.ijmuidercourant.nl/')>-1 || window.location.href.indexOf('http://www.dvhn.nl')>-1 || window.location.href.indexOf('http://www.vakantierecreatie.nl/')>-1 || window.location.href.indexOf('http://www.almerevandaag.nl/')>-1){
    window.opera.defineMagicVariable(
        'bSupportedBrowser',
        function(){return true;},
        null);
}

UserJS - Three fixes for one site.

,

Site: Huis-Aan-Bod

Problems:
1. Vertical text alignment: page contents are shifted to bottom of page
2. Navigation menu (CoolMenus 4.05 beta , feb 2002) doesn't work in Opera
3. Necessary pop-ups will be blocked by Opera unless it is set to allow all pop-ups. In other words: block unwanted pop-ups doesn't work

Fixes: Require the addition of the following lines of code to your UserJs file.

Fix for problem 1: Vertical text alignment is changed from "bottom" into "top".

// description: www.huis-aan-bod.nl - fix of (vertical) alignment of text
// last modified: 2005-04-02
if(window.location.href.indexOf('www.huis-aan-bod.nl')>-1){
	window.opera.addEventListener('AfterEventListener.load',function(ev){var str=document.body.getElementsByTagName('tr'); for(var i=str.length-1;i>=0;i--){if(str[i[b][/b]].getAttribute('valign')=='bottom'){str[i[b][/b]].setAttribute('valign','top')}}; },false);
}

Fix for problems 2 and 3: CoolMenus are replaced by a working CSS menu; login pop-ups are allowed regardless of Opera's pop-up settings.

// description: www.huis-aan-bod.nl - (1) allow login/logout popups on page regardless of popup settings in Opera & (2) fix of navigation menu
// last modified: 2005-04-04
if(window.location.href.indexOf('www.huis-aan-bod.nl')>-1){
  window.opera.addEventListener(
    'BeforeScript',
    function(ev){
      var str=ev.element.text; 
      /*(1)*/ 
      if (str.indexOf('function openWindow()')>-1){
        str=('http://www.huis-aan-bod.nl/'+ev.element.text.match(/\".*?\"/)).replace(/\"/g,'');
        ev.element.text='function openWindow(){}'; 
        window.open(str)
      } else {/*(2)*/ if (str.indexOf('Menu item creation')>-1){
        var mnu=new Array; 
        var i=0; var txt; 
        while(str.indexOf('oM.makeMenu')>-1){
          mnu[i[b][/b]]=str.match(/makeMenu.*?\);/)+'';
          str=str.replace(/makeMenu.*?\);/,'');
          i++
        }; 
        for (i=0;i<mnu.length;i++){
          if (mnu[i[b][/b]].indexOf('.gif')>-1){
            mnu[i[b][/b]]='<d[b][/b]iv class="ujsmnu"><[b][/b]a href="'+mnu[i[b][/b]].match(/mid[\d,]+/)+'"><i[b][/b]mg src="'+mnu[i[b][/b]].match(/imag.*?h\d\.gif/)+'"></[b][/b]a>';
          } else {
            txt=mnu[i[b][/b]].match(/,.*?,/)+''; 
            if(txt==",''," || txt.length==6){txt=''} else {txt=' class="ujssub"'}; 
            mnu[i[b][/b]]='<l[b][/b]i><a'+txt+' href="'+mnu[i[b][/b]].match(/mid[\d,]+/)+'">'+(mnu[i[b][/b]].match(/[^\']*?\',\'mid/)+'').replace("','mid","")+'</[b][/b]a></l[b][/b]i>';
          }
        }; 
        mnu[mnu.length-1]+='</d[b][/b]iv>'; 
        ev.element.text="document.write('<style type=\"text/css\">.ujsmnu {float:left; margin-left: 44px;} .ujsmnu + .ujsmnu {margin-left: 4px;} .ujsmnu ul {display:none;} .ujsmnu:hover ul {display:block; background: #cc6; list-style:none; position:absolute; margin: 0; z-index:2; border: solid 1px #787878; width: 154px; font-size: 11px;} .ujsmnu ul a, .ujsmnu ul a:visited {display: block; color: #000; text-decoration: none; font-family: arial,sans-serif; padding: 2px 4px;} .ujsmnu ul a:hover {background-color: #a0b39f;} .ujssub:before {content: \"- \";} .ujssub {padding-left: 12px !important; font-size: 10px; color: #1e4c4c !important}</style>')\n"; 
        for (i=0;i<mnu.length;i++){
          if(mnu[i[b][/b]].indexOf('<div')>-1 && i>1){
            if(mnu[i-1].indexOf('<li')>-1){
              mnu[i[b][/b]]='</[b][/b]ul></d[b][/b]iv>'+mnu[i[b][/b]];
            }else{
              mnu[i[b][/b]]='</[b][/b]div>'+mnu[i[b][/b]];
            }
          }; 
          if(mnu[i[b][/b]].indexOf('<di[b][/b]v')>-1 && i<mnu.length-1){
            if(mnu[i+1].indexOf('<li')>-1){
              mnu[i[b][/b]]+='<u[b][/b]l>';
            }
          }; 
          ev.element.text+="document.write('"+mnu[i[b][/b]]+"')\n"; 
        };
      }
    }
  },
  false);
}

UserJS again - fixing a broken site

, ,

Edit (2005-09-13): the site has been fixed.

The (2nd) largest Dutch university has an error in its portal for students that prevents Opera from showing the page correctly. Just visit www.student.uva.nl to see how the dropdowns fail to function. This can easily be fixed, but so far I haven't received a reply to my request for a change in their code. That's why I've written a small piece of userjs that does the webmaster's job.

Refer to the following MyOpera Forums threads for more details about the site:
http://my.opera.com/forums/showthread.php?s=&threadid=83669 (Dutch)
http://my.opera.com/forums/showthread.php?s=&threadid=83736 (English)
http://my.opera.com/forums/showthread.php?s=&threadid=84232 (English)

Here's the code you have to add to your UserJS file:

if(window.location.href.indexOf('www.student.uva.nl')>-1){
	window.opera.addEventListener('BeforeScript',function(ev){if (ev.element.text.indexOf('id="opleidingenbachelorsselect"')>-1 || ev.element.text.indexOf('id="opleidingenmastersselect"')>-1 || ev.element.text.indexOf('id="opleidingendoctoraalselect"')>-1 || ev.element.text.indexOf('id="opleidingenoverigselect"')>-1) {ev.element.text=ev.element.text+'document.wri[b][/b]teln("</sel[b][/b]ect>")[b][/b];';}},false);
}

First UserJS - avoiding browser sniffer on Trouw.nl

, ,

Edit: Trouw now has a new website with its own problems; the browser sniffer has been removed

Trouw.nl has a very annoying browser sniffer - one that has only three options: you're either IE, or Mozilla, or you don't support JavaScript. No need to explain Opera has troubles with the site. (Discussion in the Dutch part of the forums: <http://my.opera.com/forums/showthread.php?s=&threadid=67390>)

I took the UserJS file Rijk posted in his journal as an example (http://my.opera.com/Rijk/journal/54) and added a function that will let you use trouw.nl without having to id as IE. Take a look at Rijk's script to correctly interpret the following lines:

domainHandler['www.trouw.nl'] = screwSniffing01;

function screwSniffing01() {
	var str=document.body.getAttribute('onload');
	if(str.indexOf('ververs')>=0) {
		str=str.replace("ververs('","").replace("')","");
		location.replace(str);
	}
}

Of course, this is for OperaBeta 3+ only.