K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmOpenLinksAsTabs

Submitted by: JamesD and desga2



Notes:

Opens each link on a page in a new tab. Note that there are strict rules for the type of links and all pages may not pass.


This is based on an original work by jsnj which was then updated by desga2. The change is to open links in tabs rather than windows.

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file(s):

KmmOpenLinksAsTabs.kmm

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- OpenLinksAsTabs ---------------------------------------------------
#
# Dependencies        : main.kmm, Ver. 1.5.x, Tabs
# Resources           : -
# Preferences         : "browser.link.open_newwindow", 
#                       "browser.link.open_newwindow.restriction",
#                       "dom.disable_open_during_load"
# Version             : 0.0  2/24/09  JamesD & desga2
# -----------------------------------------------------------------------------

_OpenLinksAsTabs{
# Obtain current window diversion values:
$_PUB_value1 = getpref(INT, "browser.link.open_newwindow");
$_PUB_value2 = getpref(INT, "browser.link.open_newwindow.restriction");
$_PUB_value3 = getpref(BOOL, "dom.disable_open_during_load");
# Change window diversion values if needed
$_PUB_value1 != 3 ? setpref(INT,"browser.link.open_newwindow", 3):0 ;
$_PUB_value2 != 0 ? setpref(INT,"browser.link.open_newwindow.restriction", 0):0 ;
$_PUB_value3 != false ? setpref(BOOL,"dom.disable_open_during_load", false):0 ;
# Open all links in page:
&_OpenLAT;
id(ID_TAB_LAST);
# Restore current window diversion value:
$_PUB_value1 == getpref(INT, "browser.link.open_newwindow") ? 0: setpref(INT,"browser.link.open_newwindow", $_PUB_value1) ;
$_PUB_value2 == getpref(INT, "browser.link.open_newwindow.restriction") ? 0: setpref(INT,"browser.link.open_newwindow.restriction", $_PUB_value2) ;
$_PUB_value3 == getpref(BOOL, "dom.disable_open_during_load") ? 0: setpref(BOOL,"dom.disable_open_during_load", $_PUB_value3) ;
}

_OpenLAT{
injectJS("javascript:(function(){var n_to_open,dl,dll,i; function linkIsSafe(u) { if (u.substr(0,7)=='mailto:') return false; if (u.substr(0,11)=='javascript:') return false; return true; } n_to_open = 0; dl = document.links; dll = dl.length; for(i = 0; i < dll; ++i) { if (linkIsSafe(dl[i].href)) ++n_to_open; } if (!n_to_open) alert ('no links'); else { if (confirm('Open ' + n_to_open + ' links in new tabs?')) for (i = 0; i < dll; ++i) if (linkIsSafe(dl[i].href)) window.open(dl[i].href); } })();");
}

_OpenLinksAsTabs_BuildMenu{
# Add "Open Links in Tabs" option to tab bar right click context menu:
$kTabs==true ? setmenu("NavTab",macro,_("Open Links in Tabs"),"_OpenLinksAsTabs",4):0;
# Add "Open Links in Tabs" option to right click context menu:
$kTabs==true ? setmenu("Nav",separator, -1):0;
$kTabs==true ? setmenu("Nav",macro,_("Open Links in Tabs"),"_OpenLinksAsTabs"):0;
}

$OnInit=$OnInit."_OpenLinksAsTabs_BuildMenu;";
$macroModules=$macroModules."OpenLinksAsTabs;";


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.