More work on post from url

This commit is contained in:
Kabir Sala 2014-02-11 23:37:52 +01:00
parent f0bd6b1b04
commit d8a168a549
9 changed files with 63 additions and 46 deletions

View File

@ -14,6 +14,7 @@
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// @run-at document-start
// @updateURL https://github.com/Spittie/4chan-x/raw/stable/builds/4chan-X.meta.js
// @downloadURL https://github.com/Spittie/4chan-x/raw/stable/builds/4chan-X.user.js

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -873,7 +873,7 @@ input.field.tripped:not(:hover):not(:focus) {
min-height: 59px;
min-width: 302px;
}
.captcha-input {
.captcha-input{
width: 100%;
margin: 1px 0 0;
}
@ -950,7 +950,7 @@ input#qr-filename:not(.edit) {
right: 0px;
}
#qr-filerm {
margin-right: 2px;
margin-right: 3px;
z-index: 2;
}
#file-n-submit {

View File

@ -22,13 +22,14 @@
<div id=dump-list></div>
<a id=add-post href=javascript:; title="Add a post" tabindex=50>+</a>
</div>
</div>
<div id=file-n-submit>
<span id=qr-filename-container class=field tabindex=60>
<span id=qr-no-file>No selected file</span>
<input id="qr-filename" data-name="filename" spellcheck="false">
<span id=qr-extras-container>
<a id=qr-filerm href=javascript:; title='Remove file'>×</a>
<a id=url-button title='Post from url'>!</a>
<a id=url-button title='Post from url'><i class="fa fa-link"></i></a>
<a id=dump-button title='Dump list'>+</a>
</span>
</span>

View File

@ -15,6 +15,7 @@
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// @run-at document-start
// @updateURL <%= meta.repo %>raw/stable/builds/<%= meta.files.metajs %>
// @downloadURL <%= meta.repo %>raw/stable/builds/<%= meta.files.userjs %>

View File

@ -104,6 +104,7 @@ QR =
QR.cleanNotifications()
d.activeElement.blur()
$.rmClass QR.nodes.el, 'dump'
$.rmClass QR.nodes.el, 'url'
unless Conf['Captcha Warning Notifications']
$.rmClass QR.captcha.nodes.input, 'error' if QR.captcha.isEnabled
if Conf['QR Shortcut']
@ -269,23 +270,46 @@ QR =
$.addClass QR.nodes.el, 'dump'
handleUrl: ->
url = prompt("insert url")
<% if (type === 'crx') { %>
url = prompt("Insert an url:")
return if url == null
xhr = new XMLHttpRequest();
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = (e) ->
if this.readyState == this.DONE && xhr.status == 200
urlBlob = new Blob([this.response], {type: 'image/jpeg'})
urlBlob = new Blob([this.response], {type : this.getResponseHeader('content-type')})
console.log(urlBlob.type)
return if urlBlob.type == null
unless urlBlob.type in QR.mimeTypes
QR.error "Unsupported file type."
QR.handleFiles([urlBlob])
null
return
else
QR.error "Can't load image."
return
xhr.onerror = (e) ->
console.log("error" + e)
null
QR.error "Can't load image."
return
xhr.send()
null
return
<% } %>
<% if (type === 'currently-not-working-userscript') { %>
GM_xmlhttpRequest {
method: "GET",
url: url,
responseType: 'blob',
onload: (xhr) ->
urlBlob = new Blob([xhr.response], {type: 'image/png'})
QR.handleFiles([urlBlob])
return
}
return
<% } %>
handleFiles: (files) ->

View File

@ -157,7 +157,7 @@ QR.post = class
return
setFile: (@file) ->
@filename = file.name
@filename = file.name || "File from url"
@filesize = $.bytesToString file.size
@nodes.label.hidden = false if QR.spoiler
URL.revokeObjectURL @URL