Tab Aliaser 2
Friday, January 4, 2008 10:54:45 PM
Tabs are narrow, and titles often are long - so you can end up looking at the beginning of a name and wondering what the page is. Here are two solutions: an alias dictionary to permanently give webpages short, clear names or trim off clutter, and a temporary aliaser (from AyushJ) that lets you rename, label or annotate tabs on the fly.
One use is to reduce some tabs to just a favicon, like Firefox's Faviconize and Chrome's Pin Tab (a button for that: Nameless; reload page to restore name), making things very compact, if you edit your skin file to reduce minimum tab width:

(Tab Aliaser 1 - a clunky method which originally motivated this post, and does have a certain warped charm - is included as a historical artifact.)
Obviously, any browser maker could put an Alias option on the right-click menu for tabs. Why don't they? Well, people don't demand what they haven't learned to value, and resources are limited. Opera has often been a pioneer; in this matter, Maxthon has that role. Whether it will catch on is unclear: but it's definitely worthwhile. My tab bar is much more useful now, and I wouldn't be happy if my name-trimmers were taken away.
1. Alias dictionary
This is a user javascript file. They specify changes for the browser to make to pages during rendering. (Opera runs every script in your userjs folder every time a page is loaded.) The dictionary is just a set of rules that tell the browser to check the URL and title of the webpage being loaded, and to change the title if one of the specified conditions is met.
To set it up, you must have a userjs folder and user javascript switched on, as detailed here. Then make an "alias dictionary.js" file. Here's a sample dictionary that can serve as a template, demonstrating three useful types of commands which will cover most needs:
document.addEventListener('DOMContentLoaded',function() {
if (location.href=='http://jkkmobile.blogspot.com/')document.title='alias1';
if(location.href.indexOf('bpm/blog/index.dml/tag')!=-1)document.title=location.href.slice(39);
if (document.title.indexOf('Wikipedia, the f') !=-1)document.title = document.title.slice(0,-23);
}, false);
- first line: the event listener causes a pause until the page is done loading, ensuring that your alias doesn't get overwritten. Without it, aliasing works only sometimes.
- second line: "href" is the javascript term for URL. This is the type of IF condition that specifies an exact match for a full URL - the rule works for just one page.
- third line: (this fixes a flaw in MyOpera blog software: click a tag, and the title of the listing page is posts tagged "" - omitting the actual word.) "indexOf" asks where in a tested string T (the URL in this case) a search string S is located. It returns -1 if S is not in T, and the number of characters before S if it is in T. ! means "not", so !=-1 means S is present. So the IF condition is, "if the string 'bpm/blog/index.dml/tag' is in the URL", and the rule slices the actual tag out of the URL and makes it the new title.
- fourth line: this IF condition specifies presence of a string in page name, not URL. The slice command (syntax described below) trims the title; the rule chops ", the free encyclopedia" off each Wikipedia tab.
- last line: the "false" is a javascript quirk which means nothing much, but must be there.
- change minimum tab width in skin file by unzip/edit/rezip - details here.
Copy the sample rules as often as needed, replacing the variables marked in red to adapt them to your own needs. (It's safest to copy and paste the line, and modify only the variables. Javascript is finicky; for example, the O in indexOf has to be a capital.) You can have as many rules as you like.
slice syntax
In English the sample rule is, "if the Wikipedia slogan is present in the name, chop off the last 23 characters." The function can trim from either end:
- slice(7) cuts first 7.
- slice(-7) keeps last 7.
- slice (0,-7) cuts last 7.
- slice (a,-b) cuts a from left and b from right.
- slice (a,b) cuts a, keeps b. So (0,7) keeps first 7.
2. AyushJ's temporary aliasera terrific function which turns the tab into an editable field: a prominent little note you're free to use any way you like. Click the button, an alert box pops up; put in whatever you like, hit Enter - and it appears on the tab. Reload to erase the alias. Takes a bit of thought to appreciate the opportunities this gives. To the left is an image - a vertical tab bar, turned into a notepad. It (perhaps fancifully) shows one of my data-URL divider pages in use, and descent indicators - • and ¶, one for the parent, two for the children. Tabs can be marked with status indicators (e.g. + if there are links of interest); tab bar can be an organizing tool. Also, in Windows panel, Quickfind can be used to show only tabs with particular group markers on them: instantly eliminating clutter, showing only what you want to see. And (also in Windows panel) alphabetic sort can organize the listing into groups. Not that anyone will do it, of course.
Another benefit: you can give a page a good short name before you drag its tab to a toolbar to make a link button - the alias is what will be used as the link-button name.
Three access options:
- button (drag link to toolbar): Alias
- rightclick menu for tabs: copy this line into your Tab Bar Item Popup Menu:
Item, "alias tab"=go to page, "javascript:document.title=prompt('Title:',document.title)||document.title;void 1",1,,"contact4" - bookmarklet (works outside of Opera too): paste into address field of a bookmark: javascript:document.title=prompt('Title:',document.title)||document.title;void 1
3. (obsolete) Tab Aliaser 1
This technique (prompted by a request on the Opera forums) used three tricks. The first trick repurposed an old-fashioned form of webpage construction known as frames. Frames are used to display multiple web documents (each of which is actually a distinct HTML page) on a single display page. The crucial fact for this purpose was that there is a frameset page which has no content itself but acts as a host and organizer for other pages. The trick was to use a frameset page for no reason except that one got to name it. It only called one page, and therefore didn't do the thing frames were designed to do: an invisible wrapper with a name one could pick. The whole page is one line: here's the general form:
<title>Alias</title><frameset><frame src="url"></frameset>(To create one manually, and see what the method automates: create a blank page (F2, type "opera:blank", Enter), go to View Document Source (View,o or Ctrl+F3) so you can edit, delete everything (Ctrl+u), paste in the above line and swap in an actual alias and URL. Then, when you hit the "save changes" button, you will see the URL open under the alias you have given it.)
The second trick - which eliminated the need to store wrappers as files - was the use of a data URL: a URL which doesn't point to a webpage, but instead contains the data to form a page image. Opera understands them; as of now anyway, Internet Explorer does not. Here's a very simple one: hello page. Hover to see the code, click to generate a one-word page.
So - the idea was to create bookmarks or links with data URLs which generated frameset pages hosting pages one wanted to see. Here's an example: a link to my.Opera.com, aliased Fred. If you hover it, the URL you'll see in tooltip or status field is a data URL (with "%xy" escape sequences standing in for certain symbols). If you click it, you'll get the my.opera.com page - but with "Fred" on the tab, and the data URL in the address field. And if you use "View document source" to find out what's going on, you'll see the source - not for the displayed page - but for the wrapper:
<title>Fred</title><frameset><frame src="http://my.opera.com"></frameset>The third trick, contributed by Shoust, was the bookmarklet: a little javascript program which goes in the address field of a bookmark, and is run by clicking the bookmark. Here, it automated assembly of the data URL: prompting for an alias, and pasting it and the URL of the current page into a template.
Setup: make a bookmark named "aliaser", copy this:
javascript:var alias=prompt('Enter alias (page will reload)','');var content='<title>'+alias+'</title><frameset><frame src="'+location.href+'"></frameset>';location.href='data:text/html,'+escape(content);and paste it into the address field. Then click it to alias the current page. A dialog comes up, you enter the alias - and the page reloads under its alias before your very eyes!To make an alias permanent, bookmark the aliased page, or make a link by dragging from the tab to a toolbar. It will be a data-URL bookmark or link, generating a wrapper each time it's used.
Something to be aware of: a link from an aliased page opened in the same tab will open in the frame and keep the alias. To bail out and restore the page to normalcy (with the author's title), the command is "maximize frame"; it's available via the rightclick menu (Frame submenu) - and here's a button as well, which also works as a frame detector (it's dimmed unless the cursor is in a frame): unalias







nizamx # Tuesday, August 5, 2008 8:21:28 PM
bpm # Tuesday, August 5, 2008 8:28:22 PM
nizamx # Wednesday, August 6, 2008 11:03:56 AM
aparente001 # Saturday, August 1, 2009 4:28:43 PM
ValleB # Monday, November 2, 2009 1:21:27 AM
one thing. the bookmarklet by shoust isn't working. the code simply doesn't make its job. now it works:
javascript:var alias=prompt('Enter alias (page will reload)','');var content='<frameset><frame src="'+location.href+'"></frameset>';location.href='data:text/html,<title>'+alias+'</title>'+escape(content);bpm # Wednesday, November 4, 2009 4:17:44 AM
But you should switch to the userjs dictionary - much cleaner method.
Franksv-chamelea # Wednesday, February 24, 2010 11:44:12 AM
bpm # Wednesday, February 24, 2010 1:12:31 PM
r-a-y # Tuesday, November 23, 2010 11:08:53 PM
Great for labelling your tab stacks!