Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CmdUtils.CreateCommand({
name: "aliquot",
arguments: [{role: 'object', nountype: noun_arb_text}],
locale: "en-US",
author: {name: "Timothy Sorbera", email: "tim.sorbera@gmail.com"},
license: "MPL",
description: "View the selected aliquot sequence at Syd's DB.",
preview: function(pblock, args) {
var html = _("View sequence ");
if (args.object.text) {
html += args.object.text;
} else {
html += _(".");
}
pblock.innerHTML = html;
},
execute: function(args) {
var seq = escape(args.object.text);
seq = seq.replace(/\+/g,"\%2B");
Utils.openUrlInBrowser("http://factordb.com/search.php?se=1&aq=" + seq);
}
});
CmdUtils.CreateCommand({
name: "factor",
arguments: [{role: 'object', nountype: noun_arb_text, label: 'number'}, {role: 'alias', nountype: noun_arb_text}],
locale: "en-US",
author: {name: "Timothy Sorbera", email: "tim.sorbera@gmail.com"},
license: "MPL",
description: "View the factorization of this number at Syd's DB.",
preview: function(pblock, args) {
var number = args.object.text;
var factors = args.alias.text;
var html = _("View the factorization of ");
if (factors && number) {
html = _("View the factorization of " + number + " at Syd's DB and report the factor(s): " + factors);
} else if (number) {
html += _(number + " at Syd's DB.");
} else {
html += _("the selected number at Syd's DB.");
}
pblock.innerHTML = html;
},
execute: function(args) {
var number = args.object.text;
var factors = args.alias.text;
var L = number.indexOf("L")>0;
var M = number.indexOf("M")>0;
if (L||M) {
if (L) { var m = number.substr(0,number.indexOf("L")); }
else { var m = number.substr(0,number.indexOf("M")); }
var n = (m-2)/4;
var a = 2*n+1;
var b = n+1;
number = "2^"+a;
if (L) { number += "-"; }
else { number += "+"; }
number += "2^"+b+"+1";
}
number = escape(number);
number = number.replace(/\+/g,"\%2B");
factors = factors.replace(/x/g,"*");
factors = escape(factors);
factors = factors.replace(/\+/g,"\%2B");
var url = "http://factordb.com/search.php?query=" + number;
if (factors) { url = url + "&reportfac=" + factors; }
Utils.openUrlInBrowser(url);
}
});
CmdUtils.CreateCommand({
name: "Mersenne exponent status",
arguments: [{role: 'object', nountype: noun_arb_text, label: "exponent"}],
icon: "http://www.mersenne.org/favicon.ico",
locale: "en-US",
author: {name: "Timothy Sorbera", email: "tim.sorbera@gmail.com"},
license: "MPL",
description: "Look up the status of the selected Mersenne number.",
preview: function(pblock, args) {
var html;
if (args.object.text) {
var mersNum = args.object.text.replace(/,/g,"");
mersNum = mersNum.replace(/M/g,"");
html = _("View status of 2<sup>" + mersNum + "</sup>-1");
} else {
html = _("View status of the selected Mersenne number.");
}
pblock.innerHTML = html;
},
execute: function(args) {
var mersNum = args.object.text.replace(/,/g,"");
mersNum = mersNum.replace(/M/g,"");
Utils.openUrlInBrowser("http://www.mersenne.org/report_exponent/?exp_lo=" + mersNum);
}
});
CmdUtils.CreateCommand({
name: "aliquot multi",
arguments: [{role: 'object', nountype: noun_arb_text}],
locale: "en-US",
author: {name: "Timothy Sorbera", email: "tim.sorbera@gmail.com"},
license: "MPL",
description: "View the selected aliquot sequences at Syd's DB.",
preview: function(pblock, args) {
var html = _("View sequences ");
if (args.object.text) {
html += args.object.text;
} else {
html += _(".");
}
pblock.innerHTML = html;
},
execute: function(args) {
var text = args.object.text.replace(/\s/g,"");
text = text.replace(/\n/g,",");
var array = text.split(",");
for ( i = 0; i < array.length; i++) {
Utils.openUrlInBrowser("http://factordb.com/search.php?se=1&action=last&raw=1&aq=" + array[i]);
}
}
});
CmdUtils.CreateCommand({
name: "stand up",
arguments: [{role: 'object', nountype: noun_arb_text}],
locale: "en-US",
author: {name: "Timothy Sorbera", email: "tim.sorbera@gmail.com"},
license: "MPL",
description: "Converts a vertical newline-separated list to a horizontal comma-separated list.",
execute: function(args) {
CmdUtils.setSelection(args.object.text.replace(/\n/g,", "));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment