gelöst [Java] Tumblr Post addon bearbeiten

Joined
Apr 6, 2007
Messages
91
Points
0
moin moin,
ich möchte das Firefox plugin Tumblr Post etwas bearbeiten und zwar nur an einer ganz bestimmten stelle.
Leider hab keine Ahnung vom Programmieren, ich versuche mich mit suchen und etwas logischem denken durch zuschlagen.

Es gibt die eine Funktion, das wenn man ein Bild postet, das automatisch die quelle eingefügt wird:
PHP:
 <checkbox label="Automatically set a click-through link for photos" preference="pref_photo_click_through" style="padding: 0 0 0 5px; margin: 3px 0 6px 0" tooltiptext="Checking this will set a click-through link to the url the photo was posted from" />

Nun ich möchte das ein festgelegter link eingefügt wird und nicht der der Quelle (Mit link meine ich z.b. http://www.united-forum.de/).
Ich hab schon raus gefunden das ich es in dieser Datei bearbeiten muss. Und wenn ich nach dem
begriff through suche komme ich an die richtigen stellen, nur bin ich grade
etwas überfordert was ich da ändern muss.

PHP:
var TumblrPost = {

	init: function() {
		
		this.prefObserver.register();
		
		this.initprefs();
		this.initToolbarIcon();		
		this.initContextMenu();

		if (this.tumblrUrl == '') {
			this.setTumblrUrl();
		}
			
	},
	
	prefsWin: null,

	initprefs: function() {
		try {
			
			var prefService = Components.classes['@mozilla.org/preferences-service;1']
			.getService(Components.interfaces.nsIPrefService);

			var prefs = prefService.getBranch('extensions.tumblrpost.');
			prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
			
			if (prefs.prefHasUserValue('email')) {
				prefs.setCharPref('email', '');				
			}
			
			if (prefs.prefHasUserValue('password')) {
				prefs.setCharPref('password', '');
			}
			
			this.tumblrUrl = prefs.getCharPref('tumblrUrl');
			this.gotoDashboard = prefs.getBoolPref('gotoDashboard');
			this.gotoTumblelog = prefs.getBoolPref('gotoTumblelog');
			this.dashboardNewTab = prefs.getBoolPref('dashboardNewTab');
			this.urlAsQouteSource = prefs.getBoolPref('urlAsQouteSource');
			this.photoCaptions = prefs.getBoolPref('photoCaptions');
			this.quoteSources = prefs.getBoolPref('quoteSources');
			this.linkDescriptions = prefs.getBoolPref('linkDescriptions');
			this.videoCaptions = prefs.getBoolPref('videoCaptions');
			this.audioCaptions = prefs.getBoolPref('audioCaptions');
			this.textTitles = prefs.getBoolPref('textTitles');			
			this.textPublishState = prefs.getCharPref('textPublishState');
			this.photoPublishState = prefs.getCharPref('photoPublishState');
			this.quotePublishState = prefs.getCharPref('quotePublishState');
			this.linkPublishState = prefs.getCharPref('linkPublishState');
			this.audioPublishState = prefs.getCharPref('audioPublishState');
			this.videoPublishState = prefs.getCharPref('videoPublishState');						
			this.textInsteadOfQuotes = prefs.getBoolPref('textInsteadOfQuotes');
			this.postTumblelog = prefs.getCharPref('postTumblelog');
			this.photoClickThrough = prefs.getBoolPref('photoClickThrough');
			this.hidePhotoContext = prefs.getBoolPref('hidePhotoContext');
			this.hideTextContext = prefs.getBoolPref('hideTextContext');
			this.hideLinkContext = prefs.getBoolPref('hideLinkContext');
			this.hideVideoContext = prefs.getBoolPref('hideVideoContext');
			this.hideQuoteContext = prefs.getBoolPref('hideQuoteContext');
			this.hideAudioContext = prefs.getBoolPref('hideAudioContext');
			this.hideReblogContext = prefs.getBoolPref('hideReblogContext');

		} catch (e) { //set defaults
			
			prefs.setCharPref('tumblrUrl', '');
			prefs.setBoolPref('gotoDashboard', false);
			prefs.setBoolPref('gotoTumblelog', false);
			prefs.setBoolPref('dashboardNewTab', false);
			prefs.setBoolPref('urlAsQouteSource', false);
			prefs.setBoolPref('photoCaptions', false);
			prefs.setBoolPref('quoteSources', false);
			prefs.setBoolPref('linkDescriptions', false);
			prefs.setBoolPref('videoCaptions', false);
			prefs.setBoolPref('audioCaptions', false);
			prefs.setBoolPref('textTitles', false);			
			prefs.setCharPref('textPublishState', 'published');
			prefs.setCharPref('photoPublishState', 'published');
			prefs.setCharPref('quotePublishState', 'published');
			prefs.setCharPref('linkPublishState', 'published');
			prefs.setCharPref('videoPublishState', 'published');
			prefs.setCharPref('audioPublishState', 'published');						
			prefs.setBoolPref('textInsteadOfQuotes', false);
			prefs.setCharPref('postTumblelog', '');
			prefs.setBoolPref('photoClickThrough', false);
			prefs.setBoolPref('hidePhotoContext', false);
			prefs.setBoolPref('hideTextContext', false);
			prefs.setBoolPref('hideLinkContext', false);
			prefs.setBoolPref('hideVideoContext', false);
			prefs.setBoolPref('hideQuoteContext', false);
			prefs.setBoolPref('hideAudioContext', false);
			prefs.setBoolPref('hideReblogContext', false);
			
			this.initprefs();
		}
	},

	initContextMenu: function() {

		var contextMenu = document.getElementById('contentAreaContextMenu');
		if (contextMenu) {

			this.createMenuItem(contextMenu, 'Post photo to my tumblelog', function() { TumblrPost.postPhotoFromMenu(); }, false, 'tumblr-post-photo');
			this.createMenuItem(contextMenu, 'Post quote to my tumblelog', function() { TumblrPost.postTextFromMenu(); }, false, 'tumblr-post-text');
			this.createMenuItem(contextMenu, 'Post link to my tumblelog', function() { TumblrPost.postLinkFromMenu(); }, false, 'tumblr-post-link');
			this.createMenuItem(contextMenu, 'Post audio file to my tumblelog', function() { TumblrPost.postAudioFromMenu(); }, false, 'tumblr-post-audio');
			this.createMenuItem(contextMenu, 'Reblog this post', function() { TumblrPost.reblogPostFromMenu(); }, false, 'tumblr-reblog-post');
			
			contextMenu.addEventListener('popupshowing', function() { TumblrPost.onShowContextMenu(); } , false);

		}
	},
	
	initToolbarIcon: function() {		
		if (!Application.extensions) {
			Application.getExtensions(function (extensions) {
				var addonBar = document.getElementById('addon-bar');
				if (!addonBar) return;
				
				let ext = extensions.get('{99210d54-6321-41e8-bd1b-2b4c55874efb}');	
				if (ext && ext.firstRun) {
					var currSet = addonBar.currentSet.split(',');
					var btnId = 'tumblr-post-btn';
					if (currSet.indexOf(btnId) == -1) {
						var pos = currSet.length;
						var newSet = currSet.slice(0, pos).concat(btnId).concat(currSet.slice(pos));
						addonBar.setAttribute('currentset', newSet.join(','));
						addonBar.currentSet = newSet.join(',');	
						document.persist(addonBar.id, 'currentset');
						try {
							BrowserToolboxCustomizeDone(true);
						} catch (e) {}
					}
				}			
			});
		}		
	},	
	
	onShowContextMenu: function() {		
		
		if (gContextMenu) {
			
			gContextMenu.showItem('tumblr-post-photo', gContextMenu.onImage && !this.hidePhotoContext);
						
			gContextMenu.showItem('tumblr-post-audio', gContextMenu.onSaveableLink && 
											/\.mp3$/gi.test(gContextMenu.getLinkURL()) && !this.hideAudioContext);
																						
			gContextMenu.showItem('tumblr-post-link', gContextMenu.onSaveableLink && 
											!/\.mp3$/gi.test(gContextMenu.getLinkURL()) && !this.hideLinkContext);
			
			gContextMenu.showItem('tumblr-reblog-post', gContextMenu.onSaveableLink &&
											this.getPermalinkPostId(gContextMenu.getLinkURL()) && !this.hideReblogContext);
						
			var textMenuItem = document.getElementById('tumblr-post-text');
			if (textMenuItem) {
				var show = true;
				var txt = this.getSelection(document.popupNode);
				if(this.isVideo(txt)) {
					textMenuItem.setAttribute('label', 'Post video to my tumblelog');
					if (this.hideVideoContext) show = false;				
				} else if (this.isCurrentPageUrl(txt)) {
					textMenuItem.setAttribute('label', 'Post current page to my tumblelog');
				} else {
					if (this.textInsteadOfQuotes) {
						textMenuItem.setAttribute('label', 'Post text to my tumblelog');
						if (this.hideTextContext) show = false;
					} else {
						textMenuItem.setAttribute('label', 'Post quote to my tumblelog');
						if (this.hideQuoteContext) show = false;
					}
				} 
				gContextMenu.showItem('tumblr-post-text', (txt.length > 0) && show);										
			}	

		}
		
	},
	
	openPrefs: function(event) {
		if (null == this.prefsWin || this.prefsWin.closed) {
			let instaApply = Application.prefs.get('browser.preferences.instantApply');
			let feats = 'chrome,centerscreen' +
				(instaApply.value ? ',dialog=no' : ',modal');
		
			this.prefsWin = window.openDialog(
				'chrome://TumblrPost/content/prefsWindow.xul',
				'prefs-win', feats);
		}
		
		this.prefsWin.focus();		
	},
	
	getTumblrEmail: function() {

		var hostName = 'chrome://TumblrPost';
		
		if ('@mozilla.org/passwordmanager;1' in Components.classes) {

			var passwordManager = Components.classes['@mozilla.org/passwordmanager;1']
			                    .getService(Components.interfaces.nsIPasswordManager);
			
			var e = passwordManager.enumerator;
			
			while (e.hasMoreElements()) {
				try {
					var pass = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
					if (pass.host == hostName) {
						return pass.user;
					}
				} catch (ex) {}
			}		
			
		} else if ('@mozilla.org/login-manager;1' in Components.classes) {
	
			var passwordManager = Components.classes['@mozilla.org/login-manager;1']
			                                .getService(Components.interfaces.nsILoginManager);
	
			var nsLoginInfo = new Components.Constructor('@mozilla.org/login-manager/loginInfo;1',
			                                             Components.interfaces.nsILoginInfo,		
			                                             'init');				
			                                             
			var logins = passwordManager.findLogins({}, hostName, '', null);
			
			if (logins.length > 0) {
				return logins[0].username;	
			}		                                             
		}
		return '';		
	},
	
	getTumblrPassword: function() {
		
		var hostName = 'chrome://TumblrPost';
		
		if ('@mozilla.org/passwordmanager;1' in Components.classes) {

			var passwordManager = Components.classes['@mozilla.org/passwordmanager;1']
			                    .getService(Components.interfaces.nsIPasswordManager);
			
			var e = passwordManager.enumerator;
			
			while (e.hasMoreElements()) {
				try {
					var pass = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
					if (pass.host == hostName) {
						return pass.password;
					}
				} catch (ex) {}
			}		
			
		} else if ('@mozilla.org/login-manager;1' in Components.classes) {
					
			var passwordManager = Components.classes['@mozilla.org/login-manager;1']
			                                .getService(Components.interfaces.nsILoginManager);
	
			var nsLoginInfo = new Components.Constructor('@mozilla.org/login-manager/loginInfo;1',
			                                             Components.interfaces.nsILoginInfo,		
			                                             'init');				
			                                             
			var logins = passwordManager.findLogins({}, hostName, '', null);
			
			if (logins.length > 0) {
				return logins[0].password;	
			}
		}		
		return ''; 		
	}, 	

	goToDashboard: function() {
		var dashboardUrl = 'http://www.tumblr.com/dashboard/';
		if (this.dashboardNewTab) {
			gBrowser.selectedTab = gBrowser.addTab(dashboardUrl);
		} else {
			window.content.location = dashboardUrl;
		}
	},

	goToTumbleLog: function() {
		window.content.location = this.tumblrUrl;
	},

	populateMenu: function(item, event) {
			
		if(((event.which) && (event.which == 3)) || ((event.button) && (event.button == 2))) {
			
			var statusBarMenu = document.getElementById('tumblr-post-context-menu');			 

			this.clearMenu(statusBarMenu);
			
			if (statusBarMenu) {
				this.createMenuItem(statusBarMenu, 'Go to dashboard', function() { TumblrPost.goToDashboard(); }, false, 'gotoDashboard');
				if (this.tumblrUrl != '') {
					this.createMenuItem(statusBarMenu, 'Go to tumblelog', function() { TumblrPost.goToTumbleLog(); }, false, 'gotoTumbleLog');
				}
					
				statusBarMenu.appendChild(document.createElement('menuseparator'));				
				statusBarMenu.appendChild(this.createTumblelogsMenu());				
				statusBarMenu.appendChild(document.createElement('menuseparator'));
				
				this.createMenuItem(statusBarMenu, 'Settings...', function(event) { TumblrPost.openPrefs(event); }, false, 'menuSettings');
				this.createMenuItem(statusBarMenu, 'Write text entry...', function() { TumblrPost.openTextEntry(); }, false, 'textEntry');
				this.createMenuItem(statusBarMenu, 'Post photo...', function() { TumblrPost.openFileDialog("photo"); }, false, 'postPhoto');
				this.createMenuItem(statusBarMenu, 'Post audio file...', function() { TumblrPost.openFileDialog("audio"); }, false, 'postAudio');			
				this.createMenuItem(statusBarMenu, 'Post current page', function() { TumblrPost.postCurrentPage(); }, false, 'postCurrentPage');
			}
		} else {
			if (this.gotoDashboard) {
				this.goToDashboard();
			} else if (this.gotoTumblelog) {
				this.goToTumbleLog();
			} else {
				return false;
			}
		}
	},

	createMenuItem: function(menu, label, command, disabled, menuId) {
		var menuItem = document.createElement('menuitem');
		menuItem.setAttribute('label', label);
				
		if (typeof command == 'function') {
			menuItem.addEventListener('command', command, false);
		}
			
		menuItem.setAttribute('disabled', disabled);
		menuItem.setAttribute('id', menuId);
	
		menu.appendChild(menuItem);
	},

	clearMenu: function(menu) {
		while(menu.hasChildNodes()) {
			menu.removeChild(menu.firstChild);
		}
	},
		
	createTumblelogsMenu: function() {
		var menu = document.createElement('menu');
		menu.setAttribute('label', 'Tumblelogs');		
		
		var menupopup = document.createElement('menupopup');			
		
		menupopup.addEventListener('popupshowing', function() { TumblrPost.populateTumblelogs(this); }, false);
		menupopup.addEventListener('popuphiding', function() { TumblrPost.clearMenu(this); }, false);
		
		menu.appendChild(menupopup);				
		return menu;
	},
	
	populateTumblelogs: function(menu) {
	
		var loading = document.createElement('menuitem');
		loading.setAttribute('label', 'Loading...');
		loading.setAttribute('disabled', 'true');
	
		var error = document.createElement('menuitem');
		error.setAttribute('label', 'Could not fetch tumblelogs');
		error.setAttribute('disabled', 'true');

		var email = this.getTumblrEmail();
		var password = this.getTumblrPassword();
		
		if (email != '' && password != '') {
			
			var params = {};  	
			params.email = email;
			params.password = password;
  			
			var body = this.getRegularBody(params);
			
			var xhReq = new XMLHttpRequest();
	
			xhReq.onreadystatechange = function () {
				
				if (xhReq.readyState == 1) {

					menu.appendChild(loading);
					
				} else if (xhReq.readyState == 4) {
					
					menu.removeChild(loading);
					var selectedIndex = 0;
					
					if (xhReq.status == 200) {
					
						var tumblelogs = xhReq.responseXML.getElementsByTagName('tumblelog');
	
						for (var i = 0; i < tumblelogs.length; i++) {
							
							var menuitem = document.createElement('menuitem');
							menuitem.setAttribute('type', 'radio');
							menuitem.setAttribute('name', 'tumblelog');
							
							var label = tumblelogs[i].getAttribute('title');
							var type = tumblelogs[i].getAttribute('type');
							var value = '';
							if (type == 'public') {
								if (tumblelogs[i].hasAttribute('is-primary')) {
									value = 'primary';
									label += ' (Primary)';
								} else { 
									value = TumblrPost.getUrlHost(tumblelogs[i].getAttribute('url'));
								}
							} else {
								value = tumblelogs[i].getAttribute('private-id');
							}
				
							if (value == TumblrPost.postTumblelog) {
								selectedIndex = i;
								menuitem.setAttribute('checked', 'true');
							}
																			
							menuitem.setAttribute('value', value);
							menuitem.setAttribute('label', label);
							
							if (menu.parentNode.id != 'menuTumblelogs') {							
								menuitem.addEventListener('command', function() {
									
									var prefService = Components.classes['@mozilla.org/preferences-service;1']
									.getService(Components.interfaces.nsIPrefService);
					
									var prefs = prefService.getBranch('extensions.tumblrpost.');
									prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
									
									prefs.setCharPref('postTumblelog', this.getAttribute('value'));							
		
								}, false);								
							}
							
							menu.appendChild(menuitem);
							
						}
												
					} else {
						menu.appendChild(error);
					}
					
					if (menu.parentNode.id == 'menuTumblelogs') {
						menu.parentNode.selectedIndex = selectedIndex;
						if (xhReq.status != 200) {
							menu.parentNode.disabled = true;
						}
					}					
					
				}
			};
				
			xhReq.open("POST", "http://www.tumblr.com/api/authenticate", true);
			xhReq.setRequestHeader("Cache-Control", "no-cache");
			xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
			xhReq.setRequestHeader("Content-length", body.length);
	
			xhReq.send(body);
				
		} else {
			menu.appendChild(error);			
		}
	},
	
	showProgress: function() {
		var progressBar = document.getElementById('tumblr-post-progress');
		var addonBar = document.getElementById('addon-bar');
		var btnId = 'tumblr-post-btn';
		var btn = document.getElementById(btnId);
	
		progressBar.removeAttribute('value');
		progressBar.setAttribute('mode', 'undetermined');	
		progressBar.removeAttribute('collapsed');
		
		if (addonBar) {
			var currSet = addonBar.currentSet.split(',');
			if (currSet.indexOf(btnId) != -1) {
				btn.setAttribute('collapsed', 'true');
			}
		} else {
			btn.setAttribute('collapsed', 'true');
		}
	},

	hideProgress: function() {
		var progressBar = document.getElementById('tumblr-post-progress');
		var btn = document.getElementById('tumblr-post-btn');
	
		progressBar.setAttribute('mode', 'determined');
		progressBar.setAttribute('value', '0');
		progressBar.setAttribute('collapsed', 'true');
		btn.setAttribute('collapsed', 'false');
	},
	
	getGenerator: function() {
		return 'Tumblr Post v1.24';
	},
	
	postToTumblr: function(params) {

		var email = TumblrPost.getTumblrEmail();
		var password = TumblrPost.getTumblrPassword();
	
		if (email != '' && password != '') {
			
			params['email'] = email;
			params['password'] = password;
			params['generator'] = TumblrPost.getGenerator();
						
			if (typeof params['group'] == 'undefined' && 
					TumblrPost.postTumblelog != 'primary' && 
					TumblrPost.postTumblelog != '') {
				params['group'] = TumblrPost.postTumblelog;
			}
			
			if (typeof params['group'] != 'undefined' &&
					params['group'] == 'primary') {
				delete params['group'];
			}			

			var body = '';
			
			if ('file' in params) {
				body = TumblrPost.getMultipartBody(params);
			} else {
				body = TumblrPost.getRegularBody(params);
			}

			TumblrPost.makeRequest(params, body);
		} else {
			alert('Post failed. Login credentials are not set.');
			return false;			
		}
	},
	
	getRegularBody: function(params) {
		var body = '';
		for (var key in params) {
			if (params.hasOwnProperty(key)) {					
				body += key + '=' + encodeURIComponent(params[key]) + '&';					
			}
		}
		body = body.substring(0, body.length-1);
		return body;		
	},
	
	getMultipartBody: function(params) {

		var fileName = params.file.leafName;
		var filePath = params.file.path;
		var contentType = this.getContentType(params.file);

		var CC = Components.Constructor;

		var LocalFile = CC('@mozilla.org/file/local;1', 'nsILocalFile', 'initWithPath');
		var InputStream = CC('@mozilla.org/network/file-input-stream;1', 'nsIFileInputStream', 'init');
		var BufferedInputStream = CC('@mozilla.org/network/buffered-input-stream;1', 'nsIBufferedInputStream', 'init');

		var UploadStream = CC('@mozilla.org/io/multiplex-input-stream;1', 'nsIMultiplexInputStream', 'appendStream');
		var StringStream = CC('@mozilla.org/io/string-input-stream;1', 'nsIStringInputStream', 'setData');

		var localFile = new LocalFile(filePath);
		var inStream = new InputStream(localFile, 1, 0, false);
		var buffStream = new BufferedInputStream(inStream, 9000000);
									
		var boundary = 'END_OF_PART';
		var beginning = '';
		
		var partDiv = "--" + boundary + "\r\n";
		partDiv += "Content-Disposition: form-data; name=\"";
		
		for(var key in params) {
			if (params.hasOwnProperty(key) && key != 'file') {
				var  val = params[key];
				if (key == 'caption' || key == 'tags') {
					val = this.convertToUTF8(val);
				}
				beginning += partDiv + key + "\"";
				beginning += "\r\n\r\n" + val + "\r\n";
			}
		}
		beginning += partDiv;
		beginning += "data\"; filename=\"" + fileName + "\"\r\n";
		beginning += "Content-Type: " + contentType + "\r\n\r\n";
		
		var end = "\r\n--" + boundary + "--\r\n";

		var firstString = new StringStream(beginning, beginning.length);
		var secondString = new StringStream(end, end.length);

		var multiStream = Components.classes['@mozilla.org/io/multiplex-input-stream;1']
		.createInstance(Components.interfaces.nsIMultiplexInputStream);

		multiStream.appendStream(firstString);
		multiStream.appendStream(buffStream);
		multiStream.appendStream(secondString);
		
		return multiStream;	
	},

	postPhoto: function(src, file) {
		
		var params = {};
		
		params['type'] = 'photo';
		if (src) {
			params['source'] = src;
		} else {
			params['file'] = file;
		}

		if (this.photoPublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.photoPublishState;
		}
		
		if (this.photoClickThrough) {
			var pageData = TumblrPost.getCurrentPageData();		
			params['click-through-url'] = pageData[0];			
		}		
		
		if (this.photoCaptions) {
			this.openInputDialog(params);
		} else {
			this.postToTumblr(params);
		}
		
	},
	
	postPhotoFromMenu: function() {		
		if (gContextMenu) {
			var url = gContextMenu.imageURL;
			if (this.isTumblrPhotoUrl(url)) {
				this.postBinaryPhoto(url);
			} else {
				this.postPhoto(url);
			}
		}
	},
	
	postBinaryPhoto: function(url) {
		var ios = Components.classes['@mozilla.org/network/io-service;1']
		          .getService(Components.interfaces.nsIIOService);
		var uri = ios.newURI(url, null, null);
		
		try {
		  var url = uri.QueryInterface(Components.interfaces.nsIURL);
		} catch(e) {return;}
		
		var file = Components.classes['@mozilla.org/file/directory_service;1'].
		                     getService(Components.interfaces.nsIProperties).
		                     get('TmpD', Components.interfaces.nsIFile);
		
		file.append(url.fileName);		
		file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
		
		var wbp = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].
		    createInstance(Components.interfaces.nsIWebBrowserPersist);
		
		const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
		
		wbp.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | 
				nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
				nsIWBP.PERSIST_FLAGS_FROM_CACHE |
				nsIWBP.PERSIST_FLAGS_CLEANUP_ON_FAILURE;
		
		wbp.progressListener = {
			
			onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
											MaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
														
			onStateChange: function(aWebProgress, aRequest, aStatus, aMessage) {	
				const wpl = Components.interfaces.nsIWebProgressListener;
				
				if (aStatus & wpl.STATE_START) {
					TumblrPost.showProgress();
				} else if (aStatus & wpl.STATE_STOP) {
					TumblrPost.hideProgress();
					TumblrPost.postPhoto(false, file);
				}
			}
			
		}
				
		wbp.saveURI(uri, null, null, null, '', file);				
	},

	postQuote: function(quote) {
		
		var params = {};
		
		params['type'] = 'quote';
		params['quote'] = quote;

		if (this.quotePublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.quotePublishState;
		}
		
		if (this.urlAsQouteSource) {
			var pageData = this.getCurrentPageData();
			params['source'] = '<a href="' + pageData[0] + '">' + pageData[1] + '</a>';	
		}
		
		if (this.quoteSources) {
			this.openInputDialog(params);
		} else {
			this.postToTumblr(params);
		}

	},

	postLink: function(linkData) {
		
		var params = {};
		
		params['type'] = 'link';																
		params['url'] = linkData[0];
		params['name'] = linkData[1];																
		
		if (this.linkPublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.linkPublishState;
		}
		
		if (this.linkDescriptions) {
			this.openInputDialog(params);
		} else {
			this.postToTumblr(params);
		}
		
	},
	
	postLinkFromMenu: function() {		
		if (gContextMenu) {
			
			var linkData = [gContextMenu.getLinkURL(), gContextMenu.linkText()];
			this.postLink(linkData);
			
		}		
	},
	
	prepReblogPost: function(url) {
		
		var params = {}
		
		params['email'] = this.getTumblrEmail();
		params['password'] = this.getTumblrPassword();

		if (params['email'] == '' || params['password'] == '') {
			alert('Post failed. Login credentials are not set.');
			return false;
		}
		
		if (this.postTumblelog != 'primary' && this.postTumblelog != '') {
			params['group'] = this.postTumblelog;
		}		
		
		var postId = this.getPermalinkPostId(url);			
		params['post-id'] = postId;
					
		var domainMatches = /\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b/i.exec(url);
		if (domainMatches != null) {

			var readXmlUrl = 'http://' + domainMatches[0] + '/api/read/';			
			var body = this.getRegularBody({'id': postId});
			
			var xhReq = new XMLHttpRequest();
	
			xhReq.onreadystatechange = function () {				
				if (xhReq.readyState == 4) {
					
					if (xhReq.status == 200) {
						var xml = xhReq.responseXML;									
						var post = xml.getElementsByTagName('post');
						if (post[0] != null) {
							params['reblog-key'] = post[0].getAttribute('reblog-key');
							TumblrPost.reblogPost(params);		
						}						
					} else {
						alert('Server error. Unable to reblog post');
					}
				}
				
			}
			
			xhReq.open("POST", readXmlUrl, true);
			xhReq.setRequestHeader("Cache-Control", "no-cache");
			xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
			xhReq.setRequestHeader("Content-length", body.length);
	
			xhReq.send(body);				
		}
	},
	
	reblogPost: function(params) {
		
		var body = this.getRegularBody(params);		
		var xhReq = new XMLHttpRequest();
		
		xhReq.onload = function(e) {
			
			if (xhReq.status == 201) {
				var title = 'Post reblogged successfully';
				var msg = 'The post has now been reblogged on your tumblelog';

				var listener = {
					observe: function(subject, topic, data) {
						if (topic == 'alertclickcallback'){
							TumblrPost.goToDashboard();
						}
					}
				}

				var notifier = Components.classes['@mozilla.org/alerts-service;1']
												.getService(Components.interfaces.nsIAlertsService);
				
				notifier.showAlertNotification('chrome://TumblrPost/skin/tumblr_32x32.png',
					title, msg, true, '', listener);
				
			} else if (xhReq.status == 403) {
				alert('Access denied. Your email address or password were incorrect.');
			} else {
				alert('Server error. Could not post to Tumblr.');
			}
		};

		xhReq.onreadystatechange = function() {
			if (xhReq.readyState == 1) {
				TumblrPost.showProgress();
			}
			if (xhReq.readyState == 4) {
				TumblrPost.hideProgress();
			}
		};

		xhReq.open('POST', 'http://www.tumblr.com/api/reblog ', true);
		xhReq.setRequestHeader('Cache-Control', 'no-cache');
		xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
		xhReq.setRequestHeader('Content-length', body.length);

		xhReq.send(body);		
		
	},
	
	reblogPostFromMenu: function() {
		if (gContextMenu) {
			this.prepReblogPost(gContextMenu.getLinkURL());			
		}
	},
	
	postAudioFromMenu: function() {
		if (gContextMenu) {			
			this.prepPostAudio(gContextMenu.getLinkURL());			
		}		
	},
	
	postCurrentPage: function() {		
		var data = this.getCurrentPageData();
		this.postLink(data);				
	},	

	postVideo: function(embed) {
		
		var params = {};
		
		params['type'] = 'video';
		params['embed'] = embed;
		
		if (this.videoPublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.videoPublishState;
		}
		
		if (this.videoCaptions) {
			this.openInputDialog(params);
		} else {
			this.postToTumblr(params);
		}
		
	},

	postText: function(txt) {
		
		var params = {};
		
		params['type'] = 'regular';
		params['body'] = txt;
		
		if (this.textPublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.textPublishState;
		}
		
		if (this.textTitles) {
			this.openInputDialog(params);
		} else {				
			this.postToTumblr(params);
		}
		
	},
	
	postTextFromMenu: function() {
		var text = this.getSelection(document.popupNode);
		if (text.length > 0) {
			this.handleText(text);			
		}
	},
	
	prepPostAudio: function(url, file) {
		
		var params = {};
		
		params['type'] = 'audio';
		
		if (url) {
			params['externally-hosted-url'] = url;
		} else {
			params['file'] = file;
		}
		
		if (this.audioPublishState == 'private') {
			params['private'] = '1';
		} else {
			params['state'] = this.audioPublishState;
		}
		
		if (this.audioCaptions) {
			this.openInputDialog(params);
		} else {
			this.postAudio(params);
		}	
				
	},
	
	postAudio: function(params) {
		
		var audio_params = {};
		
		audio_params['email'] = this.getTumblrEmail();
		audio_params['password'] = this.getTumblrPassword();
		audio_params['generator'] = this.getGenerator();
		audio_params['action'] = 'check-audio';
		
		var body = this.getRegularBody(audio_params);
		
		var xhReq = new XMLHttpRequest();

		xhReq.onload = function(e) {
			if (xhReq.status == 200) {
				TumblrPost.postToTumblr(params);
			} else if (xhReq.status == 400) {
				alert('Daily quota reached: Could not post audio file');
			} else {
				alert('Unknown error: Could not post audio file');
			}
		};
		
		xhReq.onreadystatechange = function() {
			if (xhReq.readyState == 1) {
				TumblrPost.showProgress();
			}
			if (xhReq.readyState == 4 && xhReq.status != 200) {
				TumblrPost.hideProgress();
			}
		};		

		xhReq.open('POST', 'http://www.tumblr.com/api/write', true);
		xhReq.setRequestHeader('Cache-Control', 'no-cache');
		xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
		xhReq.setRequestHeader('Content-length', body.length);

		xhReq.send(body);
	},
	
	makeRequest: function(params, data) {
		
		var binary = ('file' in params);
			
		var type = params.type;
		var type_lbl = params.type;
				
		if (type == 'audio') {
			type_lbl += ' file';
		} else if (type == 'regular') {
			type_lbl = 'text';
		}

		var xhReq = new XMLHttpRequest();
		xhReq.onload = function(e) {
			if (xhReq.status == 201) {
				var title = TumblrPost.capitalize(type_lbl) + ' posted successfully';
				var msg = 'The ' + type_lbl + ' has now been posted to your tumblelog.';

				var listener = {
					observe: function(subject, topic, data) {
						if (topic == 'alertclickcallback')
						TumblrPost.goToDashboard();
					}
				}

				var notifier = Components.classes['@mozilla.org/alerts-service;1']
				.getService(Components.interfaces.nsIAlertsService);
				notifier.showAlertNotification('chrome://TumblrPost/skin/tumblr_32x32.png',
				title, msg, true, '', listener);
				
			} else if (xhReq.status == 403) {
				alert('Access denied. Your email address or password were incorrect.');
			} else {
				alert('Server error. Could not post the ' + type_lbl + ' to Tumblr.');
			}
		};

		xhReq.onreadystatechange = function() {
			if (xhReq.readyState == 1) {
				if (type == 'photo' || type == 'audio') {
					TumblrPost.showProgress();
				}
			}
			if (xhReq.readyState == 4) {
				if (type == 'photo' || type == 'audio') {
					TumblrPost.hideProgress();
				}
			}
		};

		xhReq.open('POST', 'http://www.tumblr.com/api/write', true);
		if (binary == false) {
			xhReq.setRequestHeader('Cache-Control', 'no-cache');
			xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
			xhReq.setRequestHeader('Content-length', data.length);
		} else {
			xhReq.setRequestHeader('Content-type', 'multipart/form-data; boundary=END_OF_PART');
			xhReq.setRequestHeader('Content-Length', (data.available()));
		}

		xhReq.send(data);
	},

	getSelection: function(node) {
		var selection = document.commandDispatcher.focusedWindow.getSelection().toString();
		
		if (node != null && typeof(node) != 'undefined') {
			if ((node.tagName == 'TEXTAREA') || (node.tagName == 'INPUT' && node.type == 'text')) {
				selection = node.value.substring(node.selectionStart, node.selectionEnd);
			}
		}
		return selection;
	},	

	isVideo: function(text) {
		var videoRegex = [/^http:\/\/www\.youtube\.com\/watch.{1,}/i,
		/^http:\/\/youtu\.be\/.{1,}/i,
		/^<object\b[^>]*>(.*?)<\/object>$/i,
		/^<embed\b[^>]*>(.*?)<\/embed>$/i];

		for (var i = 0; i < videoRegex.length; i++) {
			if (text.match(videoRegex[i])) {
				return true;
			}
		}
		return false;
	},
	
	isValidPhoto: function(file, uri) {
		var validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp'];
		var contentType = this.getContentType(file, uri);

		return this.inArray(contentType, validTypes);		
	},
	
	isTumblrPhotoUrl: function(url) {
		return url.match(/^http:\/\/(?:www\.)?tumblr\.com\/photo\//i);
	},

	isValidAudio: function(file) {
		var validType = ['audio/mpeg', 'audio/aiff'];
		var contentType = this.getContentType(file);
				
		return this.inArray(contentType, validType);		
	},
	
	isCurrentPageUrl: function(url) {
		var data = this.getCurrentPageData();
		if (data[0] && data[0] != 'about:blank') {				
			return (url == data[0]);
		}
		return false;
	},
	
	convertToUTF8: function(string) {
		var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
		.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);

		converter.charset = "UTF-8";
		var tmp = converter.ConvertFromUnicode(string);
		return tmp;
	},	

	getContentType: function(file, uri) {
		var contentType;
		try {
			
				var nsIMIME = Components.classes['@mozilla.org/mime;1']
												.getService(Components.interfaces.nsIMIMEService);							
				if (file) {
					contentType = nsIMIME.getTypeFromFile(file);
				} else if(uri) {
					contentType = nsIMIME.getTypeFromURI(uri);
				}			
		} catch(e) {
			
			var validPhotoExts = ['jpg', 'bmp', 'png', 'gif'];
			var validAudioExts = ['mp3', 'aiff'];
			
			var path = '';
			if (file) {
				path = file.path;
			} else if (uri) {
				path = uri.path;
			}
			var fileExt = path.match(/\.?(\w{3,4})$/i);			
			if (fileExt != null) {				
				if (this.inArray(fileExt[1], validPhotoExts)) {
					contentType = 'image/jpeg';
				} else if (this.inArray(fileExt[1], validAudioExts)) {
					contentType = 'audio/mpeg';
				}							
			}
			
		}
		return contentType;
	},
	
	getUrlHost: function(url) {
		var ios = Components.classes["@mozilla.org/network/io-service;1"]
		.getService(Components.interfaces.nsIIOService);
		
		var uri = ios.newURI(url, null, null);
		return uri.host;
	},
	
	getCurrentPageData: function() {
		var aDocShell = document.getElementById('content').webNavigation;		
		var url = aDocShell.currentURI.spec;
		var title = null;
		try {
			title = aDocShell.document.title || url;
		} catch (e) {
			title = url;
		}		
		var data = [url, title];
		return data;
	},
			
	getPermalinkPostId: function(url) {
		var matches = /\/post\/(\d+)/i.exec(url);
		if (matches != null) {
			return matches[1];
		}
		return false;
	},	

	capitalize: function(value) {
		if (value != '') {
			var firstLetter = value.substring(0, 1).toUpperCase();
			var restOfWord = value.substring(1, value.length).toLowerCase();
			value = firstLetter + restOfWord;
		}
		return value;
	},
	
	inArray: function(needle, haystack) {
		for (var i = 0; i < haystack.length; i++) {
			if (haystack[i] == needle) {
				return true;
			}
		}
		return false;
	},
	
	setTumblrUrl: function() {
		
		var params = {};
		
		params['email'] = this.getTumblrEmail();
		params['password'] = this.getTumblrPassword();
		
		var body = this.getRegularBody(params);
		
		var xhReq = new XMLHttpRequest();

		xhReq.onload = function(e) {
			if (xhReq.status == 200) {
				var tumblrUrl = '';
				var tumblelogs = xhReq.responseXML.getElementsByTagName('tumblelog');		
				for (var i = 0; i < tumblelogs.length; i++) {					
					if (tumblelogs[i].hasAttribute('is-primary')) {
						tumblrUrl = tumblelogs[i].getAttribute('url');
						break;
					}			
				}
								
				var prefService = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefService);

				var prefs = prefService.getBranch('extensions.tumblrpost.');
				prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
				prefs.setCharPref('tumblrUrl', tumblrUrl);
			}
		};

		xhReq.open('POST', 'http://www.tumblr.com/api/authenticate', true);
		xhReq.setRequestHeader('Cache-Control', 'no-cache');
		xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
		xhReq.setRequestHeader('Content-length', body.length);

		xhReq.send(body);
	},

	openTextEntry: function() {
		window.openDialog('chrome://TumblrPost/content/textEntryDialog.xul',
		'textEntryDialog', 'chrome, centerscreen', 
			TumblrPost.textPublishState, TumblrPost.postToTumblr);
	},
	
	openInputDialog: function(params) {
		window.openDialog('chrome://TumblrPost/content/inputDialog.xul',
		'inputDialog', 'chrome, centerscreen', params, TumblrPost.postToTumblr);
	},
	
	openFileDialog: function(type) {
		
		var nsIFilePicker = Components.interfaces.nsIFilePicker;
		var fp = Components.classes['@mozilla.org/filepicker;1']
		        .createInstance(nsIFilePicker);
		if (type == 'photo') {
			fp.init(window, 'Select a photo', nsIFilePicker.modeOpen);
			fp.appendFilters(fp.filterImages);
		} else if (type == 'audio') {
			fp.init(window, 'Select an audio file', nsIFilePicker.modeOpen);
			fp.appendFilter('Audio Files','*.mp3; *.aiff');
		}
		var rv = fp.show();
		if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {  		  		
			if (type == 'photo' && this.isValidPhoto(fp.file, false)) {				
				this.postPhoto(false, fp.file);								
			} else if (type == 'audio' && this.isValidAudio(fp.file)) {				
				this.prepPostAudio(false, fp.file);					
			}
		}
		
	},	

	onInputLoad: function() {
		
		var params = window.arguments[0];
		var callback = window.arguments[1];
		var capitalize = window.opener.TumblrPost.capitalize;
		
		var clickThroughUrl = '';
		if ('click-through-url' in params) {
			clickThroughUrl = params['click-through-url'];
		}
		
		var publishState = '';
		if ('state' in params) {
			publishState = params['state'];
		} else if ('private' in params) {
			publishState = 'private';
		}
	
		var groupBoxCaption = document.getElementById('inputGroupCaption');
		var inputTypeLabel = document.getElementById('inputTypeLabel');
		var inputTagsLabel = document.getElementById('inputTagsLabel');		
		
		var clickThroughBox = document.getElementById('clickThroughBox');
		var clickThroughLink = document.getElementById('clickThroughLink');
		var inputClickThroughBox = document.getElementById('inputClickThroughBox');
		
		var publishOnBox = document.getElementById('publishOnBox');
		var publishOnDate = document.getElementById('publishOnDate');
		var publishOnTime = document.getElementById('publishOnTime');

		var dlgInput = document.getElementById('tumblrInputDialog');		
		var inputText = document.getElementById('inputText');
		var inputTags = document.getElementById('inputTags');
		var menuPublishState = document.getElementById('menuPublishState');
		var menuTumblelogs = document.getElementById('menuTumblelogs');
		var inputClickThrough = document.getElementById('inputClickThrough');
		
		var menuitems = menuPublishState.getElementsByAttribute('value', publishState);
		if (typeof menuitems[0] != 'undefined') {
			menuPublishState.selectedItem = menuitems[0];
		}

		window.opener.TumblrPost.populateTumblelogs(menuTumblelogs.menupopup);
		
		menuPublishState.addEventListener('command', function() {

			var selVal = this.selectedItem.value;

			//sizeToContent acts really weird
			var isHidden = publishOnBox.getAttribute('hidden');
			if (selVal == 'publish-on') {
				publishOnBox.setAttribute('hidden', false);
				window.sizeToContent();
			} else {
				if (isHidden == "false") {
					publishOnBox.setAttribute('hidden', true);
					window.sizeToContent();
				}
			}
			
		}, false);
		
		if (clickThroughUrl != '') {			
			clickThroughLink.value = 'Clicking this photo links to the URL:';
			clickThroughLink.setAttribute('class', 'small-margin');
			clickThroughLink.setAttribute('style', 'margin: 5px 0 0 1px;');
			inputClickThroughBox.setAttribute('hidden', false);
			inputClickThrough.value = clickThroughUrl;						
		} else {		
			clickThroughLink.addEventListener('click', function() {
				this.value = 'Clicking this photo links to the URL:';
				this.setAttribute('class', 'small-margin');
				this.setAttribute('style', 'margin: 5px 0 0 1px;');
				inputClickThroughBox.setAttribute('hidden', false);
				window.sizeToContent();
			}, false);	
		}	
		
		var winTitle = 'Tumblr Post - ';		
		var boxLabel = capitalize(params.type);

		if (params.type == 'regular') {
			boxLabel = 'Text';
		} else if (params.type == 'audio') {
			boxLabel += ' file';
		}
		
		boxLabel += ' settings';
		winTitle += boxLabel;
		
		var inputType = '';
		
		switch(params.type) {
			case 'photo':
				clickThroughBox.setAttribute('hidden', false);
			case 'video':
			case 'audio':
				inputType = 'caption';
				break;
			case 'quote':
				inputType = 'source';
				break;
			case 'link':
				inputType = 'description';
				inputTypeLabel.width = 64;
				inputTagsLabel.width = 64;
				break;
			case 'regular':
				inputType = 'title';
				break;
		}
		
		document.title = winTitle;
		groupBoxCaption.label = boxLabel;
		inputTypeLabel.value = capitalize(inputType)+':';
		
		var accept = function() {

			params[inputType] = inputText.value;
			params['tags'] = inputTags.value;
			params['private'] = '0';
			
			if (menuTumblelogs.value != '') {
				params['group'] = menuTumblelogs.value;
			}
			
			if (params.type == 'photo') {
				params['click-through-url'] = inputClickThrough.value;
			}
						
			if (menuPublishState.value == 'publish-on') {
				
				params['state'] = 'queue';
				
				var dateVal = publishOnDate.dateValue;
				var timeVal = publishOnTime.dateValue;
				
				var date = dateVal.toLocaleFormat('%Y-%m-%d');
				var time = timeVal.toLocaleFormat('%H:%M:%S');
				
				params['publish-on'] = date + 'T' + time;
								
			} else if (menuPublishState.value == 'private') {
				params['private'] = '1';
			} else {
				params['state'] = menuPublishState.value;			
			}
			
			callback(params); 			
		};
		
		dlgInput.addEventListener('dialogaccept', accept, false);
						
		window.sizeToContent();	
		
	},

	onTextEntryLoad: function() {
		
		var params = {};
		var publishState = window.arguments[0];
		var callback = window.arguments[1];		
		
		var textEntryDialog = document.getElementById('tumblrTextEntryDialog');
		var textEntryBody = document.getElementById('textEntryBody');
		var textEntryTitle = document.getElementById('textEntryTitle');
		var textEntryTags = document.getElementById('textEntryTags');
		var menuPublishState = document.getElementById('menuPublishState');
		var menuTumblelogs = document.getElementById('menuTumblelogs');
		var publishOnBox = document.getElementById('publishOnBox');
		var publishOnDate = document.getElementById('publishOnDate');
		var publishOnTime = document.getElementById('publishOnTime');
				
		var menuitems = menuPublishState.getElementsByAttribute('value', publishState);
		if (typeof menuitems[0] != 'undefined') {
			menuPublishState.selectedItem = menuitems[0];
		}
		
		window.opener.TumblrPost.populateTumblelogs(menuTumblelogs.menupopup);
		
		menuPublishState.addEventListener('command', function() {

			var selVal = this.selectedItem.value;
			var isHidden = publishOnBox.getAttribute('hidden');
			if (selVal == 'publish-on') {
				publishOnBox.setAttribute('hidden', false);
				window.sizeToContent();
			} else {
				if (isHidden == "false") {
					publishOnBox.setAttribute('hidden', true);
					window.sizeToContent();
				}
			}
			
		}, false);		
						
		var accept = function() {
			
			params['type'] = 'regular';
			
			params['body'] = textEntryBody.value;
			params['title'] = textEntryTitle.value;
			params['tags'] = textEntryTags.value;
			
			if (menuTumblelogs.value != '') {
				params['group'] = menuTumblelogs.value;
			}			
			
			if (menuPublishState.value == 'publish-on') {
				
				params['state'] = 'queue';
				
				var dateVal = publishOnDate.dateValue;
				var timeVal = publishOnTime.dateValue;
				
				var date = dateVal.toLocaleFormat('%Y-%m-%d');
				var time = timeVal.toLocaleFormat('%H:%M:%S');
				
				params['publish-on'] = date + 'T' + time;
								
			} else if (menuPublishState.value == 'private') {
				params['private'] = '1';
			} else {
				params['state'] = menuPublishState.value;			
			}			
						
			callback(params);
			 			
		};
		
		textEntryDialog.addEventListener('dialogaccept', accept, false);		
		
	},

	handleText: function(txt) {
		if (this.isVideo(txt)) {						
			this.postVideo(txt);						
		} else if (this.isCurrentPageUrl(txt)) {						
			var data = this.getCurrentPageData();			
			this.postLink(data);								
		} else {
			if (this.textInsteadOfQuotes) {					
				this.postText(txt);								
			} else {				
				this.postQuote(txt);								
			}
		}
	},
	
	statusObserver: {
		
		getSupportedFlavours: function () {
			var flavours = new FlavourSet();
			flavours.appendFlavour('application/x-moz-file','nsIFile');
			flavours.appendFlavour('text/x-moz-url');
			flavours.appendFlavour('text/unicode')
			return flavours;
		},
	
		onDragStart: function (evt , transferData, action) {
			return;
		},
	
		onDragOver: function (evt,flavour,session) {
			var contentType = flavour.contentType;
			if (session.sourceNode != null) {
				if (session.isDataFlavorSupported(contentType)) {
					session.canDrop = true;
				}
			} else {
				if (contentType == 'application/x-moz-file' || 
									contentType == 'text/unicode') {
					session.canDrop = true;
				} else {
					session.canDrop = false;
				}
			}
		},
	
		onDragExit: function (evt, session) {
			return;
		},
	
		onDrop: function (evt, dropdata, session) {
	
			if (dropdata.data != '') {
		
				var contentType = dropdata.flavour.contentType;
				
				if (contentType == 'text/x-moz-url') {
						
					var node = session.sourceNode;
					var doc = session.sourceDocument;

					if (node.tagName == 'IMG') {
						
						var ios = Components.classes['@mozilla.org/network/io-service;1']
												.getService(Components.interfaces.nsIIOService);
						var uri = ios.newURI(node.src, null, null);						
						
						if (TumblrPost.isValidPhoto(false, uri)) {
							TumblrPost.postPhoto(node.src);
						} else {
							alert('Invalid content type found. Tumblr supports: JPEG, GIF, PNG, BMP and MP3');
							return;
						}
						
					} else {
						
						var txt = dropdata.data;
						
						if (txt.indexOf('\n') != -1) {
							
							var data = txt.split('\n');
							var url = data[0];
							
							if (/\.mp3$/gi.test(url)) {
								TumblrPost.prepPostAudio(url, false);
							} else if (TumblrPost.getPermalinkPostId(url)) {
								TumblrPost.prepReblogPost(url);
							} else {
								TumblrPost.postLink(data);
							}
							
						} else {
							//FF2 gets text/x-moz-url even if it's not a link
							TumblrPost.handleText(txt);		
						}
						
					}
					
				} else if (contentType == 'text/unicode') {
					
					var txt = dropdata.data;
					TumblrPost.handleText(txt);
				
				} else if (contentType == 'application/x-moz-file') {
	
					var file = dropdata.data;
	
					if (TumblrPost.isValidPhoto(file, false)) {												
						TumblrPost.postPhoto(false, file);						
					} else if (TumblrPost.isValidAudio(file)) {						
						TumblrPost.prepPostAudio(false, file);																			
					} else {
						alert('Invalid content type found. Tumblr supports: JPEG, GIF, PNG, BMP and MP3');
						return false;
					}
	
				}
			}
		}	
	
	},
	
	prefObserver: {
		
		register: function() {
			var prefService = Components.classes['@mozilla.org/preferences-service;1']
			.getService(Components.interfaces.nsIPrefService);
			this.prefs = prefService.getBranch('extensions.tumblrpost.');
			this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
			this.prefs.addObserver('', this, false);
		},
	
		unregister: function() {
			if(!this._branch) return;
			this._branch.removeObserver('', this);
		},
	
		observe: function(aSubject, aTopic, aData) {
			if (aTopic != 'nsPref:changed') return;
			
			var prefType = this.prefs.getPrefType(aData);

			switch(prefType) {
								
				case (this.prefs.PREF_STRING):
					TumblrPost[aData] = this.prefs.getCharPref(aData);
					break;
				case (this.prefs.PREF_INT):
					TumblrPost[aData] = this.prefs.getIntPref(aData);
					break;
				case(this.prefs.PREF_BOOL):
					TumblrPost[aData] = this.prefs.getBoolPref(aData);
					break;
						
			}
						
		}
		
	}

};

window.addEventListener('load', function() { TumblrPost.init(); }, false);

Könnte mir bitte jemand helfen ?

P.s. Ich weiß das eigentlich die Falsche Community aber vielleicht ist hier ja jemand der sich damit etwas auskennt.

Mfg
BuranATA
 
Last edited:
am Besten das Topic ändern, dass is JAVA Script kein JAVA das sind zwei unterschiedliche Sachen :)
 
geändert und hab auch eine Lösung gefunden falls es mal jemand sucht :
PHP:
params['click-through-url'] = pageData[0];

durch

PHP:
params['click-through-url'] = 'http://xxxxxxxxxxx';

ersetzen.
 
Last edited:
Back
Top Bottom