Das Addon soll über einen Eintrag im Kontextmenü Dokumente zu Google Docs hochladen. Das tut es auch; ABER: bei allen Dokumententypen außer .xls, wird das Dokument nicht sofort angezeigt nach dem Upload. .xls Dateien werden sofort nach dem Upload angezeigt.
Ursache ist folgende Zeile:
wenn keine ID empfangen wird, wird ganz einfach auf die Docs Hauptseite umgeleitet.
Was ich nicht verstehe, ist, warum nur .xls Dateien IDs empfangen und alle anderen nicht...
Blickt da wer durch?
Code
var openingoogledocs = {
onLoad: function() {
this.initialized = true;
this.strings = document.getElementById("openingoogledocs-strings");
document.getElementById("contentAreaContextMenu")
.addEventListener("popupshowing", function(e) { this.showContextMenu(e); }, false);
},
showContextMenu: function(event) {
document.getElementById("context-openingoogledocs").hidden = gContextMenu.onImage;
},
onMenuItemCommand: function(e) {
if (gContextMenu.onLink && !gContextMenu.onImage) {
var docurl = gContextMenu.getLinkURL();
if(docurl.match(/^http:.*\.(html|htm|pdf|xls|doc|ppt|csv|txt|rtf|odt|sxw|pps|ods)$/i)) {
getToken(encodeURI(decodeURI(docurl)));
}
}
},
};
window.addEventListener("load", function(e) { openingoogledocs.onLoad(e); }, false);
/*
* Gets the security token from Google
*
* Params:
* aURL - location of the document
*/
function getToken(aURL) {
xhr = new XMLHttpRequest();
// Google Docs upload form
xhr.open('GET', 'https://docs.google.com/DocAction?action=updoc&hl=en');
xhr.onreadystatechange = function (aEvent) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var pattern = /<input>/;
var patternSpreadsheet = /"key":"([^"]+)"/;
var patternPresentation = /"revision":"([^:]+):"/;
var matches = xhr.responseText.match(patternDoc);
if (matches) { // retrieved document id successfully - open document
Utils.openUrlInBrowser('https://docs.google.com/Doc?id=' + matches[1]);
return;
}
matches = xhr.responseText.match(patternFile);
if (matches) { // retrieved file id successfully - open document
gBrowser.addTab('https://docs.google.com/fileview?id=' + matches[1]);
return;
}
matches = xhr.responseText.match(patternSpreadsheet);
if (matches) { // retrieved spreadsheet id successfully - open document
gBrowser.addTab('https://spreadsheets.google.com/ccc?key=' + matches[1]);
return;
}
matches = xhr.responseText.match(patternPresentation);
if (matches) { // retrieved presentation id successfully - open document
gBrowser.addTab('https://docs.google.com/Presentation?docid=' + matches[1]);
return;
}
// ID Empfang erfolglos - Umleiten
gBrowser.addTab('http://docs.google.com/#all');
}
}
xhr.send(postData);
}
Alles anzeigen
danke vorab[/code]