mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Minor adjustments
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2010 Alfonso Martínez de Lizarrondo & Patrick O'Reilly
|
Copyright 2010 Alfonso Martínez de Lizarrondo & Patrick O'Reilly
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -23,8 +23,8 @@ sendtophone.init = function()
|
|||||||
this.prefs.setBoolPref( "installedButton", true ) ;
|
this.prefs.setBoolPref( "installedButton", true ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("contentAreaContextMenu")
|
document.getElementById("contentAreaContextMenu").
|
||||||
.addEventListener("popupshowing", function (e){ sendtophone.showFirefoxContextMenu(e); }, false);
|
addEventListener("popupshowing", function (e){ sendtophone.showFirefoxContextMenu(e); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendtophone.installToolbarButton = function()
|
sendtophone.installToolbarButton = function()
|
||||||
@@ -74,7 +74,7 @@ sendtophone.onOptionsShowing= function(popup)
|
|||||||
var option = child.getAttribute("option");
|
var option = child.getAttribute("option");
|
||||||
if (option)
|
if (option)
|
||||||
{
|
{
|
||||||
var checked = this.prefs.getBoolPref("protocols."+option);
|
var checked = this.prefs.getBoolPref("protocols."+option);
|
||||||
child.setAttribute("checked", checked);
|
child.setAttribute("checked", checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,11 +102,11 @@ sendtophone.showFirefoxContextMenu = function(event) {
|
|||||||
gContextMenu.showItem("context-sendtophone-image", true);
|
gContextMenu.showItem("context-sendtophone-image", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
gContextMenu.showItem("context-sendtophone-text", gContextMenu.isTextSelected ||
|
gContextMenu.showItem("context-sendtophone-text", gContextMenu.isTextSelected ||
|
||||||
(gContextMenu.onTextInput && gContextMenu.target.selectionEnd > gContextMenu.target.selectionStart) );
|
(gContextMenu.onTextInput && gContextMenu.target.selectionEnd > gContextMenu.target.selectionStart) );
|
||||||
|
|
||||||
gContextMenu.showItem("context-sendtophone-page", !( gContextMenu.inDirList || gContextMenu.isContentSelected || gContextMenu.onTextInput || gContextMenu.onLink || gContextMenu.onImage ));
|
gContextMenu.showItem("context-sendtophone-page", !( gContextMenu.inDirList || gContextMenu.isContentSelected || gContextMenu.onTextInput || gContextMenu.onLink || gContextMenu.onImage ));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -119,9 +119,9 @@ sendtophone.checkDrag = function(event)
|
|||||||
var types = event.dataTransfer.types;
|
var types = event.dataTransfer.types;
|
||||||
if (types.contains("text/plain") || types.contains("text/uri-list") || types.contains("text/x-moz-url"))
|
if (types.contains("text/plain") || types.contains("text/uri-list") || types.contains("text/x-moz-url"))
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (this.prefs.getCharPref( "fileServerUrl" ) && types.contains("application/x-moz-file") )
|
if (this.prefs.getCharPref( "fileServerUrl" ) && types.contains("application/x-moz-file") )
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
sendtophone.doDrop = function(event)
|
sendtophone.doDrop = function(event)
|
||||||
@@ -129,8 +129,8 @@ sendtophone.doDrop = function(event)
|
|||||||
var dt = event.dataTransfer;
|
var dt = event.dataTransfer;
|
||||||
var types = dt.types;
|
var types = dt.types;
|
||||||
var supportedTypes = ["application/x-moz-file", "text/x-moz-url", "text/uri-list", "text/plain"];
|
var supportedTypes = ["application/x-moz-file", "text/x-moz-url", "text/uri-list", "text/plain"];
|
||||||
types = supportedTypes.filter(function (value) types.contains(value));
|
types = supportedTypes.filter(function (value) {return types.contains(value)});
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
switch (types[0])
|
switch (types[0])
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ sendtophone.doDrop = function(event)
|
|||||||
var plainText = dt.getData(types[0]);
|
var plainText = dt.getData(types[0]);
|
||||||
sendtophoneCore.send("Selection", "http://google.com", plainText);
|
sendtophoneCore.send("Selection", "http://google.com", plainText);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "text/x-moz-url":
|
case "text/x-moz-url":
|
||||||
var mozUrlArray = dt.getData(types[1]).split("\n");
|
var mozUrlArray = dt.getData(types[1]).split("\n");
|
||||||
var mozUrl = mozUrlArray[0];
|
var mozUrl = mozUrlArray[0];
|
||||||
@@ -173,16 +173,16 @@ sendtophone.pickFile = function(folder)
|
|||||||
fp.init(window, this.getString("SendFolderToPhone"), Ci.nsIFilePicker.modeGetFolder);
|
fp.init(window, this.getString("SendFolderToPhone"), Ci.nsIFilePicker.modeGetFolder);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fp.init(window, this.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple);
|
fp.init(window, this.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple);
|
||||||
fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterImages);
|
fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rv = fp.show();
|
var rv = fp.show();
|
||||||
|
|
||||||
if (rv == Ci.nsIFilePicker.returnOK)
|
if (rv == Ci.nsIFilePicker.returnOK)
|
||||||
{
|
{
|
||||||
var files = fp.files;
|
var files = fp.files;
|
||||||
while (files.hasMoreElements())
|
while (files.hasMoreElements())
|
||||||
{
|
{
|
||||||
var file = files.getNext().QueryInterface(Ci.nsILocalFile);
|
var file = files.getNext().QueryInterface(Ci.nsILocalFile);
|
||||||
sendtophoneCore.sendFile( file );
|
sendtophoneCore.sendFile( file );
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2010 Alfonso Martínez de Lizarrondo & Patrick O'Reilly
|
Copyright 2010 Alfonso Martínez de Lizarrondo & Patrick O'Reilly
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -51,7 +51,7 @@ var sendtophone = {
|
|||||||
var match = url.match(/^http:\/\/chart.apis.google.com\/chart\?(.*)/i);
|
var match = url.match(/^http:\/\/chart.apis.google.com\/chart\?(.*)/i);
|
||||||
if (!match)
|
if (!match)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var chartLink=/^chl=/;
|
var chartLink=/^chl=/;
|
||||||
var qrArray = match[0].split("&");
|
var qrArray = match[0].split("&");
|
||||||
for(var qrI=0; qrI<qrArray.length; qrI++){
|
for(var qrI=0; qrI<qrArray.length; qrI++){
|
||||||
@@ -84,7 +84,7 @@ var sendtophone = {
|
|||||||
url = data;
|
url = data;
|
||||||
else
|
else
|
||||||
selection = data;
|
selection = data;
|
||||||
|
|
||||||
//If the QR Image has no title text, give it one.
|
//If the QR Image has no title text, give it one.
|
||||||
if (!title)
|
if (!title)
|
||||||
title=this.getString("qrTitle");
|
title=this.getString("qrTitle");
|
||||||
@@ -109,18 +109,19 @@ var sendtophone = {
|
|||||||
case 'pageButton':
|
case 'pageButton':
|
||||||
// Check if there's a single image with a QR code in the contents
|
// Check if there's a single image with a QR code in the contents
|
||||||
var images = gBrowser.contentDocument.getElementsByTagName( "img" );
|
var images = gBrowser.contentDocument.getElementsByTagName( "img" );
|
||||||
|
|
||||||
// 0: search and prompt, 1: search and launch automatically, 2: don't search
|
// 0: search and prompt, 1: search and launch automatically, 2: don't search
|
||||||
var pref = this.prefs.getIntPref("SearchQR")
|
var pref = this.prefs.getIntPref("SearchQR");
|
||||||
if (pref!=2)
|
if (pref!=2)
|
||||||
{
|
{
|
||||||
var QRs = [];
|
var QRs = [];
|
||||||
for( var i=0; i<images.length; i++)
|
for( var i=0; i<images.length; i++)
|
||||||
{
|
{
|
||||||
var data = this.detectQR( images[i].src );
|
var imgData = this.detectQR( images[i].src );
|
||||||
if (data)
|
if (imgData)
|
||||||
QRs.push({data: data, img: images[i]});
|
QRs.push({data: data, img: images[i]});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QRs.length==1)
|
if (QRs.length==1)
|
||||||
{
|
{
|
||||||
var data = QRs[0].data;
|
var data = QRs[0].data;
|
||||||
@@ -132,25 +133,25 @@ var sendtophone = {
|
|||||||
if (answer.remember)
|
if (answer.remember)
|
||||||
this.prefs.setIntPref("SearchQR", pref);
|
this.prefs.setIntPref("SearchQR", pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pref!=2 )
|
if ( pref!=2 )
|
||||||
{
|
{
|
||||||
title = QRs[0].img.title || QRs[0].img.alt;
|
title = QRs[0].img.title || QRs[0].img.alt;
|
||||||
|
|
||||||
if (this.validURI(data))
|
if (this.validURI(data))
|
||||||
url = data;
|
url = data;
|
||||||
else
|
else
|
||||||
selection = data;
|
selection = data;
|
||||||
|
|
||||||
if (!title)
|
if (!title)
|
||||||
title=this.getString("qrTitle");
|
title=this.getString("qrTitle");
|
||||||
|
|
||||||
// We got the data, break out of the select
|
// We got the data, break out of the select
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // pref != 2
|
} // pref != 2
|
||||||
|
|
||||||
// fall through
|
// fall through
|
||||||
case 'page':
|
case 'page':
|
||||||
default:
|
default:
|
||||||
@@ -178,10 +179,10 @@ var sendtophone = {
|
|||||||
{
|
{
|
||||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||||
.getService(Ci.nsIPromptService);
|
.getService(Ci.nsIPromptService);
|
||||||
|
|
||||||
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#confirmEx
|
// https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService#confirmEx
|
||||||
var check = {value: false};
|
var check = {value: false};
|
||||||
|
|
||||||
var button = promptService.confirmEx(window, this.getString("SendToPhoneTitle"),
|
var button = promptService.confirmEx(window, this.getString("SendToPhoneTitle"),
|
||||||
text, promptService.STD_YES_NO_BUTTONS, "", "", "", this.getString("RememberMyDecision"), check);
|
text, promptService.STD_YES_NO_BUTTONS, "", "", "", this.getString("RememberMyDecision"), check);
|
||||||
// confirmEx returns the pressed button, and Yes it's the first one.
|
// confirmEx returns the pressed button, and Yes it's the first one.
|
||||||
@@ -196,7 +197,7 @@ var sendtophone = {
|
|||||||
getInfo: function() {
|
getInfo: function() {
|
||||||
var doc = gBrowser.contentDocument,
|
var doc = gBrowser.contentDocument,
|
||||||
href = doc.location.href;
|
href = doc.location.href;
|
||||||
|
|
||||||
// Is it the Google Maps page?
|
// Is it the Google Maps page?
|
||||||
if (this.isMapsURL(href))
|
if (this.isMapsURL(href))
|
||||||
{
|
{
|
||||||
@@ -204,7 +205,7 @@ var sendtophone = {
|
|||||||
var link = doc.getElementById('link');
|
var link = doc.getElementById('link');
|
||||||
if (link && link.href)
|
if (link && link.href)
|
||||||
href = link.href;
|
href = link.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||||
var selection = focusedWindow.getSelection().toString();
|
var selection = focusedWindow.getSelection().toString();
|
||||||
@@ -236,7 +237,7 @@ var sendtophone = {
|
|||||||
document.getElementById("sendtophoneContextMenuSendFolder").hidden = true;
|
document.getElementById("sendtophoneContextMenuSendFolder").hidden = true;
|
||||||
}
|
}
|
||||||
document.getElementById("sendtophoneContextMenuSendClipboard").disabled = !this.clipboardHasText();
|
document.getElementById("sendtophoneContextMenuSendClipboard").disabled = !this.clipboardHasText();
|
||||||
|
|
||||||
// returning true will make the popup show
|
// returning true will make the popup show
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -251,39 +252,39 @@ var sendtophone = {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
sendClipboard : function()
|
sendClipboard : function()
|
||||||
{
|
{
|
||||||
// https://developer.mozilla.org/en/using_the_clipboard
|
// https://developer.mozilla.org/en/using_the_clipboard
|
||||||
// Access Clipboard
|
// Access Clipboard
|
||||||
var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
|
var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
|
||||||
if (!clip) return false;
|
if (!clip) return;
|
||||||
|
|
||||||
if (!clip.hasDataMatchingFlavors(["text/unicode"], 1, clip.kGlobalClipboard))
|
if (!clip.hasDataMatchingFlavors(["text/unicode"], 1, clip.kGlobalClipboard))
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
|
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
|
||||||
if (!trans) return false;
|
if (!trans) return;
|
||||||
trans.addDataFlavor("text/unicode");
|
trans.addDataFlavor("text/unicode");
|
||||||
|
|
||||||
// Get the data
|
// Get the data
|
||||||
clip.getData(trans, clip.kGlobalClipboard);
|
clip.getData(trans, clip.kGlobalClipboard);
|
||||||
|
|
||||||
var str = new Object();
|
var str = new Object();
|
||||||
var strLength = new Object();
|
var strLength = new Object();
|
||||||
var pastetext;
|
var pastetext;
|
||||||
|
|
||||||
trans.getTransferData("text/unicode", str, strLength);
|
trans.getTransferData("text/unicode", str, strLength);
|
||||||
|
|
||||||
// Convert to js string
|
// Convert to js string
|
||||||
if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
|
if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
|
||||||
if (str) pastetext = str.data.substring(0, strLength.value / 2);
|
if (str) pastetext = str.data.substring(0, strLength.value / 2);
|
||||||
|
|
||||||
// Send it.
|
// Send it.
|
||||||
if (pastetext)
|
if (pastetext)
|
||||||
sendtophoneCore.send("Clipboard", "http://google.com", pastetext);
|
sendtophoneCore.send("Clipboard", "http://google.com", pastetext);
|
||||||
},
|
},
|
||||||
|
|
||||||
logout: function()
|
logout: function()
|
||||||
{
|
{
|
||||||
sendtophoneCore.logout();
|
sendtophoneCore.logout();
|
||||||
|
|||||||
@@ -31,10 +31,16 @@ function addFile(upload)
|
|||||||
gUploadsView.appendChild( dl );
|
gUploadsView.appendChild( dl );
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPendingUploads()
|
var checkTimerEvent =
|
||||||
{
|
{
|
||||||
if (gUploadsView.children.length==0)
|
notify: function(timer)
|
||||||
window.close();
|
{
|
||||||
|
if (sendtophoneUploadsManager.isWindowNeeded())
|
||||||
|
{
|
||||||
|
if (gUploadsView.children.length==0)
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelUpload(item)
|
function cancelUpload(item)
|
||||||
@@ -52,7 +58,7 @@ let gUploadListener = {
|
|||||||
let item = document.getElementById( "upl" + data.id);
|
let item = document.getElementById( "upl" + data.id);
|
||||||
item.setAttribute("currBytes", data.currBytes);
|
item.setAttribute("currBytes", data.currBytes);
|
||||||
item.setAttribute("maxBytes", data.maxBytes);
|
item.setAttribute("maxBytes", data.maxBytes);
|
||||||
|
|
||||||
let percentComplete = Math.round(100 * data.currBytes / data.maxBytes);
|
let percentComplete = Math.round(100 * data.currBytes / data.maxBytes);
|
||||||
item.setAttribute("progress", percentComplete);
|
item.setAttribute("progress", percentComplete);
|
||||||
|
|
||||||
@@ -63,10 +69,12 @@ let gUploadListener = {
|
|||||||
{
|
{
|
||||||
let item = document.getElementById("upl" + data.id);
|
let item = document.getElementById("upl" + data.id);
|
||||||
gUploadsView.removeChild(item);
|
gUploadsView.removeChild(item);
|
||||||
|
|
||||||
// If no more pending uploads, close the tab.
|
// If no more pending uploads, close the tab.
|
||||||
// Use a 0 ms timeout to avoid flicker while compress -> upload a folder
|
// Use a 0 ms timeout to avoid flicker while compress -> upload a folder
|
||||||
window.setTimeout( checkPendingUploads, 0);
|
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||||
|
checkTimer.initWithCallback(checkTimerEvent, 0, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,22 +147,22 @@ function performCommand(aCmd, aItem)
|
|||||||
gUploadViewController.doCommand(aCmd, elm);
|
gUploadViewController.doCommand(aCmd, elm);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatus(aItem)
|
function updateStatus(aItem)
|
||||||
{
|
{
|
||||||
let currBytes = Number(aItem.getAttribute("currBytes"));
|
let currBytes = Number(aItem.getAttribute("currBytes"));
|
||||||
let maxBytes = Number(aItem.getAttribute("maxBytes"));
|
let maxBytes = Number(aItem.getAttribute("maxBytes"));
|
||||||
|
|
||||||
let elapsedTime = (Date.now() - Number(aItem.getAttribute("startTime"))) / 1000;
|
let elapsedTime = (Date.now() - Number(aItem.getAttribute("startTime"))) / 1000;
|
||||||
// If we don't have an active upload, assume 0 bytes/sec
|
// If we don't have an active upload, assume 0 bytes/sec
|
||||||
let speed = (currBytes>0) ? currBytes/elapsedTime : 0;
|
let speed = (currBytes>0) ? currBytes/elapsedTime : 0;
|
||||||
let lastSec = Number(aItem.getAttribute("lastSeconds"));
|
let lastSec = Number(aItem.getAttribute("lastSeconds"));
|
||||||
|
|
||||||
let status, newLast;
|
let status, newLast;
|
||||||
[status, newLast] =
|
[status, newLast] =
|
||||||
DownloadUtils.getDownloadStatus(currBytes, maxBytes, speed, lastSec);
|
DownloadUtils.getDownloadStatus(currBytes, maxBytes, speed, lastSec);
|
||||||
|
|
||||||
// Update lastSeconds to be the new value
|
// Update lastSeconds to be the new value
|
||||||
aItem.setAttribute("lastSeconds", newLast);
|
aItem.setAttribute("lastSeconds", newLast);
|
||||||
|
|
||||||
aItem.setAttribute("status", status);
|
aItem.setAttribute("status", status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ function initShowTest()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Now it is time to create the timer...
|
// Now it is time to create the timer...
|
||||||
showTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
showTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||||
showTimer.initWithCallback(showTimerEvent, 400, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
showTimer.initWithCallback(showTimerEvent, 400, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +235,9 @@ function cancelShowTimer()
|
|||||||
|
|
||||||
// https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#Reusing_tabs
|
// https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#Reusing_tabs
|
||||||
function openAndReuseOneTabPerURL(url) {
|
function openAndReuseOneTabPerURL(url) {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
|
||||||
.getService(Components.interfaces.nsIWindowMediator);
|
.getService(Ci.nsIWindowMediator);
|
||||||
var browserEnumerator = wm.getEnumerator("navigator:browser");
|
var browserEnumerator = wm.getEnumerator("navigator:browser");
|
||||||
|
|
||||||
// Check each browser instance for our URL
|
// Check each browser instance for our URL
|
||||||
var found = false;
|
var found = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user