keyconfig 20110522

Announce and Discuss the Latest Theme and Extension Releases.
Post Reply
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Re: keyconfig 20110522

Post by Zoolcar9 »

Cattleya wrote:I want a hotkey to subscrible current page to RSS Feed, like Menu -> Bookmark -> Subscrible to This Page did :)

Code: Select all

const TITLE "Subscribe to this page\u2026";
const 
kPromptService Services.prompt;

function 
selectItems(aTextaArray) {
  var 
selected = {};
  var 
result kPromptService.select(nullTITLEaTextaArray.lengthaArrayselected);
  if (
result) return selected.value;
  return 
false;
}

function 
subscribeToFeed(aFeedURL) {
  try {
    return 
FeedHandler.subscribeToFeed(aFeedURL);
  } catch(
ex) {}
}

var 
feeds gBrowser.selectedBrowser.feeds;

if (!
feeds)
  return 
kPromptService.alert(nullTITLE"No feeds found on this page.");

if (
feeds.length === 1)
  return 
subscribeToFeed(feeds[0].href);

var 
feedNames = [];
var 
feedURLs = [];
for (var 
0feeds.lengthi++) {
  
feedNames.push(feeds[i].title);
  
feedURLs.push(feeds[i].href);
}
var 
index selectItems("Select feed to subscribe:"feedNames);
if (
index !== undefined)
  return 
subscribeToFeed(feedURLs[index]); 

Revisions: 2 | 3
Last edited by Zoolcar9 on July 19th, 2013, 9:16 am, edited 2 times in total.
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
rbfye14
Posts: 26
Joined: April 9th, 2012, 8:23 am

Re: keyconfig 20110522

Post by rbfye14 »

I made a simple script to remotely upload images to image hosting

Code: Select all

gBrowser.loadOneTab("http://housepic.org/", null, null, null, false);
gBrowser.addEventListener("load", function upl() {
clp = readFromClipboard(); // Image address was saved in the clipboard
 content.document.getElementsByName('web_uploadfile')[0].value=clp;
content.document.forms[0].submit()
} , true )


It works fine, but why do I keep getting these two errors?

Code: Select all

TelemetryStopwatch: key "FX_PAGE_LOAD_MS" was already initialized
resource://gre/modules/TelemetryStopwatch.jsm
Line: 53


And

Code: Select all

TypeError: content.document.getElementsByName(...)[0] is undefined
chrome://browser/content/browser.xul
Line: 4
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Re: keyconfig 20110522

Post by Zoolcar9 »

rbfye14 wrote:

Code: Select all

TelemetryStopwatch: key "FX_PAGE_LOAD_MS" was already initialized
resource://gre/modules/TelemetryStopwatch.jsm
Line: 53

That error came from Telemetry. Just ignore it.

rbfye14 wrote:

Code: Select all

TypeError: content.document.getElementsByName(...)[0] is undefined
chrome://browser/content/browser.xul
Line: 4

Because you didn't remove the event listener, you'll get that error
because it will search for 'web_uploadfile' everytime you open a tab.
Add 'removeEventListener' in your code

Code: Select all

gBrowser.loadOneTab("http://housepic.org/", null, null, null, false);
gBrowser.addEventListener("load", function upl(e) { // added argument
  e.currentTarget.removeEventListener(e.type, arguments.callee, true); // remove event listener
  clp = readFromClipboard(); // Image address was saved in the clipboard
  content.document.getElementsByName('web_uploadfile')[0].value=clp;
  content.document.forms[0].submit()
},
 true) 

or change your code (add event listener to browser object inside the tab instead of global browser)

Code: Select all

var tab = gBrowser.loadOneTab("http://housepic.org/", null, null, null, false);
tab.linkedBrowser.addEventListener("load", function upl(e) {
  e.currentTarget.removeEventListener(e.type, arguments.callee, true);
  clp = readFromClipboard(); // Image address was saved in the clipboard
  content.document.getElementsByName('web_uploadfile')[0].value=clp;
  content.document.forms[0].submit()
},
 true ) 
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
rbfye14
Posts: 26
Joined: April 9th, 2012, 8:23 am

Re: keyconfig 20110522

Post by rbfye14 »

Zoolcar9
Thanks a lot!
Patu
Posts: 31
Joined: September 24th, 2008, 2:20 am

Re: keyconfig 20110522

Post by Patu »

Hi Dorando, I remember you were considering an import/export-function for keyconfig.

Is it going to come?
dorando
Posts: 1203
Joined: January 9th, 2004, 9:57 am
Contact:

Re: keyconfig 20110522

Post by dorando »

Eventually, but likely not in the next release.
Support mozilla.dorando.at through donations/contributions.
ltwally
Posts: 13
Joined: November 24th, 2005, 10:16 am

Re: keyconfig 20110522

Post by ltwally »

Anyone know if it's possible to create a shortcut for Thunderbird to start a bullet list in the new message window? If so, how?

Thanks
User avatar
RegiOween
Posts: 3
Joined: September 11th, 2008, 6:59 pm

Code to open Firefox context-menu at mouse position

Post by RegiOween »

Hi, folks!

I've searched this thread for some way to open Firefox context-menu at mouse position (simulating a right-button click), but didn't find nothing.
I already tried many javascript, jquery and xul snippets, but nothing worked, so I ask you for some guidance to do that.

Thanks in advance.

RegiOween
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@ltwally

Try this:

Code: Select all

doStyleUICommand("cmd_ul");

I found the command by running the following code and clicking on the menu item.

Code: Select all

function getCommand(event) {
  window.removeEventListener("command", getCommand, true);
  event.preventDefault();
  event.stopPropagation();
  alert(event.target.getAttribute("oncommand") ||
    event.target.getAttribute("onclick"));
}
window.addEventListener("command", getCommand, true);

This trick does not work for all user interface elements.

@RegiOween

Try these:

Code: Select all

var popup = document.getElementById("contentAreaContextMenu");
var anchor = gBrowser.tabs[0];
var position = "after_start";
var x = 0;
var y = 0;
var isContextMenu = true;
var attributesOverride = true;
popup.openPopup(anchor, position, x, y, isContextMenu, attributesOverride);

Code: Select all

var popup = document.getElementById("contentAreaContextMenu");
var x = window.outerWidth / 4;
var y = window.outerHeight / 4;
var isContextMenu = true;
popup.openPopupAtScreen(x, y, isContextMenu);

Code: Select all

var utils = gBrowser.contentWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
var x = 0;
var y = 0;
var button = 2;
var clickCount = 1;
var modifiers = 0;
utils.sendMouseEvent("contextmenu", x, y, button, clickCount, modifiers);

I do not know how to get the mouse position.

https://developer.mozilla.org/en/XUL/Method/openPopup
https://developer.mozilla.org/en/XUL/Me ... upAtScreen
https://developer.mozilla.org/en/XUL/Po ... ositioning
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIDOMWindowUtils#sendMouseEvent()

You can use the Shift+F10 keyboard shortcut or Menu key to launch a context menu.

http://en.wikipedia.org/wiki/Menu_key

You can use the NirCmd program to send a right click.

Code: Select all

var localFile = Components.classes["@mozilla.org/file/local;1"].
  createInstance(Components.interfaces.nsILocalFile);
var process = Components.classes["@mozilla.org/process/util;1"].
  createInstance(Components.interfaces.nsIProcess);
var args = ["sendmouse", "right", "click"];
localFile.initWithPath("C:\\nircmd.exe");
process.init(localFile);
process.run(false, args, args.length);

http://www.nirsoft.net/utils/nircmd.html
http://www.nirsoft.net/utils/nircmd2.html#sendmouse
Last edited by morat on July 14th, 2013, 11:18 am, edited 2 times in total.
GotA20
Posts: 2
Joined: July 11th, 2013, 2:27 pm

Code for closing all private browsing windows

Post by GotA20 »

Is there a way to close all private browsing windows using keyconfig?

Thanks in advance!
Zoolcar9
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)
Contact:

Re: Code for closing all private browsing windows

Post by Zoolcar9 »

GotA20 wrote:Is there a way to close all private browsing windows using keyconfig?

Code: Select all

var em = Services.wm.getEnumerator("navigator:browser");
var win;
while (em.hasMoreElements()) {
  win = em.getNext();
  if (PrivateBrowsingUtils.isWindowPrivate(win))
    win.close();
}
 

