keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
Post Reply
t3l0zvxqIiXuzuH0
Posts: 92
Joined: August 17th, 2014, 5:57 am

Re: keyconfig 20110522

Post by t3l0zvxqIiXuzuH0 »

rejlan givens wrote:Hi everyone,

The functions for closing all tabs, left tabs and right tabs do not work without the TabMix add-on installed:

gBrowser.closeLeftTabs(gBrowser.mCurrentTab);
gBrowser.closeRightTabs(gBrowser.mCurrentTab);
gBrowser.closeAllTabs();

I wonder if it is possible for these to work without having to instal TabMix or any other additional add-on? Or is it possible to make at least "Close other tabs" and "Close tabs to the right" from the Firefox tab context menu work without installing TabMix?

Thank you for the help.

Try these:

Close Right Tabs

Code: Select all

var n = gBrowser.mCurrentTab._tPos;
var i = gBrowser.mTabContainer.childNodes.length - 1;
while (i > n)
 { var tab = gBrowser.mTabs[i];
   gBrowser.removeTab(tab);
   i = i - 1; }

Close Left Tabs

Code: Select all

var i = gBrowser.mCurrentTab._tPos - 1;
while (i >= 0)
 { var tab = gBrowser.mTabs[i];
   gBrowser.removeTab(tab);
   i = i - 1; }

Close All Tabs

Code: Select all

var i = gBrowser.mTabContainer.childNodes.length - 1;
while (i >= 0)
 { var tab = gBrowser.mTabs[i];
   gBrowser.removeTab(tab);
   i = i - 1; }

Close Other Tabs

Code: Select all

var n = gBrowser.mCurrentTab._tPos;
var i = gBrowser.mTabContainer.childNodes.length - 1;
while (i >= 0)
 { var tab = gBrowser.mTabs[i];
   if (i != n)
    { gBrowser.removeTab(tab); }
   i = i - 1; }
rejlan givens
Posts: 11
Joined: December 9th, 2014, 1:35 am

Re: keyconfig 20110522

Post by rejlan givens »

Thank you very much for the codes t3l0zvxqIiXuzuH0, each works like a charm!
DlGMartin
Posts: 1
Joined: March 20th, 2015, 3:17 pm

Re: keyconfig 20110522

Post by DlGMartin »

Hello.
I have two problems, help please with a little help:

1. I have trouble with "right click, "Copy Image Location".
For keyconfig I know it is gContextMenu.copyMediaLocation().
But I cant make it work, is nothing in clipboard.

2...and with right click, "Start saving image with dTa OneClick".
I want to assign a shortcut with keyconfig, but with dTa commands is very difficult (for me).
K4RBQT99
Posts: 284
Joined: November 11th, 2010, 3:23 pm

Re: keyconfig 20110522

Post by K4RBQT99 »

I'm building a shortcut to focus the existent private window, or only if it doesn't exist, open a new:

Code: Select all

let em = Services.wm.getEnumerator("navigator:browser");
let found = false;
while (em.hasMoreElements()) {
    let win = em.getNext();
    if (PrivateBrowsingUtils.isWindowPrivate(win)) {
        win.focus();
        found = true;
        break;
    }
}

if (!found)
    OpenBrowserWindow({private: true});

But after assigning it a key combination, the shorcut doesnt' work: the console report me a syntax error (?); I try the same code triggered via a new internal command in some other extension and It works; I'm not sure where is the problem here. Can somebody to try it at least and confirm me if it works?
morat
Posts: 6394
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@DlGMartin

Here is a gContextMenu example.

Code: Select all

// left click image - open image in current tab
// left click image with ctrl - open image in new tab in foreground
// left click image with ctrl and shift - open image in new tab in background
// left click image with shift - open image in new window
// middle click image - same as left click with ctrl
function handleClick(event) {
  window.removeEventListener("click", handleClick, true);
  event.preventDefault();
  event.stopPropagation();
  document.popupNode = event.originalTarget;
  var menuPopup = document.getElementById("contentAreaContextMenu");
  var shiftKey = false;
  gContextMenu = new nsContextMenu(menuPopup, shiftKey);
  if (gContextMenu.onImage) gContextMenu.viewMedia(event);
  else if (gContextMenu.hasBGImage) gContextMenu.viewBGImage(event);
  gContextMenu = null;
}
window.addEventListener("click", handleClick, true);

dorando wrote:AFAIK it is currently impossible to determine over which element the mouse is from within a XULCommandEvent, so keyconfig can't do it alone.

viewtopic.php?f=48&t=72994&start=1485

@K4RBQT99

Try this:

Code: Select all

var em = Services.wm.getEnumerator("navigator:browser");
var found = false;
while (em.hasMoreElements()) {
  var win = em.getNext();
  if (PrivateBrowsingUtils.isWindowPrivate(win)) {
    win.focus();
    found = true;
    break;
  }
}
if (!found) OpenBrowserWindow({private: true});
morat
Posts: 6394
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

In case anyone is interested, here is a fix for the following error in keyconfig 20110522.

Error: TypeError: props is undefined
Source file: chrome://keyconfig/content/keyconfig.js
Line: 420

Remove nsISupportsArray usage from nsITreeView
http://bugzilla.mozilla.org/show_bug.cgi?id=407956

Setting Properties for the Custom View
http://developer.mozilla.org/en/XUL_Tut ... ing_a_Tree

Fix for style bug:

Code: Select all

getRowProperties: function(row) { return this.getCellProperties(row, ""); },

getCellProperties: function(row,col) {
 var key = gKeys[row];
 if(key.hardcoded) return "hardcoded";
 if(key.disabled) return "disabled";
 if(key.pref[3]) return "custom";
 if(key.pref.length) return "user";
 if((col.id || col) == "shortcut" && gUsedKeys[key.shortcut].length > 1)
  return "duplicate";
 return "";
},

getColumnProperties: function(col,colElement) { return ""; },

Tweak for style bug:

Code: Select all

treechildren::-moz-tree-cell-text(hardcoded) {
 color: darkorange;
}

treechildren::-moz-tree-cell-text(disabled) {
 color: red;
}

treechildren::-moz-tree-cell-text(custom) {
 color: magenta;
}

treechildren::-moz-tree-cell-text(user) {
 color: deepskyblue;
}

treechildren::-moz-tree-cell-text(duplicate) {
 background-color: Highlight;
 color: HighlightText !important;
}

treechildren::-moz-tree-cell-text(selected, duplicate) {
 background-color: HighlightText;
 color: Highlight !important;
}

unzip keyconfig.xpi keyconfig.zip
unzip keyconfig.zip content\keyconfig.js
unzip keyconfig.zip skin\keyconfig.css
notepad content\keyconfig.js
notepad skin\keyconfig.css
zip keyconfig.zip content\keyconfig.js
zip keyconfig.zip skin\keyconfig.css
zip keyconfig.xpi keyconfig.zip
ren keyconfig.xpi keyconfig_20110522_update.xpi
del keyconfig.zip content\keyconfig.js skin\keyconfig.css
rd content
rd skin

I do not know how to create a shortcut with a "user" property.
Last edited by morat on May 7th, 2015, 1:37 am, edited 1 time in total.
ltGuillaume
Posts: 3
Joined: March 30th, 2015, 9:40 am

Re: keyconfig 20110522

Post by ltGuillaume »

Real noob in this for now, but numerous searches couldn't get me to the right answer, so perhaps you can help. These things I cannot get to work:

1) Close tab and go to tab on the left IF I'm not on the right-most tab

Code: Select all

BrowserCloseTabOrWindow();
if (gBrowser.mCurrentTab._tPos != gBrowser.mTabContainer.childNodes.length - 1)
   gBrowser.mTabContainer.advanceSelectedTab(-1,true);

Problem: really unpredictable.
Edit: The following seems to be more consistent in behavior, plus added a snippet to skip pinned tabs:

Code: Select all

var tab = gBrowser.mCurrentTab;
if (tab.previousSibling)
   gBrowser.mTabContainer.selectedIndex--;
if (!tab.pinned)
   gBrowser.removeTab(tab);


2) When in address bar, add ".nl" suffix to the typed address and load the URI

Code: Select all

loadURI(gURLBar.value +'.nl');

Problem: only works when address bar is not focused.
Edit: The following worked out fine:

Code: Select all

if (gURLBar.inputField == document.activeElement) {
   loadURI(gURLBar.value +'.nl');
   _content.focus();
}
t3l0zvxqIiXuzuH0
Posts: 92
Joined: August 17th, 2014, 5:57 am

Re: keyconfig 20110522

Post by t3l0zvxqIiXuzuH0 »

ltGuillaume wrote:Real noob in this for now, but numerous searches couldn't get me to the right answer, so perhaps you can help. These things I cannot get to work:

1) Close tab and go to tab on the left IF I'm not on the right-most tab


Close Tab and Select Next

Code: Select all

var tab = gBrowser.mCurrentTab;
gBrowser.removeTab(tab);

Close Tab and Select Previous

Code: Select all

var tab = gBrowser.mCurrentTab;
if(tab.previousSibling)
 { gBrowser.mTabContainer.selectedIndex--; }
gBrowser.removeTab(tab);
K4RBQT99
Posts: 284
Joined: November 11th, 2010, 3:23 pm

Re: keyconfig 20110522

Post by K4RBQT99 »

morat wrote:Try this:
...
...

Thanks for catching that detail, morat :P It helps me a lot.
ltGuillaume
Posts: 3
Joined: March 30th, 2015, 9:40 am

Re: keyconfig 20110522

Post by ltGuillaume »

I'd like to create a shortcut to the cookies Exceptions dialog. Does anyone here know how to?
Edit:

Code: Select all

var params = {
   blockVisible: true,
   sessionVisible: true,
   allowVisible: true,
   prefilledHost: gBrowser.contentWindow.location.hostname,
   permissionType: 'cookie',
   windowTitle: 'Exceptions - Cookies',
   introText: '' };
openDialog('chrome://browser/content/preferences/permissions.xul', '_blank', 'resizable', params);
seems to work ok.
chirpy_7
Posts: 165
Joined: March 19th, 2007, 6:24 am

Re: keyconfig 20110522

Post by chirpy_7 »

Hi there,

I posted the below in February but noone seems to have taken notice yet. Still stuck with the problem, help much appreciated!

chirpy_7 wrote:hi dorando & co,

(and @nigelle)

Code: Select all

if(window.content.location.href.match(/^http(s)?:\/\/www\.google.(com|fr)\/search/))
{
var nodes = content.document.evaluate('//h3[@class]/a', content.document, null, 7, null);
gBrowser.addTab(nodes.snapshotItem(0));
}


and

Code: Select all

if(window.content.location.href.match(/^http(s)?:\/\/www\.google.(com|fr)\/search/))
{
var nodes = content.document.evaluate('//h3[@class]/a', content.document, null, 7, null);
gBrowser.loadURI(nodes.snapshotItem(0));
}


stopped working in FF.36 (it seems).

This error *might* be related:

Code: Select all

TypeError: aURI.toLowerCase is not a function


How to fix?

Thank you.
morat
Posts: 6394
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@chirpy_7

Try this:

Code: Select all

// firefox 37.0.2
if (content.location.href.match(/^http(s)?:\/\/www\.google.(com|fr)\/search/)) {
  var nodes = content.document.evaluate("//h3[@class]/a", content.document, null, 7, null);
  var url = nodes.snapshotItem(0);
  // inspectObject(url); // inspect with dom inspector
  // alert(typeof url + "\n" + url); // object
  // alert(typeof url.href + "\n" + url.href); // string
  // alert(typeof url.toString() + "\n" + url.toString()); // string
  try {
    // gBrowser.addTab(url); // fails with object
    // gBrowser.addTab(url.href); // succeeds with string
    gBrowser.addTab(url.toString()); // succeeds with string
  } catch (e) { alert(e); }
}

DOM Inspector
https://addons.mozilla.org/firefox/addon/6622
chirpy_7
Posts: 165
Joined: March 19th, 2007, 6:24 am

Re: keyconfig 20110522

Post by chirpy_7 »

thanks morat, adding .href does the trick!

Code: Select all

gBrowser.addTab(url_temp.href);


thanks also for showing how to employ DOM Inspector for troubleshooting this (I skipped it for now as I was too lazy to enable it and restart my browser).

Errata: Note that in my original post

Code: Select all

gBrowser.loadURI(nodes.snapshotItem(0));
works: this loads the link in the same tab (in the google search page, that is).
Patu
Posts: 31
Joined: September 24th, 2008, 2:20 am

iMacros

Post by Patu »

iMacros prduced the following command clicking a button.
EVENT TYPE=CLICK SELECTOR="#maincontent>DIV:nth-of-type(3)>FORM>TABLE>TBODY>TR:nth-of-type(4)>TD:nth-of-type(2)>A" BUTTON=0

Can anyone help me to transfer this into a key command? I'm completly daft with this. Thanks in advance.
morat
Posts: 6394
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@Patu

Try this:

Code: Select all

var selectors = "#maincontent > DIV:nth-of-type(3) > FORM > TABLE > TBODY > TR:nth-of-type(4) > TD:nth-of-type(2) > A";
var element = content.document.querySelector(selectors);
element.click();

https://developer.mozilla.org/en-US/doc ... rySelector
Post Reply