mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 17:22:26 +01:00
prefer let over var in util.js
This commit is contained in:
@@ -26,7 +26,6 @@ the provisions above, a recipient may use your version of this file under
|
|||||||
the terms of any one of the MPL, the GPL or the LGPL.
|
the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
}}} ***** END LICENSE BLOCK *****/
|
}}} ***** END LICENSE BLOCK *****/
|
||||||
|
|
||||||
|
|
||||||
const util = { //{{{
|
const util = { //{{{
|
||||||
|
|
||||||
Array: {
|
Array: {
|
||||||
@@ -150,7 +149,7 @@ const util = { //{{{
|
|||||||
|
|
||||||
copyToClipboard: function (str, verbose)
|
copyToClipboard: function (str, verbose)
|
||||||
{
|
{
|
||||||
var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
||||||
.getService(Components.interfaces.nsIClipboardHelper);
|
.getService(Components.interfaces.nsIClipboardHelper);
|
||||||
clipboardHelper.copyString(str);
|
clipboardHelper.copyString(str);
|
||||||
|
|
||||||
@@ -191,9 +190,9 @@ const util = { //{{{
|
|||||||
formatBytes: function (num, decimalPlaces, humanReadable)
|
formatBytes: function (num, decimalPlaces, humanReadable)
|
||||||
{
|
{
|
||||||
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
||||||
var unitIndex = 0;
|
let unitIndex = 0;
|
||||||
var tmpNum = parseInt(num, 10) || 0;
|
let tmpNum = parseInt(num, 10) || 0;
|
||||||
var strNum = [tmpNum + ""];
|
let strNum = [tmpNum + ""];
|
||||||
|
|
||||||
if (humanReadable)
|
if (humanReadable)
|
||||||
{
|
{
|
||||||
@@ -203,12 +202,14 @@ const util = { //{{{
|
|||||||
if (++unitIndex > (unitVal.length - 1))
|
if (++unitIndex > (unitVal.length - 1))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let decPower = Math.pow(10, decimalPlaces);
|
let decPower = Math.pow(10, decimalPlaces);
|
||||||
strNum = ((Math.round(tmpNum * decPower) / decPower) + "").split(".", 2);
|
strNum = ((Math.round(tmpNum * decPower) / decPower) + "").split(".", 2);
|
||||||
|
|
||||||
if (!strNum[1])
|
if (!strNum[1])
|
||||||
strNum[1] = "";
|
strNum[1] = "";
|
||||||
while (strNum[1].length < decimalPlaces) // padd with "0" to the desired decimalPlaces)
|
|
||||||
|
while (strNum[1].length < decimalPlaces) // pad with "0" to the desired decimalPlaces)
|
||||||
strNum[1] += "0";
|
strNum[1] += "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,14 +226,14 @@ const util = { //{{{
|
|||||||
// generates an Asciidoc help entry, "command" can also be a mapping
|
// generates an Asciidoc help entry, "command" can also be a mapping
|
||||||
generateHelp: function (command, extraHelp)
|
generateHelp: function (command, extraHelp)
|
||||||
{
|
{
|
||||||
var start = "", end = "";
|
let start = "", end = "";
|
||||||
if (command instanceof liberator.Command)
|
if (command instanceof liberator.Command)
|
||||||
start = ":";
|
start = ":";
|
||||||
else if (command instanceof liberator.Option)
|
else if (command instanceof liberator.Option)
|
||||||
start = end = "'";
|
start = end = "'";
|
||||||
|
|
||||||
var ret = "";
|
let ret = "";
|
||||||
var longHelp = false;
|
let longHelp = false;
|
||||||
if ((command.help && command.description) && (command.help.length + command.description.length) > 50)
|
if ((command.help && command.description) && (command.help.length + command.description.length) > 50)
|
||||||
longHelp = true;
|
longHelp = true;
|
||||||
|
|
||||||
@@ -246,7 +247,7 @@ const util = { //{{{
|
|||||||
ret += "\n";
|
ret += "\n";
|
||||||
|
|
||||||
// the usage information for the command
|
// the usage information for the command
|
||||||
var usage = command.names[0];
|
let usage = command.names[0];
|
||||||
if (command.specs) // for :commands
|
if (command.specs) // for :commands
|
||||||
usage = command.specs[0];
|
usage = command.specs[0];
|
||||||
|
|
||||||
@@ -376,22 +377,27 @@ const util = { //{{{
|
|||||||
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
|
// same as Firefox's readFromClipboard function, but needed for apps like Thunderbird
|
||||||
readFromClipboard: function ()
|
readFromClipboard: function ()
|
||||||
{
|
{
|
||||||
var url;
|
let url;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var clipboard = Components.classes['@mozilla.org/widget/clipboard;1']
|
const clipboard = Components.classes['@mozilla.org/widget/clipboard;1']
|
||||||
.getService(Components.interfaces.nsIClipboard);
|
.getService(Components.interfaces.nsIClipboard);
|
||||||
var trans = Components.classes['@mozilla.org/widget/transferable;1']
|
const transferable = Components.classes['@mozilla.org/widget/transferable;1']
|
||||||
.createInstance(Components.interfaces.nsITransferable);
|
.createInstance(Components.interfaces.nsITransferable);
|
||||||
trans.addDataFlavor("text/unicode");
|
|
||||||
if (clipboard.supportsSelectionClipboard())
|
|
||||||
clipboard.getData(trans, clipboard.kSelectionClipboard);
|
|
||||||
else
|
|
||||||
clipboard.getData(trans, clipboard.kGlobalClipboard);
|
|
||||||
|
|
||||||
var data = {};
|
transferable.addDataFlavor("text/unicode");
|
||||||
var dataLen = {};
|
|
||||||
trans.getTransferData("text/unicode", data, dataLen);
|
if (clipboard.supportsSelectionClipboard())
|
||||||
|
clipboard.getData(transferable, clipboard.kSelectionClipboard);
|
||||||
|
else
|
||||||
|
clipboard.getData(transferable, clipboard.kGlobalClipboard);
|
||||||
|
|
||||||
|
let data = {};
|
||||||
|
let dataLen = {};
|
||||||
|
|
||||||
|
transferable.getTransferData("text/unicode", data, dataLen);
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
data = data.value.QueryInterface(Components.interfaces.nsISupportsString);
|
data = data.value.QueryInterface(Components.interfaces.nsISupportsString);
|
||||||
@@ -407,13 +413,13 @@ const util = { //{{{
|
|||||||
// and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
|
// and returns an array ['www.google.com/search?q=bla', 'www.osnews.com']
|
||||||
stringToURLArray: function (str)
|
stringToURLArray: function (str)
|
||||||
{
|
{
|
||||||
var urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*"));
|
let urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*"));
|
||||||
|
|
||||||
for (let url = 0; url < urls.length; url++)
|
for (let url = 0; url < urls.length; url++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var file = io.getFile(urls[url]);
|
let file = io.getFile(urls[url]);
|
||||||
if (file.exists() && file.isReadable())
|
if (file.exists() && file.isReadable())
|
||||||
{
|
{
|
||||||
urls[url] = file.path;
|
urls[url] = file.path;
|
||||||
@@ -437,7 +443,7 @@ const util = { //{{{
|
|||||||
// like the comments below ;-)
|
// like the comments below ;-)
|
||||||
|
|
||||||
// check for a search engine match in the string
|
// check for a search engine match in the string
|
||||||
var searchURL = bookmarks.getSearchURL(urls[url], false);
|
let searchURL = bookmarks.getSearchURL(urls[url], false);
|
||||||
if (searchURL)
|
if (searchURL)
|
||||||
{
|
{
|
||||||
urls[url] = searchURL;
|
urls[url] = searchURL;
|
||||||
|
|||||||
Reference in New Issue
Block a user