upload.load.need('js/download.js', function() { return upload.download }) upload.load.need('js/textpaste.js', function() { return upload.textpaste }) upload.load.need('js/loadencryption.js', function() { return window.crypt }) upload.load.need('js/updown.js', function() { return upload.updown }) upload.modules.addmodule({ name: 'home', // Dear santa, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings template: '\
\').prop('id', 'pastecatcher') this.pastecatcher.prop('contenteditable', true) $('body').append(this.pastecatcher) }, focuspaste: function () { setTimeout(function () { this.pastecatcher.focus() }, 100) }, triggerfocuspaste: function(e) { if (e.which != 1) { return } if (e.target == document.body && this._ && !this._.pastearea.hasClass('hidden')) { e.preventDefault() this.focuspaste() } }, progress: function(e) { if (e.eventsource != 'encrypt') { this._.progress.type.text('Uploading') } else { this._.progress.type.text('Encrypting') } var percent = (e.loaded / e.total) * 100 this._.progress.bg.css('width', percent + '%') this._.progress.amount.text(Math.floor(percent) + '%') }, doupload: function (blob) { this._.pastearea.addClass('hidden') this._.progress.main.removeClass('hidden') this._.progress.type.text('Encrypting') this._.progress.bg.css('width', 0) this._.newpaste.addClass('hidden') upload.updown.upload(blob, this.progress.bind(this), this.uploaded.bind(this)) }, closepaste: function() { this._.pastearea.removeClass('hidden') this._.view.find('#uploadview').show() this._.view.find('.viewswitcher').show() }, dopasteupload: function (data) { this._.pastearea.addClass('hidden') this._.view.find('#uploadview').hide() this._.view.find('.viewswitcher').hide() upload.textpaste.render(this._.view, 'Pasted text.txt', data, 'text/plain', this.closepaste.bind(this)) }, uploaded: function (data, response) { upload.download.delkeys[data.ident] = response.delkey try { localStorage.setItem('delete-' + data.ident, response.delkey) } catch (e) { console.log(e) } if (window.location.hash == '#noref') { history.replaceState(undefined, undefined, '#' + data.seed) upload.route.setroute(upload.download, undefined, data.seed) } else { window.location = '#' + data.seed } }, newpaste: function() { this.dopasteupload('') }, pasted: function (e) { if (!this._ || this._.pastearea.hasClass('hidden')) { return } var items = e.clipboardData.items var text = e.clipboardData.getData('text/plain') if (text) { e.preventDefault() this.dopasteupload(text) } else if (typeof items == 'undefined') { self = this setTimeout(function () { if (self.pastecatcher.find('img').length) { var src = self.pastecatcher.find('img').prop('src') if (src.startsWith('data:')) { self.doupload(dataURItoBlob(src)) } else { // TODO: Firefox } } }, 0) } else if (items.length >= 1) { e.preventDefault() for (var i = 0; i < items.length; i++) { var blob = items[i].getAsFile() if (blob) { this.doupload(blob) break } } } }, })