s.p.
If you only want to use only ONE private window, install Open in Private Window extension or Private Tab.
My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."
nigelle
Posts: 117
Joined: June 9th, 2005, 8:30 am
Location: France

Re: keyconfig 20110522

Post by nigelle »

To Patu
My private copy of Keyconfig has import/export.
In the past, Dorando has given the (long) codes to define a) import (from a file), b) export (to a file) short-cuts. This is not very convenient because if you wish to import your old short-cuts to a new FF profile, you have first to download Keyconfig then define the import short-cut then use it. This process consumes 2 letter-combinations to define the 2 short-cuts that are not frequently used.

I see an other solution for Dorando :
-He integrate in the next release the short-cut to execute the code placed in the clipboard (this code has been given in the past). This short-cut may have many other applications.
-He put as downloadable files (for us) in his site the codes to put in clipboard for a) export, b) import, c) printing the list of short-cuts (that was also contributed at nearly the same time), any other utilities (to be defined) for keyconfig...
dorando
Posts: 1203
Joined: January 9th, 2004, 9:57 am
Contact:

Re: keyconfig 20110522

Post by dorando »

RegiOween wrote:I've searched this thread for some way to open Firefox context-menu at mouse position (simulating a right-button click), but didn't find nothing.
I am not aware of any internal API for getting the mouse position (outside a mouse event), but try (only works on Windows)

Code: Select all

Components.utils.import("resource://gre/modules/ctypes.jsm");
var 
user32 ctypes.open("user32");

var 
BOOL  ctypes.int;
var 
LONG  ctypes.long;

var 
POINT ctypes.StructType("tagPOINT", [
 { 
LONG },
 { 
LONG }
]);

var 
LPPOINT POINT.ptr;

var 
GetCursorPos user32.declare('GetCursorPos'ctypes.winapi_abiBOOLLPPOINT);

var 
point = new POINT;
if(
GetCursorPos(point.address())) {
 var 
utils window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
 
getInterface(Components.interfaces.nsIDOMWindowUtils);

 var 
MOUSEEVENTF_RIGHTDOWN 0x0008;
 var 
MOUSEEVENTF_RIGHTUP   0x0010;
 
utils.sendNativeMouseEvent(point.xpoint.yMOUSEEVENTF_RIGHTDOWN MOUSEEVENTF_RIGHTUP0null);
}

user32.close(); 
Support mozilla.dorando.at through donations/contributions.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: keyconfig 20110522

Post by morat »

@dorando

Nicely done.

The cursor moves in the ctypes example when I hold down the shortcut keys. I got the ctypes example to work like the NirCmd example with the following tweak.

Code: Select all

var x = point.x - window.screenX;
var y = point.y - window.screenY;
utils.sendNativeMouseEvent(x, y, MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, null);
Cattleya
Posts: 57
Joined: October 7th, 2010, 11:14 pm

Re: keyconfig 20110522

Post by Cattleya »

Zoolcar9 wrote:
Cattleya wrote:I want a hotkey to subscrible current page to RSS Feed, like Menu -> Bookmark -> Subscrible to This Page did :)

Code: Select all

const TITLE = "Subscribe to this page\u2026";
const kPromptService = Services.prompt;

function selectItems(aText, aArray) {
  var selected = {};
  var result = kPromptService.select(null, TITLE, aText, aArray.length, aArray, selected);
  if (result) return selected.value;
  return;
}

var feeds = content.document.querySelectorAll('link[rel="alternate"]\[type^="application/"]\[type$="+xml"]');
/* Note: keyconfig keeps adding spaces between ']' and '[' when I saved the code, so I used '\['.
   Must be because the way keyconfig store codes in the preferences. */

if (!feeds.length) {
  kPromptService.alert(null, TITLE, "No feeds found on this page.");
  return;
}

if (feeds.length === 1) {
  FeedHandler.subscribeToFeed(feeds[0].href);
  return;
}

var feedNames = [];
var feedURLs = [];
for (var i = 0; i < feeds.length; i++) {
  feedNames.push(feeds[i].title);
  feedURLs.push(feeds[i].href);
}
var index = selectItems("Select feed to subscribe:", feedNames);
if (index !== undefined)
  FeedHandler.subscribeToFeed(feedURLs[index]); 


Many thank, Zoolcar, you helped me so much :)
Post Reply