mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 10:17:59 +01:00
Update curl plugin.
This commit is contained in:
@@ -548,7 +548,7 @@ var DOM = Class("DOM", {
|
|||||||
let charset = doc.characterSet;
|
let charset = doc.characterSet;
|
||||||
let converter = services.CharsetConv(charset);
|
let converter = services.CharsetConv(charset);
|
||||||
for (let cs of form.acceptCharset.split(/\s*,\s*|\s+/)) {
|
for (let cs of form.acceptCharset.split(/\s*,\s*|\s+/)) {
|
||||||
let c = services.CharsetConv(cs);
|
let c = cs && services.CharsetConv(cs);
|
||||||
if (c) {
|
if (c) {
|
||||||
converter = services.CharsetConv(cs);
|
converter = services.CharsetConv(cs);
|
||||||
charset = cs;
|
charset = cs;
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ var Services = Module("Services", {
|
|||||||
* @param {string} init Name of a property or method used to initialize the
|
* @param {string} init Name of a property or method used to initialize the
|
||||||
* class.
|
* class.
|
||||||
*/
|
*/
|
||||||
addClass: function addClass(name, class_, ifaces, init = null, quiet = false) {
|
addClass: function addClass(name, class_, ifaces, init = null, quiet = true) {
|
||||||
this.services[name] = { class: class_,
|
this.services[name] = { class: class_,
|
||||||
interfaces: Array.concat(ifaces || []),
|
interfaces: Array.concat(ifaces || []),
|
||||||
method: "createInstance",
|
method: "createInstance",
|
||||||
|
|||||||
@@ -1543,6 +1543,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* separators.
|
* separators.
|
||||||
*/
|
*/
|
||||||
shellEscape: function shellEscape(str) {
|
shellEscape: function shellEscape(str) {
|
||||||
|
// Pass through simple strings without escaping.
|
||||||
|
if (/^[-+\w/.,/:]+$/.test(str))
|
||||||
|
return str;
|
||||||
|
|
||||||
return '"' + String.replace(str, /[\\"$`]/g, "\\$&") + '"';
|
return '"' + String.replace(str, /[\\"$`]/g, "\\$&") + '"';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var INFO =
|
var INFO =
|
||||||
["plugin", { name: "curl",
|
["plugin", { name: "curl",
|
||||||
version: "0.3",
|
version: "0.4",
|
||||||
href: "http://dactyl.sf.net/pentadactyl/plugins#curl-plugin",
|
href: "http://dactyl.sf.net/pentadactyl/plugins#curl-plugin",
|
||||||
summary: "Curl command-line generator",
|
summary: "Curl command-line generator",
|
||||||
xmlns: "dactyl" },
|
xmlns: "dactyl" },
|
||||||
@@ -25,6 +25,9 @@ var INFO =
|
|||||||
"page."]]]];
|
"page."]]]];
|
||||||
|
|
||||||
hints.addMode('C', "Generate curl command for a form", function(elem) {
|
hints.addMode('C', "Generate curl command for a form", function(elem) {
|
||||||
|
let doc = elem.ownerDocument;
|
||||||
|
let win = doc.defaultView;
|
||||||
|
|
||||||
if (elem.form)
|
if (elem.form)
|
||||||
var { url, postData, elements } = DOM(elem).formData;
|
var { url, postData, elements } = DOM(elem).formData;
|
||||||
else
|
else
|
||||||
@@ -33,19 +36,31 @@ hints.addMode('C', "Generate curl command for a form", function(elem) {
|
|||||||
if (!url || /^javascript:/.test(url))
|
if (!url || /^javascript:/.test(url))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
url = util.newURI(url, null,
|
url = util.newURI(url, null, doc.documentURIObject).spec;
|
||||||
elem.ownerDocument.documentURIObject).spec;
|
|
||||||
|
|
||||||
let { shellEscape } = util.closure;
|
if (!elements)
|
||||||
|
elements = [];
|
||||||
|
|
||||||
dactyl.clipboardWrite(["curl"].concat(
|
let paramLines = [
|
||||||
[].concat(
|
...elements.map(datum => ["--form-string", datum]),
|
||||||
[["--form-string", shellEscape(datum)] for (datum of (elements || []))],
|
|
||||||
postData != null && !elements.length ? [["-d", shellEscape("")]] : [],
|
["-H", "Cookie: " + doc.cookie],
|
||||||
[["-H", shellEscape("Cookie: " + elem.ownerDocument.cookie)],
|
|
||||||
["-A", shellEscape(navigator.userAgent)],
|
["-A", win.navigator.userAgent],
|
||||||
[shellEscape(url)]]
|
|
||||||
).map(function(e) e.join(" ")).join(" \\\n ")).join(" "), true);
|
[url],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (postData != null && !elements.length)
|
||||||
|
paramLines.unshift(["-d", postData]);
|
||||||
|
|
||||||
|
|
||||||
|
let { shellEscape } = util.bound;
|
||||||
|
let params = paramLines.map(params => params.map(shellEscape).join(" "))
|
||||||
|
.join(" \\\n ");
|
||||||
|
|
||||||
|
|
||||||
|
dactyl.clipboardWrite(`curl ${params}`, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* vim:se sts=4 sw=4 et: */
|
/* vim:se sts=4 sw=4 et: */
|
||||||
|
|||||||
Reference in New Issue
Block a user