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