Announce and Discuss the Latest Theme and Extension Releases.
Zoolcar9

Posts: 2225Joined: November 9th, 2004, 6:45 pmLocation: Jakarta, Indonesia (UTC+7)
Posted March 17th, 2014, 5:37 am
@morat Encode to base64 (btoa) and then decode it with atob? Isn't it just the same as using the original string? Why don't just use loadURI('javascript:alert("foo")')?
Zoolcar9

Posts: 2225Joined: November 9th, 2004, 6:45 pmLocation: Jakarta, Indonesia (UTC+7)
Posted March 17th, 2014, 7:22 pm
troypst
Posts: 16Joined: March 15th, 2013, 5:19 am
Posted March 19th, 2014, 3:00 pm
Ok, so this is the encoded result, and it works: - Code: Select all
loadURI(atob("amF2YXNjcmlwdDp2YXIlMjB1cmk9d2luZG93LmxvY2F0aW9uLmhyZWY7eGhyPW5ldyUyMFhNTEh0dHBSZXF1ZXN0KCk7eGhyLm9wZW4oJ1BPU1QnLCdodHRwczov L3d3dy5nb29nbGVhcGlzLmNvbS91cmxzaG9ydGVuZXIvdjEvdXJsJyxmYWxzZSk7eGhyLnNldFJlcXVlc3RIZWFkZXIoJ0NvbnRlbnQtVHlwZScsJ2FwcGxpY2F0aW9uL2pzb24nKTt4aHIuc2VuZ ChKU09OLnN0cmluZ2lmeSh7bG9uZ1VybDp1cml9KSk7dmFyJTIwanNvbj14aHIucmVzcG9uc2VUZXh0O3ZhciUyMG9iaj1KU09OLnBhcnNlKGpzb24pO2FsZXJ0KG9iai5pZCk7"));
But... is it possible to bypass the whole bookmarklet thing? All I really need is the javascript part to put in keyconfig, because noscript blocks bookmarklet on untrusted sites (and I like it that way). Thanx for this anyway.
Last edited by troypst on March 22nd, 2014, 1:28 pm, edited 1 time in total.
Zoolcar9

