+ Antworten
Ergebnis 1 bis 3 von 3

[Java] Tumblr Post addon bearbeiten

Eine Diskussion über [Java] Tumblr Post addon bearbeiten im Forum Technik Ecke. Teil des Off Topic-Bereichs; moin moin, ich möchte das Firefox plugin Tumblr Post etwas bearbeiten und zwar nur an einer ganz bestimmten stelle. Leider ...

  1. #1
    Schütze
    Avatar von BuranATA
    Registriert seit
    06.04.2007
    Alter
    25
    Beiträge
    91

    [Java] Tumblr Post addon bearbeiten

    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:
    1. <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.

    Spoiler:
    1. var TumblrPost = {
    2.  
    3. init: function() {
    4.  
    5. this.prefObserver.register();
    6.  
    7. this.initprefs();
    8. this.initToolbarIcon();
    9. this.initContextMenu();
    10.  
    11. if (this.tumblrUrl == '') {
    12. this.setTumblrUrl();
    13. }
    14.  
    15. },
    16.  
    17. prefsWin: null,
    18.  
    19. initprefs: function() {
    20. try {
    21.  
    22. var prefService = Components.classes['@mozilla.org/preferences-service;1']
    23. .getService(Components.interfaces.nsIPrefService);
    24.  
    25. var prefs = prefService.getBranch('extensions.tumblrpost.');
    26. prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    27.  
    28. if (prefs.prefHasUserValue('email')) {
    29. prefs.setCharPref('email', '');
    30. }
    31.  
    32. if (prefs.prefHasUserValue('password')) {
    33. prefs.setCharPref('password', '');
    34. }
    35.  
    36. this.tumblrUrl = prefs.getCharPref('tumblrUrl');
    37. this.gotoDashboard = prefs.getBoolPref('gotoDashboard');
    38. this.gotoTumblelog = prefs.getBoolPref('gotoTumblelog');
    39. this.dashboardNewTab = prefs.getBoolPref('dashboardNewTab');
    40. this.urlAsQouteSource = prefs.getBoolPref('urlAsQouteSource');
    41. this.photoCaptions = prefs.getBoolPref('photoCaptions');
    42. this.quoteSources = prefs.getBoolPref('quoteSources');
    43. this.linkDescriptions = prefs.getBoolPref('linkDescriptions');
    44. this.videoCaptions = prefs.getBoolPref('videoCaptions');
    45. this.audioCaptions = prefs.getBoolPref('audioCaptions');
    46. this.textTitles = prefs.getBoolPref('textTitles');
    47. this.textPublishState = prefs.getCharPref('textPublishState');
    48. this.photoPublishState = prefs.getCharPref('photoPublishState');
    49. this.quotePublishState = prefs.getCharPref('quotePublishState');
    50. this.linkPublishState = prefs.getCharPref('linkPublishState');
    51. this.audioPublishState = prefs.getCharPref('audioPublishState');
    52. this.videoPublishState = prefs.getCharPref('videoPublishState');
    53. this.textInsteadOfQuotes = prefs.getBoolPref('textInsteadOfQuotes');
    54. this.postTumblelog = prefs.getCharPref('postTumblelog');
    55. this.photoClickThrough = prefs.getBoolPref('photoClickThrough');
    56. this.hidePhotoContext = prefs.getBoolPref('hidePhotoContext');
    57. this.hideTextContext = prefs.getBoolPref('hideTextContext');
    58. this.hideLinkContext = prefs.getBoolPref('hideLinkContext');
    59. this.hideVideoContext = prefs.getBoolPref('hideVideoContext');
    60. this.hideQuoteContext = prefs.getBoolPref('hideQuoteContext');
    61. this.hideAudioContext = prefs.getBoolPref('hideAudioContext');
    62. this.hideReblogContext = prefs.getBoolPref('hideReblogContext');
    63.  
    64. } catch (e) { //set defaults
    65.  
    66. prefs.setCharPref('tumblrUrl', '');
    67. prefs.setBoolPref('gotoDashboard', false);
    68. prefs.setBoolPref('gotoTumblelog', false);
    69. prefs.setBoolPref('dashboardNewTab', false);
    70. prefs.setBoolPref('urlAsQouteSource', false);
    71. prefs.setBoolPref('photoCaptions', false);
    72. prefs.setBoolPref('quoteSources', false);
    73. prefs.setBoolPref('linkDescriptions', false);
    74. prefs.setBoolPref('videoCaptions', false);
    75. prefs.setBoolPref('audioCaptions', false);
    76. prefs.setBoolPref('textTitles', false);
    77. prefs.setCharPref('textPublishState', 'published');
    78. prefs.setCharPref('photoPublishState', 'published');
    79. prefs.setCharPref('quotePublishState', 'published');
    80. prefs.setCharPref('linkPublishState', 'published');
    81. prefs.setCharPref('videoPublishState', 'published');
    82. prefs.setCharPref('audioPublishState', 'published');
    83. prefs.setBoolPref('textInsteadOfQuotes', false);
    84. prefs.setCharPref('postTumblelog', '');
    85. prefs.setBoolPref('photoClickThrough', false);
    86. prefs.setBoolPref('hidePhotoContext', false);
    87. prefs.setBoolPref('hideTextContext', false);
    88. prefs.setBoolPref('hideLinkContext', false);
    89. prefs.setBoolPref('hideVideoContext', false);
    90. prefs.setBoolPref('hideQuoteContext', false);
    91. prefs.setBoolPref('hideAudioContext', false);
    92. prefs.setBoolPref('hideReblogContext', false);
    93.  
    94. this.initprefs();
    95. }
    96. },
    97.  
    98. initContextMenu: function() {
    99.  
    100. var contextMenu = document.getElementById('contentAreaContextMenu');
    101. if (contextMenu) {
    102.  
    103. this.createMenuItem(contextMenu, 'Post photo to my tumblelog', function() { TumblrPost.postPhotoFromMenu(); }, false, 'tumblr-post-photo');
    104. this.createMenuItem(contextMenu, 'Post quote to my tumblelog', function() { TumblrPost.postTextFromMenu(); }, false, 'tumblr-post-text');
    105. this.createMenuItem(contextMenu, 'Post link to my tumblelog', function() { TumblrPost.postLinkFromMenu(); }, false, 'tumblr-post-link');
    106. this.createMenuItem(contextMenu, 'Post audio file to my tumblelog', function() { TumblrPost.postAudioFromMenu(); }, false, 'tumblr-post-audio');
    107. this.createMenuItem(contextMenu, 'Reblog this post', function() { TumblrPost.reblogPostFromMenu(); }, false, 'tumblr-reblog-post');
    108.  
    109. contextMenu.addEventListener('popupshowing', function() { TumblrPost.onShowContextMenu(); } , false);
    110.  
    111. }
    112. },
    113.  
    114. initToolbarIcon: function() {
    115. if (!Application.extensions) {
    116. Application.getExtensions(function (extensions) {
    117. var addonBar = document.getElementById('addon-bar');
    118. if (!addonBar) return;
    119.  
    120. let ext = extensions.get('{99210d54-6321-41e8-bd1b-2b4c55874efb}');
    121. if (ext && ext.firstRun) {
    122. var currSet = addonBar.currentSet.split(',');
    123. var btnId = 'tumblr-post-btn';
    124. if (currSet.indexOf(btnId) == -1) {
    125. var pos = currSet.length;
    126. var newSet = currSet.slice(0, pos).concat(btnId).concat(currSet.slice(pos));
    127. addonBar.setAttribute('currentset', newSet.join(','));
    128. addonBar.currentSet = newSet.join(',');
    129. document.persist(addonBar.id, 'currentset');
    130. try {
    131. BrowserToolboxCustomizeDone(true);
    132. } catch (e) {}
    133. }
    134. }
    135. });
    136. }
    137. },
    138.  
    139. onShowContextMenu: function() {
    140.  
    141. if (gContextMenu) {
    142.  
    143. gContextMenu.showItem('tumblr-post-photo', gContextMenu.onImage && !this.hidePhotoContext);
    144.  
    145. gContextMenu.showItem('tumblr-post-audio', gContextMenu.onSaveableLink &&
    146. /\.mp3$/gi.test(gContextMenu.getLinkURL()) && !this.hideAudioContext);
    147.  
    148. gContextMenu.showItem('tumblr-post-link', gContextMenu.onSaveableLink &&
    149. !/\.mp3$/gi.test(gContextMenu.getLinkURL()) && !this.hideLinkContext);
    150.  
    151. gContextMenu.showItem('tumblr-reblog-post', gContextMenu.onSaveableLink &&
    152. this.getPermalinkPostId(gContextMenu.getLinkURL()) && !this.hideReblogContext);
    153.  
    154. var textMenuItem = document.getElementById('tumblr-post-text');
    155. if (textMenuItem) {
    156. var show = true;
    157. var txt = this.getSelection(document.popupNode);
    158. if(this.isVideo(txt)) {
    159. textMenuItem.setAttribute('label', 'Post video to my tumblelog');
    160. if (this.hideVideoContext) show = false;
    161. } else if (this.isCurrentPageUrl(txt)) {
    162. textMenuItem.setAttribute('label', 'Post current page to my tumblelog');
    163. } else {
    164. if (this.textInsteadOfQuotes) {
    165. textMenuItem.setAttribute('label', 'Post text to my tumblelog');
    166. if (this.hideTextContext) show = false;
    167. } else {
    168. textMenuItem.setAttribute('label', 'Post quote to my tumblelog');
    169. if (this.hideQuoteContext) show = false;
    170. }
    171. }
    172. gContextMenu.showItem('tumblr-post-text', (txt.length > 0) && show);
    173. }
    174.  
    175. }
    176.  
    177. },
    178.  
    179. openPrefs: function(event) {
    180. if (null == this.prefsWin || this.prefsWin.closed) {
    181. let instaApply = Application.prefs.get('browser.preferences.instantApply');
    182. let feats = 'chrome,centerscreen' +
    183. (instaApply.value ? ',dialog=no' : ',modal');
    184.  
    185. this.prefsWin = window.openDialog(
    186. 'chrome://TumblrPost/content/prefsWindow.xul',
    187. 'prefs-win', feats);
    188. }
    189.  
    190. this.prefsWin.focus();
    191. },
    192.  
    193. getTumblrEmail: function() {
    194.  
    195. var hostName = 'chrome://TumblrPost';
    196.  
    197. if ('@mozilla.org/passwordmanager;1' in Components.classes) {
    198.  
    199. var passwordManager = Components.classes['@mozilla.org/passwordmanager;1']
    200. .getService(Components.interfaces.nsIPasswordManager);
    201.  
    202. var e = passwordManager.enumerator;
    203.  
    204. while (e.hasMoreElements()) {
    205. try {
    206. var pass = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
    207. if (pass.host == hostName) {
    208. return pass.user;
    209. }
    210. } catch (ex) {}
    211. }
    212.  
    213. } else if ('@mozilla.org/login-manager;1' in Components.classes) {
    214.  
    215. var passwordManager = Components.classes['@mozilla.org/login-manager;1']
    216. .getService(Components.interfaces.nsILoginManager);
    217.  
    218. var nsLoginInfo = new Components.Constructor('@mozilla.org/login-manager/loginInfo;1',
    219. Components.interfaces.nsILoginInfo,
    220. 'init');
    221.  
    222. var logins = passwordManager.findLogins({}, hostName, '', null);
    223.  
    224. if (logins.length > 0) {
    225. return logins[0].username;
    226. }
    227. }
    228. return '';
    229. },
    230.  
    231. getTumblrPassword: function() {
    232.  
    233. var hostName = 'chrome://TumblrPost';
    234.  
    235. if ('@mozilla.org/passwordmanager;1' in Components.classes) {
    236.  
    237. var passwordManager = Components.classes['@mozilla.org/passwordmanager;1']
    238. .getService(Components.interfaces.nsIPasswordManager);
    239.  
    240. var e = passwordManager.enumerator;
    241.  
    242. while (e.hasMoreElements()) {
    243. try {
    244. var pass = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
    245. if (pass.host == hostName) {
    246. return pass.password;
    247. }
    248. } catch (ex) {}
    249. }
    250.  
    251. } else if ('@mozilla.org/login-manager;1' in Components.classes) {
    252.  
    253. var passwordManager = Components.classes['@mozilla.org/login-manager;1']
    254. .getService(Components.interfaces.nsILoginManager);
    255.  
    256. var nsLoginInfo = new Components.Constructor('@mozilla.org/login-manager/loginInfo;1',
    257. Components.interfaces.nsILoginInfo,
    258. 'init');
    259.  
    260. var logins = passwordManager.findLogins({}, hostName, '', null);
    261.  
    262. if (logins.length > 0) {
    263. return logins[0].password;
    264. }
    265. }
    266. return '';
    267. },
    268.  
    269. goToDashboard: function() {
    270. var dashboardUrl = 'http://www.tumblr.com/dashboard/';
    271. if (this.dashboardNewTab) {
    272. gBrowser.selectedTab = gBrowser.addTab(dashboardUrl);
    273. } else {
    274. window.content.location = dashboardUrl;
    275. }
    276. },
    277.  
    278. goToTumbleLog: function() {
    279. window.content.location = this.tumblrUrl;
    280. },
    281.  
    282. populateMenu: function(item, event) {
    283.  
    284. if(((event.which) && (event.which == 3)) || ((event.button) && (event.button == 2))) {
    285.  
    286. var statusBarMenu = document.getElementById('tumblr-post-context-menu');
    287.  
    288. this.clearMenu(statusBarMenu);
    289.  
    290. if (statusBarMenu) {
    291. this.createMenuItem(statusBarMenu, 'Go to dashboard', function() { TumblrPost.goToDashboard(); }, false, 'gotoDashboard');
    292. if (this.tumblrUrl != '') {
    293. this.createMenuItem(statusBarMenu, 'Go to tumblelog', function() { TumblrPost.goToTumbleLog(); }, false, 'gotoTumbleLog');
    294. }
    295.  
    296. statusBarMenu.appendChild(document.createElement('menuseparator'));
    297. statusBarMenu.appendChild(this.createTumblelogsMenu());
    298. statusBarMenu.appendChild(document.createElement('menuseparator'));
    299.  
    300. this.createMenuItem(statusBarMenu, 'Settings...', function(event) { TumblrPost.openPrefs(event); }, false, 'menuSettings');
    301. this.createMenuItem(statusBarMenu, 'Write text entry...', function() { TumblrPost.openTextEntry(); }, false, 'textEntry');
    302. this.createMenuItem(statusBarMenu, 'Post photo...', function() { TumblrPost.openFileDialog("photo"); }, false, 'postPhoto');
    303. this.createMenuItem(statusBarMenu, 'Post audio file...', function() { TumblrPost.openFileDialog("audio"); }, false, 'postAudio');
    304. this.createMenuItem(statusBarMenu, 'Post current page', function() { TumblrPost.postCurrentPage(); }, false, 'postCurrentPage');
    305. }
    306. } else {
    307. if (this.gotoDashboard) {
    308. this.goToDashboard();
    309. } else if (this.gotoTumblelog) {
    310. this.goToTumbleLog();
    311. } else {
    312. return false;
    313. }
    314. }
    315. },
    316.  
    317. createMenuItem: function(menu, label, command, disabled, menuId) {
    318. var menuItem = document.createElement('menuitem');
    319. menuItem.setAttribute('label', label);
    320.  
    321. if (typeof command == 'function') {
    322. menuItem.addEventListener('command', command, false);
    323. }
    324.  
    325. menuItem.setAttribute('disabled', disabled);
    326. menuItem.setAttribute('id', menuId);
    327.  
    328. menu.appendChild(menuItem);
    329. },
    330.  
    331. clearMenu: function(menu) {
    332. while(menu.hasChildNodes()) {
    333. menu.removeChild(menu.firstChild);
    334. }
    335. },
    336.  
    337. createTumblelogsMenu: function() {
    338. var menu = document.createElement('menu');
    339. menu.setAttribute('label', 'Tumblelogs');
    340.  
    341. var menupopup = document.createElement('menupopup');
    342.  
    343. menupopup.addEventListener('popupshowing', function() { TumblrPost.populateTumblelogs(this); }, false);
    344. menupopup.addEventListener('popuphiding', function() { TumblrPost.clearMenu(this); }, false);
    345.  
    346. menu.appendChild(menupopup);
    347. return menu;
    348. },
    349.  
    350. populateTumblelogs: function(menu) {
    351.  
    352. var loading = document.createElement('menuitem');
    353. loading.setAttribute('label', 'Loading...');
    354. loading.setAttribute('disabled', 'true');
    355.  
    356. var error = document.createElement('menuitem');
    357. error.setAttribute('label', 'Could not fetch tumblelogs');
    358. error.setAttribute('disabled', 'true');
    359.  
    360. var email = this.getTumblrEmail();
    361. var password = this.getTumblrPassword();
    362.  
    363. if (email != '' && password != '') {
    364.  
    365. var params = {};
    366. params.email = email;
    367. params.password = password;
    368.  
    369. var body = this.getRegularBody(params);
    370.  
    371. var xhReq = new XMLHttpRequest();
    372.  
    373. xhReq.onreadystatechange = function () {
    374.  
    375. if (xhReq.readyState == 1) {
    376.  
    377. menu.appendChild(loading);
    378.  
    379. } else if (xhReq.readyState == 4) {
    380.  
    381. menu.removeChild(loading);
    382. var selectedIndex = 0;
    383.  
    384. if (xhReq.status == 200) {
    385.  
    386. var tumblelogs = xhReq.responseXML.getElementsByTagName('tumblelog');
    387.  
    388. for (var i = 0; i < tumblelogs.length; i++) {
    389.  
    390. var menuitem = document.createElement('menuitem');
    391. menuitem.setAttribute('type', 'radio');
    392. menuitem.setAttribute('name', 'tumblelog');
    393.  
    394. var label = tumblelogs[i].getAttribute('title');
    395. var type = tumblelogs[i].getAttribute('type');
    396. var value = '';
    397. if (type == 'public') {
    398. if (tumblelogs[i].hasAttribute('is-primary')) {
    399. value = 'primary';
    400. label += ' (Primary)';
    401. } else {
    402. value = TumblrPost.getUrlHost(tumblelogs[i].getAttribute('url'));
    403. }
    404. } else {
    405. value = tumblelogs[i].getAttribute('private-id');
    406. }
    407.  
    408. if (value == TumblrPost.postTumblelog) {
    409. selectedIndex = i;
    410. menuitem.setAttribute('checked', 'true');
    411. }
    412.  
    413. menuitem.setAttribute('value', value);
    414. menuitem.setAttribute('label', label);
    415.  
    416. if (menu.parentNode.id != 'menuTumblelogs') {
    417. menuitem.addEventListener('command', function() {
    418.  
    419. var prefService = Components.classes['@mozilla.org/preferences-service;1']
    420. .getService(Components.interfaces.nsIPrefService);
    421.  
    422. var prefs = prefService.getBranch('extensions.tumblrpost.');
    423. prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    424.  
    425. prefs.setCharPref('postTumblelog', this.getAttribute('value'));
    426.  
    427. }, false);
    428. }
    429.  
    430. menu.appendChild(menuitem);
    431.  
    432. }
    433.  
    434. } else {
    435. menu.appendChild(error);
    436. }
    437.  
    438. if (menu.parentNode.id == 'menuTumblelogs') {
    439. menu.parentNode.selectedIndex = selectedIndex;
    440. if (xhReq.status != 200) {
    441. menu.parentNode.disabled = true;
    442. }
    443. }
    444.  
    445. }
    446. };
    447.  
    448. xhReq.open("POST", "http://www.tumblr.com/api/authenticate", true);
    449. xhReq.setRequestHeader("Cache-Control", "no-cache");
    450. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    451. xhReq.setRequestHeader("Content-length", body.length);
    452.  
    453. xhReq.send(body);
    454.  
    455. } else {
    456. menu.appendChild(error);
    457. }
    458. },
    459.  
    460. showProgress: function() {
    461. var progressBar = document.getElementById('tumblr-post-progress');
    462. var addonBar = document.getElementById('addon-bar');
    463. var btnId = 'tumblr-post-btn';
    464. var btn = document.getElementById(btnId);
    465.  
    466. progressBar.removeAttribute('value');
    467. progressBar.setAttribute('mode', 'undetermined');
    468. progressBar.removeAttribute('collapsed');
    469.  
    470. if (addonBar) {
    471. var currSet = addonBar.currentSet.split(',');
    472. if (currSet.indexOf(btnId) != -1) {
    473. btn.setAttribute('collapsed', 'true');
    474. }
    475. } else {
    476. btn.setAttribute('collapsed', 'true');
    477. }
    478. },
    479.  
    480. hideProgress: function() {
    481. var progressBar = document.getElementById('tumblr-post-progress');
    482. var btn = document.getElementById('tumblr-post-btn');
    483.  
    484. progressBar.setAttribute('mode', 'determined');
    485. progressBar.setAttribute('value', '0');
    486. progressBar.setAttribute('collapsed', 'true');
    487. btn.setAttribute('collapsed', 'false');
    488. },
    489.  
    490. getGenerator: function() {
    491. return 'Tumblr Post v1.24';
    492. },
    493.  
    494. postToTumblr: function(params) {
    495.  
    496. var email = TumblrPost.getTumblrEmail();
    497. var password = TumblrPost.getTumblrPassword();
    498.  
    499. if (email != '' && password != '') {
    500.  
    501. params['email'] = email;
    502. params['password'] = password;
    503. params['generator'] = TumblrPost.getGenerator();
    504.  
    505. if (typeof params['group'] == 'undefined' &&
    506. TumblrPost.postTumblelog != 'primary' &&
    507. TumblrPost.postTumblelog != '') {
    508. params['group'] = TumblrPost.postTumblelog;
    509. }
    510.  
    511. if (typeof params['group'] != 'undefined' &&
    512. params['group'] == 'primary') {
    513. delete params['group'];
    514. }
    515.  
    516. var body = '';
    517.  
    518. if ('file' in params) {
    519. body = TumblrPost.getMultipartBody(params);
    520. } else {
    521. body = TumblrPost.getRegularBody(params);
    522. }
    523.  
    524. TumblrPost.makeRequest(params, body);
    525. } else {
    526. alert('Post failed. Login credentials are not set.');
    527. return false;
    528. }
    529. },
    530.  
    531. getRegularBody: function(params) {
    532. var body = '';
    533. for (var key in params) {
    534. if (params.hasOwnProperty(key)) {
    535. body += key + '=' + encodeURIComponent(params[key]) + '&';
    536. }
    537. }
    538. body = body.substring(0, body.length-1);
    539. return body;
    540. },
    541.  
    542. getMultipartBody: function(params) {
    543.  
    544. var fileName = params.file.leafName;
    545. var filePath = params.file.path;
    546. var contentType = this.getContentType(params.file);
    547.  
    548. var CC = Components.Constructor;
    549.  
    550. var LocalFile = CC('@mozilla.org/file/local;1', 'nsILocalFile', 'initWithPath');
    551. var InputStream = CC('@mozilla.org/network/file-input-stream;1', 'nsIFileInputStream', 'init');
    552. var BufferedInputStream = CC('@mozilla.org/network/buffered-input-stream;1', 'nsIBufferedInputStream', 'init');
    553.  
    554. var UploadStream = CC('@mozilla.org/io/multiplex-input-stream;1', 'nsIMultiplexInputStream', 'appendStream');
    555. var StringStream = CC('@mozilla.org/io/string-input-stream;1', 'nsIStringInputStream', 'setData');
    556.  
    557. var localFile = new LocalFile(filePath);
    558. var inStream = new InputStream(localFile, 1, 0, false);
    559. var buffStream = new BufferedInputStream(inStream, 9000000);
    560.  
    561. var boundary = 'END_OF_PART';
    562. var beginning = '';
    563.  
    564. var partDiv = "--" + boundary + "\r\n";
    565. partDiv += "Content-Disposition: form-data; name=\"";
    566.  
    567. for(var key in params) {
    568. if (params.hasOwnProperty(key) && key != 'file') {
    569. var val = params[key];
    570. if (key == 'caption' || key == 'tags') {
    571. val = this.convertToUTF8(val);
    572. }
    573. beginning += partDiv + key + "\"";
    574. beginning += "\r\n\r\n" + val + "\r\n";
    575. }
    576. }
    577. beginning += partDiv;
    578. beginning += "data\"; filename=\"" + fileName + "\"\r\n";
    579. beginning += "Content-Type: " + contentType + "\r\n\r\n";
    580.  
    581. var end = "\r\n--" + boundary + "--\r\n";
    582.  
    583. var firstString = new StringStream(beginning, beginning.length);
    584. var secondString = new StringStream(end, end.length);
    585.  
    586. var multiStream = Components.classes['@mozilla.org/io/multiplex-input-stream;1']
    587. .createInstance(Components.interfaces.nsIMultiplexInputStream);
    588.  
    589. multiStream.appendStream(firstString);
    590. multiStream.appendStream(buffStream);
    591. multiStream.appendStream(secondString);
    592.  
    593. return multiStream;
    594. },
    595.  
    596. postPhoto: function(src, file) {
    597.  
    598. var params = {};
    599.  
    600. params['type'] = 'photo';
    601. if (src) {
    602. params['source'] = src;
    603. } else {
    604. params['file'] = file;
    605. }
    606.  
    607. if (this.photoPublishState == 'private') {
    608. params['private'] = '1';
    609. } else {
    610. params['state'] = this.photoPublishState;
    611. }
    612.  
    613. if (this.photoClickThrough) {
    614. var pageData = TumblrPost.getCurrentPageData();
    615. params['click-through-url'] = pageData[0];
    616. }
    617.  
    618. if (this.photoCaptions) {
    619. this.openInputDialog(params);
    620. } else {
    621. this.postToTumblr(params);
    622. }
    623.  
    624. },
    625.  
    626. postPhotoFromMenu: function() {
    627. if (gContextMenu) {
    628. var url = gContextMenu.imageURL;
    629. if (this.isTumblrPhotoUrl(url)) {
    630. this.postBinaryPhoto(url);
    631. } else {
    632. this.postPhoto(url);
    633. }
    634. }
    635. },
    636.  
    637. postBinaryPhoto: function(url) {
    638. var ios = Components.classes['@mozilla.org/network/io-service;1']
    639. .getService(Components.interfaces.nsIIOService);
    640. var uri = ios.newURI(url, null, null);
    641.  
    642. try {
    643. var url = uri.QueryInterface(Components.interfaces.nsIURL);
    644. } catch(e) {return;}
    645.  
    646. var file = Components.classes['@mozilla.org/file/directory_service;1'].
    647. getService(Components.interfaces.nsIProperties).
    648. get('TmpD', Components.interfaces.nsIFile);
    649.  
    650. file.append(url.fileName);
    651. file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
    652.  
    653. var wbp = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].
    654. createInstance(Components.interfaces.nsIWebBrowserPersist);
    655.  
    656. const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
    657.  
    658. wbp.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
    659. nsIWBP.PERSIST_FLAGS_NO_CONVERSION |
    660. nsIWBP.PERSIST_FLAGS_FROM_CACHE |
    661. nsIWBP.PERSIST_FLAGS_CLEANUP_ON_FAILURE;
    662.  
    663. wbp.progressListener = {
    664.  
    665. onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
    666. MaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
    667.  
    668. onStateChange: function(aWebProgress, aRequest, aStatus, aMessage) {
    669. const wpl = Components.interfaces.nsIWebProgressListener;
    670.  
    671. if (aStatus & wpl.STATE_START) {
    672. TumblrPost.showProgress();
    673. } else if (aStatus & wpl.STATE_STOP) {
    674. TumblrPost.hideProgress();
    675. TumblrPost.postPhoto(false, file);
    676. }
    677. }
    678.  
    679. }
    680.  
    681. wbp.saveURI(uri, null, null, null, '', file);
    682. },
    683.  
    684. postQuote: function(quote) {
    685.  
    686. var params = {};
    687.  
    688. params['type'] = 'quote';
    689. params['quote'] = quote;
    690.  
    691. if (this.quotePublishState == 'private') {
    692. params['private'] = '1';
    693. } else {
    694. params['state'] = this.quotePublishState;
    695. }
    696.  
    697. if (this.urlAsQouteSource) {
    698. var pageData = this.getCurrentPageData();
    699. params['source'] = '<a href="' + pageData[0] + '">' + pageData[1] + '</a>';
    700. }
    701.  
    702. if (this.quoteSources) {
    703. this.openInputDialog(params);
    704. } else {
    705. this.postToTumblr(params);
    706. }
    707.  
    708. },
    709.  
    710. postLink: function(linkData) {
    711.  
    712. var params = {};
    713.  
    714. params['type'] = 'link';
    715. params['url'] = linkData[0];
    716. params['name'] = linkData[1];
    717.  
    718. if (this.linkPublishState == 'private') {
    719. params['private'] = '1';
    720. } else {
    721. params['state'] = this.linkPublishState;
    722. }
    723.  
    724. if (this.linkDescriptions) {
    725. this.openInputDialog(params);
    726. } else {
    727. this.postToTumblr(params);
    728. }
    729.  
    730. },
    731.  
    732. postLinkFromMenu: function() {
    733. if (gContextMenu) {
    734.  
    735. var linkData = [gContextMenu.getLinkURL(), gContextMenu.linkText()];
    736. this.postLink(linkData);
    737.  
    738. }
    739. },
    740.  
    741. prepReblogPost: function(url) {
    742.  
    743. var params = {}
    744.  
    745. params['email'] = this.getTumblrEmail();
    746. params['password'] = this.getTumblrPassword();
    747.  
    748. if (params['email'] == '' || params['password'] == '') {
    749. alert('Post failed. Login credentials are not set.');
    750. return false;
    751. }
    752.  
    753. if (this.postTumblelog != 'primary' && this.postTumblelog != '') {
    754. params['group'] = this.postTumblelog;
    755. }
    756.  
    757. var postId = this.getPermalinkPostId(url);
    758. params['post-id'] = postId;
    759.  
    760. var domainMatches = /\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b/i.exec(url);
    761. if (domainMatches != null) {
    762.  
    763. var readXmlUrl = 'http://' + domainMatches[0] + '/api/read/';
    764. var body = this.getRegularBody({'id': postId});
    765.  
    766. var xhReq = new XMLHttpRequest();
    767.  
    768. xhReq.onreadystatechange = function () {
    769. if (xhReq.readyState == 4) {
    770.  
    771. if (xhReq.status == 200) {
    772. var xml = xhReq.responseXML;
    773. var post = xml.getElementsByTagName('post');
    774. if (post[0] != null) {
    775. params['reblog-key'] = post[0].getAttribute('reblog-key');
    776. TumblrPost.reblogPost(params);
    777. }
    778. } else {
    779. alert('Server error. Unable to reblog post');
    780. }
    781. }
    782.  
    783. }
    784.  
    785. xhReq.open("POST", readXmlUrl, true);
    786. xhReq.setRequestHeader("Cache-Control", "no-cache");
    787. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    788. xhReq.setRequestHeader("Content-length", body.length);
    789.  
    790. xhReq.send(body);
    791. }
    792. },
    793.  
    794. reblogPost: function(params) {
    795.  
    796. var body = this.getRegularBody(params);
    797. var xhReq = new XMLHttpRequest();
    798.  
    799. xhReq.onload = function(e) {
    800.  
    801. if (xhReq.status == 201) {
    802. var title = 'Post reblogged successfully';
    803. var msg = 'The post has now been reblogged on your tumblelog';
    804.  
    805. var listener = {
    806. observe: function(subject, topic, data) {
    807. if (topic == 'alertclickcallback'){
    808. TumblrPost.goToDashboard();
    809. }
    810. }
    811. }
    812.  
    813. var notifier = Components.classes['@mozilla.org/alerts-service;1']
    814. .getService(Components.interfaces.nsIAlertsService);
    815.  
    816. notifier.showAlertNotification('chrome://TumblrPost/skin/tumblr_32x32.png',
    817. title, msg, true, '', listener);
    818.  
    819. } else if (xhReq.status == 403) {
    820. alert('Access denied. Your email address or password were incorrect.');
    821. } else {
    822. alert('Server error. Could not post to Tumblr.');
    823. }
    824. };
    825.  
    826. xhReq.onreadystatechange = function() {
    827. if (xhReq.readyState == 1) {
    828. TumblrPost.showProgress();
    829. }
    830. if (xhReq.readyState == 4) {
    831. TumblrPost.hideProgress();
    832. }
    833. };
    834.  
    835. xhReq.open('POST', 'http://www.tumblr.com/api/reblog ', true);
    836. xhReq.setRequestHeader('Cache-Control', 'no-cache');
    837. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    838. xhReq.setRequestHeader('Content-length', body.length);
    839.  
    840. xhReq.send(body);
    841.  
    842. },
    843.  
    844. reblogPostFromMenu: function() {
    845. if (gContextMenu) {
    846. this.prepReblogPost(gContextMenu.getLinkURL());
    847. }
    848. },
    849.  
    850. postAudioFromMenu: function() {
    851. if (gContextMenu) {
    852. this.prepPostAudio(gContextMenu.getLinkURL());
    853. }
    854. },
    855.  
    856. postCurrentPage: function() {
    857. var data = this.getCurrentPageData();
    858. this.postLink(data);
    859. },
    860.  
    861. postVideo: function(embed) {
    862.  
    863. var params = {};
    864.  
    865. params['type'] = 'video';
    866. params['embed'] = embed;
    867.  
    868. if (this.videoPublishState == 'private') {
    869. params['private'] = '1';
    870. } else {
    871. params['state'] = this.videoPublishState;
    872. }
    873.  
    874. if (this.videoCaptions) {
    875. this.openInputDialog(params);
    876. } else {
    877. this.postToTumblr(params);
    878. }
    879.  
    880. },
    881.  
    882. postText: function(txt) {
    883.  
    884. var params = {};
    885.  
    886. params['type'] = 'regular';
    887. params['body'] = txt;
    888.  
    889. if (this.textPublishState == 'private') {
    890. params['private'] = '1';
    891. } else {
    892. params['state'] = this.textPublishState;
    893. }
    894.  
    895. if (this.textTitles) {
    896. this.openInputDialog(params);
    897. } else {
    898. this.postToTumblr(params);
    899. }
    900.  
    901. },
    902.  
    903. postTextFromMenu: function() {
    904. var text = this.getSelection(document.popupNode);
    905. if (text.length > 0) {
    906. this.handleText(text);
    907. }
    908. },
    909.  
    910. prepPostAudio: function(url, file) {
    911.  
    912. var params = {};
    913.  
    914. params['type'] = 'audio';
    915.  
    916. if (url) {
    917. params['externally-hosted-url'] = url;
    918. } else {
    919. params['file'] = file;
    920. }
    921.  
    922. if (this.audioPublishState == 'private') {
    923. params['private'] = '1';
    924. } else {
    925. params['state'] = this.audioPublishState;
    926. }
    927.  
    928. if (this.audioCaptions) {
    929. this.openInputDialog(params);
    930. } else {
    931. this.postAudio(params);
    932. }
    933.  
    934. },
    935.  
    936. postAudio: function(params) {
    937.  
    938. var audio_params = {};
    939.  
    940. audio_params['email'] = this.getTumblrEmail();
    941. audio_params['password'] = this.getTumblrPassword();
    942. audio_params['generator'] = this.getGenerator();
    943. audio_params['action'] = 'check-audio';
    944.  
    945. var body = this.getRegularBody(audio_params);
    946.  
    947. var xhReq = new XMLHttpRequest();
    948.  
    949. xhReq.onload = function(e) {
    950. if (xhReq.status == 200) {
    951. TumblrPost.postToTumblr(params);
    952. } else if (xhReq.status == 400) {
    953. alert('Daily quota reached: Could not post audio file');
    954. } else {
    955. alert('Unknown error: Could not post audio file');
    956. }
    957. };
    958.  
    959. xhReq.onreadystatechange = function() {
    960. if (xhReq.readyState == 1) {
    961. TumblrPost.showProgress();
    962. }
    963. if (xhReq.readyState == 4 && xhReq.status != 200) {
    964. TumblrPost.hideProgress();
    965. }
    966. };
    967.  
    968. xhReq.open('POST', 'http://www.tumblr.com/api/write', true);
    969. xhReq.setRequestHeader('Cache-Control', 'no-cache');
    970. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    971. xhReq.setRequestHeader('Content-length', body.length);
    972.  
    973. xhReq.send(body);
    974. },
    975.  
    976. makeRequest: function(params, data) {
    977.  
    978. var binary = ('file' in params);
    979.  
    980. var type = params.type;
    981. var type_lbl = params.type;
    982.  
    983. if (type == 'audio') {
    984. type_lbl += ' file';
    985. } else if (type == 'regular') {
    986. type_lbl = 'text';
    987. }
    988.  
    989. var xhReq = new XMLHttpRequest();
    990. xhReq.onload = function(e) {
    991. if (xhReq.status == 201) {
    992. var title = TumblrPost.capitalize(type_lbl) + ' posted successfully';
    993. var msg = 'The ' + type_lbl + ' has now been posted to your tumblelog.';
    994.  
    995. var listener = {
    996. observe: function(subject, topic, data) {
    997. if (topic == 'alertclickcallback')
    998. TumblrPost.goToDashboard();
    999. }
    1000. }
    1001.  
    1002. var notifier = Components.classes['@mozilla.org/alerts-service;1']
    1003. .getService(Components.interfaces.nsIAlertsService);
    1004. notifier.showAlertNotification('chrome://TumblrPost/skin/tumblr_32x32.png',
    1005. title, msg, true, '', listener);
    1006.  
    1007. } else if (xhReq.status == 403) {
    1008. alert('Access denied. Your email address or password were incorrect.');
    1009. } else {
    1010. alert('Server error. Could not post the ' + type_lbl + ' to Tumblr.');
    1011. }
    1012. };
    1013.  
    1014. xhReq.onreadystatechange = function() {
    1015. if (xhReq.readyState == 1) {
    1016. if (type == 'photo' || type == 'audio') {
    1017. TumblrPost.showProgress();
    1018. }
    1019. }
    1020. if (xhReq.readyState == 4) {
    1021. if (type == 'photo' || type == 'audio') {
    1022. TumblrPost.hideProgress();
    1023. }
    1024. }
    1025. };
    1026.  
    1027. xhReq.open('POST', 'http://www.tumblr.com/api/write', true);
    1028. if (binary == false) {
    1029. xhReq.setRequestHeader('Cache-Control', 'no-cache');
    1030. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    1031. xhReq.setRequestHeader('Content-length', data.length);
    1032. } else {
    1033. xhReq.setRequestHeader('Content-type', 'multipart/form-data; boundary=END_OF_PART');
    1034. xhReq.setRequestHeader('Content-Length', (data.available()));
    1035. }
    1036.  
    1037. xhReq.send(data);
    1038. },
    1039.  
    1040. getSelection: function(node) {
    1041. var selection = document.commandDispatcher.focusedWindow.getSelection().toString();
    1042.  
    1043. if (node != null && typeof(node) != 'undefined') {
    1044. if ((node.tagName == 'TEXTAREA') || (node.tagName == 'INPUT' && node.type == 'text')) {
    1045. selection = node.value.substring(node.selectionStart, node.selectionEnd);
    1046. }
    1047. }
    1048. return selection;
    1049. },
    1050.  
    1051. isVideo: function(text) {
    1052. var videoRegex = [/^http:\/\/www\.youtube\.com\/watch.{1,}/i,
    1053. /^http:\/\/youtu\.be\/.{1,}/i,
    1054. /^<object\b[^>]*>(.*?)<\/object>$/i,
    1055. /^<embed\b[^>]*>(.*?)<\/embed>$/i];
    1056.  
    1057. for (var i = 0; i < videoRegex.length; i++) {
    1058. if (text.match(videoRegex[i])) {
    1059. return true;
    1060. }
    1061. }
    1062. return false;
    1063. },
    1064.  
    1065. isValidPhoto: function(file, uri) {
    1066. var validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp'];
    1067. var contentType = this.getContentType(file, uri);
    1068.  
    1069. return this.inArray(contentType, validTypes);
    1070. },
    1071.  
    1072. isTumblrPhotoUrl: function(url) {
    1073. return url.match(/^http:\/\/(?:www\.)?tumblr\.com\/photo\//i);
    1074. },
    1075.  
    1076. isValidAudio: function(file) {
    1077. var validType = ['audio/mpeg', 'audio/aiff'];
    1078. var contentType = this.getContentType(file);
    1079.  
    1080. return this.inArray(contentType, validType);
    1081. },
    1082.  
    1083. isCurrentPageUrl: function(url) {
    1084. var data = this.getCurrentPageData();
    1085. if (data[0] && data[0] != 'about:blank') {
    1086. return (url == data[0]);
    1087. }
    1088. return false;
    1089. },
    1090.  
    1091. convertToUTF8: function(string) {
    1092. var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
    1093. .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
    1094.  
    1095. converter.charset = "UTF-8";
    1096. var tmp = converter.ConvertFromUnicode(string);
    1097. return tmp;
    1098. },
    1099.  
    1100. getContentType: function(file, uri) {
    1101. var contentType;
    1102. try {
    1103.  
    1104. var nsIMIME = Components.classes['@mozilla.org/mime;1']
    1105. .getService(Components.interfaces.nsIMIMEService);
    1106. if (file) {
    1107. contentType = nsIMIME.getTypeFromFile(file);
    1108. } else if(uri) {
    1109. contentType = nsIMIME.getTypeFromURI(uri);
    1110. }
    1111. } catch(e) {
    1112.  
    1113. var validPhotoExts = ['jpg', 'bmp', 'png', 'gif'];
    1114. var validAudioExts = ['mp3', 'aiff'];
    1115.  
    1116. var path = '';
    1117. if (file) {
    1118. path = file.path;
    1119. } else if (uri) {
    1120. path = uri.path;
    1121. }
    1122. var fileExt = path.match(/\.?(\w{3,4})$/i);
    1123. if (fileExt != null) {
    1124. if (this.inArray(fileExt[1], validPhotoExts)) {
    1125. contentType = 'image/jpeg';
    1126. } else if (this.inArray(fileExt[1], validAudioExts)) {
    1127. contentType = 'audio/mpeg';
    1128. }
    1129. }
    1130.  
    1131. }
    1132. return contentType;
    1133. },
    1134.  
    1135. getUrlHost: function(url) {
    1136. var ios = Components.classes["@mozilla.org/network/io-service;1"]
    1137. .getService(Components.interfaces.nsIIOService);
    1138.  
    1139. var uri = ios.newURI(url, null, null);
    1140. return uri.host;
    1141. },
    1142.  
    1143. getCurrentPageData: function() {
    1144. var aDocShell = document.getElementById('content').webNavigation;
    1145. var url = aDocShell.currentURI.spec;
    1146. var title = null;
    1147. try {
    1148. title = aDocShell.document.title || url;
    1149. } catch (e) {
    1150. title = url;
    1151. }
    1152. var data = [url, title];
    1153. return data;
    1154. },
    1155.  
    1156. getPermalinkPostId: function(url) {
    1157. var matches = /\/post\/(\d+)/i.exec(url);
    1158. if (matches != null) {
    1159. return matches[1];
    1160. }
    1161. return false;
    1162. },
    1163.  
    1164. capitalize: function(value) {
    1165. if (value != '') {
    1166. var firstLetter = value.substring(0, 1).toUpperCase();
    1167. var restOfWord = value.substring(1, value.length).toLowerCase();
    1168. value = firstLetter + restOfWord;
    1169. }
    1170. return value;
    1171. },
    1172.  
    1173. inArray: function(needle, haystack) {
    1174. for (var i = 0; i < haystack.length; i++) {
    1175. if (haystack[i] == needle) {
    1176. return true;
    1177. }
    1178. }
    1179. return false;
    1180. },
    1181.  
    1182. setTumblrUrl: function() {
    1183.  
    1184. var params = {};
    1185.  
    1186. params['email'] = this.getTumblrEmail();
    1187. params['password'] = this.getTumblrPassword();
    1188.  
    1189. var body = this.getRegularBody(params);
    1190.  
    1191. var xhReq = new XMLHttpRequest();
    1192.  
    1193. xhReq.onload = function(e) {
    1194. if (xhReq.status == 200) {
    1195. var tumblrUrl = '';
    1196. var tumblelogs = xhReq.responseXML.getElementsByTagName('tumblelog');
    1197. for (var i = 0; i < tumblelogs.length; i++) {
    1198. if (tumblelogs[i].hasAttribute('is-primary')) {
    1199. tumblrUrl = tumblelogs[i].getAttribute('url');
    1200. break;
    1201. }
    1202. }
    1203.  
    1204. var prefService = Components.classes['@mozilla.org/preferences-service;1']
    1205. .getService(Components.interfaces.nsIPrefService);
    1206.  
    1207. var prefs = prefService.getBranch('extensions.tumblrpost.');
    1208. prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    1209. prefs.setCharPref('tumblrUrl', tumblrUrl);
    1210. }
    1211. };
    1212.  
    1213. xhReq.open('POST', 'http://www.tumblr.com/api/authenticate', true);
    1214. xhReq.setRequestHeader('Cache-Control', 'no-cache');
    1215. xhReq.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=utf-8');
    1216. xhReq.setRequestHeader('Content-length', body.length);
    1217.  
    1218. xhReq.send(body);
    1219. },
    1220.  
    1221. openTextEntry: function() {
    1222. window.openDialog('chrome://TumblrPost/content/textEntryDialog.xul',
    1223. 'textEntryDialog', 'chrome, centerscreen',
    1224. TumblrPost.textPublishState, TumblrPost.postToTumblr);
    1225. },
    1226.  
    1227. openInputDialog: function(params) {
    1228. window.openDialog('chrome://TumblrPost/content/inputDialog.xul',
    1229. 'inputDialog', 'chrome, centerscreen', params, TumblrPost.postToTumblr);
    1230. },
    1231.  
    1232. openFileDialog: function(type) {
    1233.  
    1234. var nsIFilePicker = Components.interfaces.nsIFilePicker;
    1235. var fp = Components.classes['@mozilla.org/filepicker;1']
    1236. .createInstance(nsIFilePicker);
    1237. if (type == 'photo') {
    1238. fp.init(window, 'Select a photo', nsIFilePicker.modeOpen);
    1239. fp.appendFilters(fp.filterImages);
    1240. } else if (type == 'audio') {
    1241. fp.init(window, 'Select an audio file', nsIFilePicker.modeOpen);
    1242. fp.appendFilter('Audio Files','*.mp3; *.aiff');
    1243. }
    1244. var rv = fp.show();
    1245. if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
    1246. if (type == 'photo' && this.isValidPhoto(fp.file, false)) {
    1247. this.postPhoto(false, fp.file);
    1248. } else if (type == 'audio' && this.isValidAudio(fp.file)) {
    1249. this.prepPostAudio(false, fp.file);
    1250. }
    1251. }
    1252.  
    1253. },
    1254.  
    1255. onInputLoad: function() {
    1256.  
    1257. var params = window.arguments[0];
    1258. var callback = window.arguments[1];
    1259. var capitalize = window.opener.TumblrPost.capitalize;
    1260.  
    1261. var clickThroughUrl = '';
    1262. if ('click-through-url' in params) {
    1263. clickThroughUrl = params['click-through-url'];
    1264. }
    1265.  
    1266. var publishState = '';
    1267. if ('state' in params) {
    1268. publishState = params['state'];
    1269. } else if ('private' in params) {
    1270. publishState = 'private';
    1271. }
    1272.  
    1273. var groupBoxCaption = document.getElementById('inputGroupCaption');
    1274. var inputTypeLabel = document.getElementById('inputTypeLabel');
    1275. var inputTagsLabel = document.getElementById('inputTagsLabel');
    1276.  
    1277. var clickThroughBox = document.getElementById('clickThroughBox');
    1278. var clickThroughLink = document.getElementById('clickThroughLink');
    1279. var inputClickThroughBox = document.getElementById('inputClickThroughBox');
    1280.  
    1281. var publishOnBox = document.getElementById('publishOnBox');
    1282. var publishOnDate = document.getElementById('publishOnDate');
    1283. var publishOnTime = document.getElementById('publishOnTime');
    1284.  
    1285. var dlgInput = document.getElementById('tumblrInputDialog');
    1286. var inputText = document.getElementById('inputText');
    1287. var inputTags = document.getElementById('inputTags');
    1288. var menuPublishState = document.getElementById('menuPublishState');
    1289. var menuTumblelogs = document.getElementById('menuTumblelogs');
    1290. var inputClickThrough = document.getElementById('inputClickThrough');
    1291.  
    1292. var menuitems = menuPublishState.getElementsByAttribute('value', publishState);
    1293. if (typeof menuitems[0] != 'undefined') {
    1294. menuPublishState.selectedItem = menuitems[0];
    1295. }
    1296.  
    1297. window.opener.TumblrPost.populateTumblelogs(menuTumblelogs.menupopup);
    1298.  
    1299. menuPublishState.addEventListener('command', function() {
    1300.  
    1301. var selVal = this.selectedItem.value;
    1302.  
    1303. //sizeToContent acts really weird
    1304. var isHidden = publishOnBox.getAttribute('hidden');
    1305. if (selVal == 'publish-on') {
    1306. publishOnBox.setAttribute('hidden', false);
    1307. window.sizeToContent();
    1308. } else {
    1309. if (isHidden == "false") {
    1310. publishOnBox.setAttribute('hidden', true);
    1311. window.sizeToContent();
    1312. }
    1313. }
    1314.  
    1315. }, false);
    1316.  
    1317. if (clickThroughUrl != '') {
    1318. clickThroughLink.value = 'Clicking this photo links to the URL:';
    1319. clickThroughLink.setAttribute('class', 'small-margin');
    1320. clickThroughLink.setAttribute('style', 'margin: 5px 0 0 1px;');
    1321. inputClickThroughBox.setAttribute('hidden', false);
    1322. inputClickThrough.value = clickThroughUrl;
    1323. } else {
    1324. clickThroughLink.addEventListener('click', function() {
    1325. this.value = 'Clicking this photo links to the URL:';
    1326. this.setAttribute('class', 'small-margin');
    1327. this.setAttribute('style', 'margin: 5px 0 0 1px;');
    1328. inputClickThroughBox.setAttribute('hidden', false);
    1329. window.sizeToContent();
    1330. }, false);
    1331. }
    1332.  
    1333. var winTitle = 'Tumblr Post - ';
    1334. var boxLabel = capitalize(params.type);
    1335.  
    1336. if (params.type == 'regular') {
    1337. boxLabel = 'Text';
    1338. } else if (params.type == 'audio') {
    1339. boxLabel += ' file';
    1340. }
    1341.  
    1342. boxLabel += ' settings';
    1343. winTitle += boxLabel;
    1344.  
    1345. var inputType = '';
    1346.  
    1347. switch(params.type) {
    1348. case 'photo':
    1349. clickThroughBox.setAttribute('hidden', false);
    1350. case 'video':
    1351. case 'audio':
    1352. inputType = 'caption';
    1353. break;
    1354. case 'quote':
    1355. inputType = 'source';
    1356. break;
    1357. case 'link':
    1358. inputType = 'description';
    1359. inputTypeLabel.width = 64;
    1360. inputTagsLabel.width = 64;
    1361. break;
    1362. case 'regular':
    1363. inputType = 'title';
    1364. break;
    1365. }
    1366.  
    1367. document.title = winTitle;
    1368. groupBoxCaption.label = boxLabel;
    1369. inputTypeLabel.value = capitalize(inputType)+':';
    1370.  
    1371. var accept = function() {
    1372.  
    1373. params[inputType] = inputText.value;
    1374. params['tags'] = inputTags.value;
    1375. params['private'] = '0';
    1376.  
    1377. if (menuTumblelogs.value != '') {
    1378. params['group'] = menuTumblelogs.value;
    1379. }
    1380.  
    1381. if (params.type == 'photo') {
    1382. params['click-through-url'] = inputClickThrough.value;
    1383. }
    1384.  
    1385. if (menuPublishState.value == 'publish-on') {
    1386.  
    1387. params['state'] = 'queue';
    1388.  
    1389. var dateVal = publishOnDate.dateValue;
    1390. var timeVal = publishOnTime.dateValue;
    1391.  
    1392. var date = dateVal.toLocaleFormat('%Y-%m-%d');
    1393. var time = timeVal.toLocaleFormat('%H:%M:%S');
    1394.  
    1395. params['publish-on'] = date + 'T' + time;
    1396.  
    1397. } else if (menuPublishState.value == 'private') {
    1398. params['private'] = '1';
    1399. } else {
    1400. params['state'] = menuPublishState.value;
    1401. }
    1402.  
    1403. callback(params);
    1404. };
    1405.  
    1406. dlgInput.addEventListener('dialogaccept', accept, false);
    1407.  
    1408. window.sizeToContent();
    1409.  
    1410. },
    1411.  
    1412. onTextEntryLoad: function() {
    1413.  
    1414. var params = {};
    1415. var publishState = window.arguments[0];
    1416. var callback = window.arguments[1];
    1417.  
    1418. var textEntryDialog = document.getElementById('tumblrTextEntryDialog');
    1419. var textEntryBody = document.getElementById('textEntryBody');
    1420. var textEntryTitle = document.getElementById('textEntryTitle');
    1421. var textEntryTags = document.getElementById('textEntryTags');
    1422. var menuPublishState = document.getElementById('menuPublishState');
    1423. var menuTumblelogs = document.getElementById('menuTumblelogs');
    1424. var publishOnBox = document.getElementById('publishOnBox');
    1425. var publishOnDate = document.getElementById('publishOnDate');
    1426. var publishOnTime = document.getElementById('publishOnTime');
    1427.  
    1428. var menuitems = menuPublishState.getElementsByAttribute('value', publishState);
    1429. if (typeof menuitems[0] != 'undefined') {
    1430. menuPublishState.selectedItem = menuitems[0];
    1431. }
    1432.  
    1433. window.opener.TumblrPost.populateTumblelogs(menuTumblelogs.menupopup);
    1434.  
    1435. menuPublishState.addEventListener('command', function() {
    1436.  
    1437. var selVal = this.selectedItem.value;
    1438. var isHidden = publishOnBox.getAttribute('hidden');
    1439. if (selVal == 'publish-on') {
    1440. publishOnBox.setAttribute('hidden', false);
    1441. window.sizeToContent();
    1442. } else {
    1443. if (isHidden == "false") {
    1444. publishOnBox.setAttribute('hidden', true);
    1445. window.sizeToContent();
    1446. }
    1447. }
    1448.  
    1449. }, false);
    1450.  
    1451. var accept = function() {
    1452.  
    1453. params['type'] = 'regular';
    1454.  
    1455. params['body'] = textEntryBody.value;
    1456. params['title'] = textEntryTitle.value;
    1457. params['tags'] = textEntryTags.value;
    1458.  
    1459. if (menuTumblelogs.value != '') {
    1460. params['group'] = menuTumblelogs.value;
    1461. }
    1462.  
    1463. if (menuPublishState.value == 'publish-on') {
    1464.  
    1465. params['state'] = 'queue';
    1466.  
    1467. var dateVal = publishOnDate.dateValue;
    1468. var timeVal = publishOnTime.dateValue;
    1469.  
    1470. var date = dateVal.toLocaleFormat('%Y-%m-%d');
    1471. var time = timeVal.toLocaleFormat('%H:%M:%S');
    1472.  
    1473. params['publish-on'] = date + 'T' + time;
    1474.  
    1475. } else if (menuPublishState.value == 'private') {
    1476. params['private'] = '1';
    1477. } else {
    1478. params['state'] = menuPublishState.value;
    1479. }
    1480.  
    1481. callback(params);
    1482.  
    1483. };
    1484.  
    1485. textEntryDialog.addEventListener('dialogaccept', accept, false);
    1486.  
    1487. },
    1488.  
    1489. handleText: function(txt) {
    1490. if (this.isVideo(txt)) {
    1491. this.postVideo(txt);
    1492. } else if (this.isCurrentPageUrl(txt)) {
    1493. var data = this.getCurrentPageData();
    1494. this.postLink(data);
    1495. } else {
    1496. if (this.textInsteadOfQuotes) {
    1497. this.postText(txt);
    1498. } else {
    1499. this.postQuote(txt);
    1500. }
    1501. }
    1502. },
    1503.  
    1504. statusObserver: {
    1505.  
    1506. getSupportedFlavours: function () {
    1507. var flavours = new FlavourSet();
    1508. flavours.appendFlavour('application/x-moz-file','nsIFile');
    1509. flavours.appendFlavour('text/x-moz-url');
    1510. flavours.appendFlavour('text/unicode')
    1511. return flavours;
    1512. },
    1513.  
    1514. onDragStart: function (evt , transferData, action) {
    1515. return;
    1516. },
    1517.  
    1518. onDragOver: function (evt,flavour,session) {
    1519. var contentType = flavour.contentType;
    1520. if (session.sourceNode != null) {
    1521. if (session.isDataFlavorSupported(contentType)) {
    1522. session.canDrop = true;
    1523. }
    1524. } else {
    1525. if (contentType == 'application/x-moz-file' ||
    1526. contentType == 'text/unicode') {
    1527. session.canDrop = true;
    1528. } else {
    1529. session.canDrop = false;
    1530. }
    1531. }
    1532. },
    1533.  
    1534. onDragExit: function (evt, session) {
    1535. return;
    1536. },
    1537.  
    1538. onDrop: function (evt, dropdata, session) {
    1539.  
    1540. if (dropdata.data != '') {
    1541.  
    1542. var contentType = dropdata.flavour.contentType;
    1543.  
    1544. if (contentType == 'text/x-moz-url') {
    1545.  
    1546. var node = session.sourceNode;
    1547. var doc = session.sourceDocument;
    1548.  
    1549. if (node.tagName == 'IMG') {
    1550.  
    1551. var ios = Components.classes['@mozilla.org/network/io-service;1']
    1552. .getService(Components.interfaces.nsIIOService);
    1553. var uri = ios.newURI(node.src, null, null);
    1554.  
    1555. if (TumblrPost.isValidPhoto(false, uri)) {
    1556. TumblrPost.postPhoto(node.src);
    1557. } else {
    1558. alert('Invalid content type found. Tumblr supports: JPEG, GIF, PNG, BMP and MP3');
    1559. return;
    1560. }
    1561.  
    1562. } else {
    1563.  
    1564. var txt = dropdata.data;
    1565.  
    1566. if (txt.indexOf('\n') != -1) {
    1567.  
    1568. var data = txt.split('\n');
    1569. var url = data[0];
    1570.  
    1571. if (/\.mp3$/gi.test(url)) {
    1572. TumblrPost.prepPostAudio(url, false);
    1573. } else if (TumblrPost.getPermalinkPostId(url)) {
    1574. TumblrPost.prepReblogPost(url);
    1575. } else {
    1576. TumblrPost.postLink(data);
    1577. }
    1578.  
    1579. } else {
    1580. //FF2 gets text/x-moz-url even if it's not a link
    1581. TumblrPost.handleText(txt);
    1582. }
    1583.  
    1584. }
    1585.  
    1586. } else if (contentType == 'text/unicode') {
    1587.  
    1588. var txt = dropdata.data;
    1589. TumblrPost.handleText(txt);
    1590.  
    1591. } else if (contentType == 'application/x-moz-file') {
    1592.  
    1593. var file = dropdata.data;
    1594.  
    1595. if (TumblrPost.isValidPhoto(file, false)) {
    1596. TumblrPost.postPhoto(false, file);
    1597. } else if (TumblrPost.isValidAudio(file)) {
    1598. TumblrPost.prepPostAudio(false, file);
    1599. } else {
    1600. alert('Invalid content type found. Tumblr supports: JPEG, GIF, PNG, BMP and MP3');
    1601. return false;
    1602. }
    1603.  
    1604. }
    1605. }
    1606. }
    1607.  
    1608. },
    1609.  
    1610. prefObserver: {
    1611.  
    1612. register: function() {
    1613. var prefService = Components.classes['@mozilla.org/preferences-service;1']
    1614. .getService(Components.interfaces.nsIPrefService);
    1615. this.prefs = prefService.getBranch('extensions.tumblrpost.');
    1616. this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
    1617. this.prefs.addObserver('', this, false);
    1618. },
    1619.  
    1620. unregister: function() {
    1621. if(!this._branch) return;
    1622. this._branch.removeObserver('', this);
    1623. },
    1624.  
    1625. observe: function(aSubject, aTopic, aData) {
    1626. if (aTopic != 'nsPref:changed') return;
    1627.  
    1628. var prefType = this.prefs.getPrefType(aData);
    1629.  
    1630. switch(prefType) {
    1631.  
    1632. case (this.prefs.PREF_STRING):
    1633. TumblrPost[aData] = this.prefs.getCharPref(aData);
    1634. break;
    1635. case (this.prefs.PREF_INT):
    1636. TumblrPost[aData] = this.prefs.getIntPref(aData);
    1637. break;
    1638. case(this.prefs.PREF_BOOL):
    1639. TumblrPost[aData] = this.prefs.getBoolPref(aData);
    1640. break;
    1641.  
    1642. }
    1643.  
    1644. }
    1645.  
    1646. }
    1647.  
    1648. };
    1649.  
    1650. window.addEventListener('load', function() { TumblrPost.init(); }, false);
    1651.  
    1652.  


    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
    Geändert von BuranATA (08.04.2012 um 21:06 Uhr)

  2. #2
    am Besten das Topic ändern, dass is JAVA Script kein JAVA das sind zwei unterschiedliche Sachen

  3. #3
    Schütze
    Avatar von BuranATA
    Registriert seit
    06.04.2007
    Alter
    25
    Beiträge
    91
    geändert und hab auch eine Lösung gefunden falls es mal jemand sucht :
    1. params['click-through-url'] = pageData[0];

    durch

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

    ersetzen.
    Geändert von BuranATA (08.04.2012 um 22:39 Uhr)

+ Antworten

Ähnliche Themen

  1. Eigener Java-Server, Bilder per HTTP-Post übertragen
    Von .deviant im Forum Technik Ecke
    Antworten: 1
    Letzter Beitrag: 14.03.2009, 07:07
  2. TIBERIAN DAWN 2 Addon
    Von CNCloggerJack im Forum Mods & Maps
    Antworten: 269
    Letzter Beitrag: 27.04.2002, 04:11
  3. Countdown zum 5000. post läuft.
    Von patrick im Forum RAP-1
    Antworten: 81
    Letzter Beitrag: 21.11.2001, 00:57
  4. Post-Day
    Von FLoorfiLLa im Forum T*G*E
    Antworten: 17
    Letzter Beitrag: 13.11.2001, 10:16
  5. post in our own cheaters forum
    Von KluiFie im Forum FD-NL
    Antworten: 8
    Letzter Beitrag: 18.09.2001, 19:16

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •