Tab aliaser

Rename webpages by page or site; trim repetitive clutter off names.

5-line alias dictionary gives you templates for three types of rules:

  • rules to alias single pages
  • rules to alias by site
  • rules to slice off slogans and other clutter that makes names too long.

document.addEventListener('DOMContentLoaded',function() {
if (location.href=='http://site.com/page') document.title='alias1';
if (location.href.indexOf('google.c') !=-1) document.title='alias2';
if(document.title.indexOf('Wikipedia, the free encyclopedia') !=-1) document.title = document.title.slice(0,-23)
}, false);

explanation (by line):

  1. event listener causes pause until page is loaded, so alias doesn't get overwritten.
  2. "href" is javascript for URL. This == rule specifies an exact match for a URL - works for just one page.
  3. "indexOf" asks where in a tested string T (the URL in this case) a search string S (google.c in this case) is located. Returns -1 if S is not in T, and number of characters before S if it is in T. ! means "not", so !=-1 means S is present. So the condition is, "if the string 'google.c' is in the URL", and the rule aliases any page from Google.
  4. this rule specifies presence of 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.
  5. "false"... must be there.

Copy sample rules as often as needed, replacing variables (green background) to adapt them to your own needs. Safest to copy and paste the line, and modify only the variables. 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


Syndicate content

Tested with Opera version(s): 
9.5
10.x
No votes yet

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Formatting

Green background didn't work.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.