Posts: 2225Joined: November 9th, 2004, 6:45 pmLocation: Jakarta, Indonesia (UTC+7)
Posted March 21st, 2014, 4:43 pm
troypst wrote:But... is it possible to bypass the whole bookmarklet thing? All I really need is the javascript part to put in keyconfig, because noscript blocks bookmarklet on untrusted sites (and I like it that way).
You just have to replace 'window' to 'content' in your original code. - Code: Select all
var uri=content.location.href; var xhr=new XMLHttpRequest(); xhr.open('POST','https://www.googleapis.com/urlshortener/v1/url',false); xhr.setRequestHeader('Content-Type','application/json'); xhr.send(JSON.stringify({longUrl:uri})); var json=xhr.responseText; var obj=JSON.parse(json); alert(obj.id);
troypst
Posts: 16Joined: March 15th, 2013, 5:19 am
Posted March 22nd, 2014, 1:44 pm
Zoolcar9 wrote:troypst wrote:But... is it possible to bypass the whole bookmarklet thing? All I really need is the javascript part to put in keyconfig, because noscript blocks bookmarklet on untrusted sites (and I like it that way).
You just have to replace 'window' to 'content' in your original code. - Code: Select all
var uri=content.location.href; var xhr=new XMLHttpRequest(); xhr.open('POST','https://www.googleapis.com/urlshortener/v1/url',false); xhr.setRequestHeader('Content-Type','application/json'); xhr.send(JSON.stringify({longUrl:uri})); var json=xhr.responseText; var obj=JSON.parse(json); alert(obj.id);
Yep, that's exactly what I wanted! This is my final code: - Code: Select all
var txt = "Short URL created for the current page. Press OK to copy to Clipboard.";
var uri = content.location.href; var xhr = new XMLHttpRequest(); xhr.open("POST","https://www.googleapis.com/urlshortener/v1/url",false); xhr.setRequestHeader("Content-Type","application/json"); xhr.send(JSON.stringify({longUrl:uri})); var json = xhr.responseText; var obj = JSON.parse(json);
var p = prompt(txt,obj.id); if (p) { var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper); clipboard.copyString(p); }
Thanks very much to morat and Zoolcar!
bege
Posts: 119Joined: January 23rd, 2009, 9:14 pmLocation: Germany
Posted April 6th, 2014, 1:28 am
Hi, I have a shortcut to toggle activity of a couple of extensions. I'd like to add a popup window to ask whether firefox/thunderbird should be restarted now and have a yes/no choice. If yes - restart the application, if no - do nothing else. Can this be accomplished with keyconfig? If so, can someone help me with the code? Thank you very much in advance.
dorando
Posts: 1203Joined: January 9th, 2004, 9:57 am
Posted April 6th, 2014, 2:38 pm
bege wrote:I want to be able to close the attachment reminder in the Thunderbird compose window with a shortcut.
Try - Code: Select all
document.getElementById("attachmentNotificationBox").allNotifications[0].close();
Leopoldus wrote:[…] a hotkey to toggle on/off HTML view[…] for the current message only[…]
Try - Code: Select all
if(event.target.running) return;
event.target.running = true;
var prefer_plaintext = Services.prefs.getBoolPref("mailnews.display.prefer_plaintext"); var html_as = Services.prefs.getIntPref("mailnews.display.html_as"); var disallow_mime_handlers = Services.prefs.getIntPref("mailnews.display.disallow_mime_handlers");
Services.obs.addObserver({ observe: function() { Services.obs.removeObserver(this, "MsgMsgDisplayed"); event.target.running = false; Services.prefs.setBoolPref("mailnews.display.prefer_plaintext", prefer_plaintext); Services.prefs.setIntPref("mailnews.display.html_as", html_as); Services.prefs.setIntPref("mailnews.display.disallow_mime_handlers", disallow_mime_handlers); } }, "MsgMsgDisplayed", false);
if(content.document.querySelector(".moz-text-html")) { MsgBodyAsPlaintext(); } else { MsgBodyAllowHTML(); }
(based on Allow HTML Temp 3.6.4) WildcatRay wrote:However, still, nothing is copying to the clipboard. ](./images/smilies/eusa_wall.gif)
Anything in the Browser Console? hungerburg wrote:Can I use the keyconfig addon to make "Ctrl-Shift-F" preselect "body" in the initial term (instead of subject)?
Try to Add a new key containing: - Code: Select all
openDialog("chrome://messenger/content/SearchDialog.xul", "_blank", "chrome,resizable,status,centerscreen,dialog=no", { folder: gFolderDisplay.displayedFolder }) .addEventListener("pageshow", function tempFunction(event){ this.removeEventListener(event.type, tempFunction, false);
var searchAttr0 = this.document.getElementById("searchAttr0"); searchAttr0.value = searchAttr0.valueIds[searchAttr0.valueStrings.indexOf("Body")];
this.document.getAnonymousElementByAttribute(this.document.getElementById("searchVal0"), "class", "search-value-textbox").focus(); }, false);
rbfye14 wrote:I thought it's possible to emulate keydown and keyup event for Alt key and select part of link. Without really pressing the Alt key.
Try - Code: Select all
var listener = { handleEvent: function(event) { content.removeEventListener(event.type, this, false);
switch(event.type) { case "dragstart": event.preventDefault();
var utils = document.commandDispatcher.focusedWindow. QueryInterface(Components.interfaces.nsIInterfaceRequestor). getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEvent("mousedown", event.clientX, event.clientY, event.button, 1, utils.MODIFIER_ALT);
this.target = event.target; content.addEventListener("click", this, false); content.addEventListener("mouseup", this, false); break; case "mouseup": if(event.target != this.target) content.removeEventListener("click", this, false); break; case "click": event.preventDefault(); break; } } }
content.addEventListener("dragstart", listener, false);
(activate shortcut, then try to drag a link) liquider wrote:[…], and I would like to appeal to him to reevaluate his position.
I'll likely submit it eventually, but for the time being I have other tasks with a higher priority. ddong wrote:What's happening is on one the firefox opened window, most used keyboard shortcuts are messed/mixed up.
In what way are they messed/mixed up? Is the display in the menu or in the keyconfig window also affected? bege wrote:I'd like to add a popup window to ask whether firefox/thunderbird should be restarted now and have a yes/no choice.
Try - Code: Select all
if(Services.prompt.confirmEx(null, "Restart?", "Restart?", Services.prompt.STD_YES_NO_BUTTONS, null, null, null, null, {}) == 0) Application.restart();
WildcatRay

Posts: 7470Joined: October 18th, 2007, 7:03 pmLocation: Columbus, OH
Posted April 6th, 2014, 3:53 pm
dorando wrote:WildcatRay wrote:However, still, nothing is copying to the clipboard. ](./images/smilies/eusa_wall.gif)
Anything in the Browser Console?
Nothing appears when pressing my key combination or when pasting. - Code: Select all
var url = "about:buildconfig"; var req = new XMLHttpRequest(); req.open("GET", url, false); req.send(null);
var changeset = req.responseText.match(/https?://hg.mozilla.org/[^"]*/).toString(); var changesetId = changeset.match(/[^\/]+$/).toString();
Components.classes["@mozilla.org/widget/clipboardhelper;1"] .getService(Components.interfaces.nsIClipboardHelper) .copyString(changeset);
Ray
OS'es: 4 computers with Win10 Pro 64-bit; Current Firefox, Beta, Nightly, Chrome, Vivaldi
bege
Posts: 119Joined: January 23rd, 2009, 9:14 pmLocation: Germany
Posted April 7th, 2014, 7:43 am
dorando wrote:bege wrote:I want to be able to close the attachment reminder in the Thunderbird compose window with a shortcut.
Try - Code: Select all
document.getElementById("attachmentNotificationBox").allNotifications[0].close();
bege wrote:I'd like to add a popup window to ask whether firefox/thunderbird should be restarted now and have a yes/no choice.
Try - Code: Select all
if(Services.prompt.confirmEx(null, "Restart?", "Restart?", Services.prompt.STD_YES_NO_BUTTONS, null, null, null, null, {}) == 0) Application.restart();
Both work perfectly, thank you very much, Dorando
j6CPmZpg38SiOu91
Posts: 4Joined: April 9th, 2014, 4:54 pm
Posted April 10th, 2014, 7:18 am
Hi all, I have a couple of questions for you experts. The first one is about this script: - Code: Select all
//close prev tab var tab = gBrowser.mCurrentTab.boxObject.previousSibling; if (tab) { gBrowser.removeTab(tab); }
//close next tab var tab = gBrowser.mCurrentTab.boxObject.nextSibling; if (tab) { gBrowser.removeTab(tab); }
//close left tabs while (gBrowser.mCurrentTab.boxObject.previousSibling) { gBrowser.removeTab(gBrowser.mCurrentTab.boxObject.previousSibling); }
//close right tabs while (gBrowser.mCurrentTab.boxObject.nextSibling) { gBrowser.removeTab(gBrowser.mCurrentTab.boxObject.nextSibling); }
I modified the "close prev/next tab" scripts to create the other two: close all rifgt/left tabs without confirmation. They seem to work fine but I don't know much about scripts, are they safe to use? The second question is about a Firegestures script, and I know maybe this is not the right place to ask and I apologize, but their site is dead and I didn't know where else to go. Here it is: - Code: Select all
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); var recentWindow = wm.getMostRecentWindow("navigator:browser"); var browser = recentWindow.gBrowser;
searchTab1 = function(url) //open in current tab { if (!url) { FireGestures.setStatusText("Invalid URL."); FireGestures.clearStatusText(2000); return; } browser.loadURI(url); };
searchTab2 = function(url) //open in next tab and select it { if (!url) { FireGestures.setStatusText("Invalid URL."); FireGestures.clearStatusText(2000); return; } var pos = browser.selectedTab._tPos; var tab = browser.addTab(url); browser.moveTabTo(tab,pos+1); browser.selectedTab = tab; };
searchTab3 = function(url) //open in next tab { if (!url) { FireGestures.setStatusText("Invalid URL."); FireGestures.clearStatusText(2000); return; } var pos = browser.selectedTab._tPos; var tab = browser.addTab(url); browser.moveTabTo(tab,pos+1); };
searchTab4 = function(url) //open in last tab and select it { if (!url) { FireGestures.setStatusText("Invalid URL."); FireGestures.clearStatusText(2000); return; } var tab = browser.addTab(url); browser.selectedTab = tab; };
searchTab5 = function(url) //open in last tab { if (!url) { FireGestures.setStatusText("Invalid URL."); FireGestures.clearStatusText(2000); return; } var tab = browser.addTab(url); };
searchCommand = function(nm,text) { if (!text) { var text = ""; } var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService); var engine = ss.getEngineByName(nm); if (!engine) { return; } var submission = engine.getSubmission(text,null); if (!submission) { return; } searchTab3(submission.uri.spec); };
searchArray = function(text) // need a way to decide the tab from here???????????? { if (!text) { var text = ""; } var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService).getEngines([]); var arr = []; for (var i in ss) { arr.push( { label: ss[i].name, oncommand: "searchCommand('" + ss[i].name + "','" + text + "');", class: "menuitem-iconic searchbar-engine-menuitem menuitem-with-favicon", src: ss[i].iconURI.spec } ); } return arr; };
customMenuArray = function(url) { var a = [ { label: "Open Selection as URL", oncommand: "searchTab3(" + '"' + url + '"' + ");", }, null, ]; return a; };
//search terms: from selected text or clipboard or whatever if (event.ctrlKey) { var str = readFromClipboard(); } else { var str = FireGestures.getSelectedText(); }
menu = customMenuArray(str); menu.push.apply(menu,searchArray(str));
FireGestures.generatePopup(event,menu);
I put this togheter from parts that I found via google on a chinese website where i learned from a chinese God coder that firegestures can be used to create entire totally custom context menus (with submenus, icons, separators, external apps, etc.) using arrays of names and commands. This particular one recreate the "[Popup] Search for Selection with..." function (select some text and choose which of your installed search engines to use to do a search). The good thing is that here I can decide the search terms to use and in which tab to perform the search. What I need (if possible) is a way to determine the search tab form the LAST function (searchArray) without having to duplicate things around over and over. But all this functions inside functions business is way too much for me; in fact I really understand only half of all this. So, if anyone understood anything I wrote, I accept suggestions. Thanks for the help. Edit Other problems after a bit of testing: the search is broken it the apostrophe (') char is selected or by end of paragraph. Edit2 I worked out some problems and all seems fine now. This is the result: - Code: Select all
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); var recentWindow = wm.getMostRecentWindow("navigator:browser"); var browser = recentWindow.gBrowser;
openSearchLink = function(i) { url = searchUrls[i]; if (!url) { alert("Invalid URL."); return; } else if (event.shiftKey) // press SHIFT: open tab at end { browser.addTab(url); } else if (event.ctrlKey) // press CTRL: open in current tab { var tab = browser.loadURI(url); } else // press nothing: open in next tab { var pos = browser.selectedTab._tPos; var tab = browser.addTab(url); browser.moveTabTo(tab,pos+1); } };
openCustomLink = function(i) { url = customUrls[i]; if (!url) { alert("Invalid URL."); return; } else if (event.shiftKey) // press SHIFT: open tab at end { browser.addTab(url); } else if (event.ctrlKey) // press CTRL: open in current tab { var tab = browser.loadURI(url); } else // press nothing: open in next tab { var pos = browser.selectedTab._tPos; var tab = browser.addTab(url); browser.moveTabTo(tab,pos+1); } };
createSearchArray = function(text) { var ss = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService); var tt = ss.getEngines([]); var arr = []; for (var i in tt) { var engine = ss.getEngineByName(tt[i].name); var submission = engine.getSubmission(text,null); searchUrls.push(submission.uri.spec); arr.push( { label: tt[i].name, oncommand: "openSearchLink(" + i + ");", class: "menuitem-iconic searchbar-engine-menuitem menuitem-with-favicon", src: tt[i].iconURI.spec, } ); } return arr; };
if (event.altKey) // press ALT: search from clipboard { var str = readFromClipboard(); if (!str) { alert("Clipboard is empty."); return; } } else // press nothing: search from selection { var str = FireGestures.getSelectedText(); }
var searchUrls = []; searchArray = createSearchArray(str);
var customUrls = [str]; var customArray = [ { label: "Open as URL", oncommand: "openCustomLink(0);", }, null, ];
menuArray = customArray.concat(searchArray); FireGestures.generatePopup(event,menuArray);
Could you point out problems and improvements if you find any? Thanks.
Negativeions
Posts: 244Joined: September 17th, 2003, 12:07 pm
Posted April 19th, 2014, 11:49 am
Does anyone know how to set a hotkey for "restore previous session"? Thanks.
Zoolcar9

Posts: 2225Joined: November 9th, 2004, 6:45 pmLocation: Jakarta, Indonesia (UTC+7)
Posted April 19th, 2014, 4:44 pm
- Code: Select all
try { restoreLastSession(); } catch (ex) {}
dorando
Posts: 1203Joined: January 9th, 2004, 9:57 am
Posted April 21st, 2014, 11:51 am
WildcatRay wrote:dorando wrote:WildcatRay wrote:However, still, nothing is copying to the clipboard. ](./images/smilies/eusa_wall.gif)
Anything in the Browser Console?
Nothing appears when pressing my key combination or when pasting. - Code: Select all
var url = "about:buildconfig"; var req = new XMLHttpRequest(); req.open("GET", url, false); req.send(null);
var changeset = req.responseText.match(/https?://hg.mozilla.org/[^"]*/).toString(); var changesetId = changeset.match(/[^\/]+$/).toString();
Components.classes["@mozilla.org/widget/clipboardhelper;1"] .getService(Components.interfaces.nsIClipboardHelper) .copyString(changeset);
The board did eat the backslashes: - Code: Select all
var changeset = req.responseText.match(/https?:\/\/hg.mozilla.org\/[^\"]*/).toString();
j6CPmZpg38SiOu91 wrote:They seem to work fine but I don't know much about scripts, are they safe to use?
Likely.
Return to Extension/Theme Releases
Who is online
Users browsing this forum: No registered users and 1 guest
|