kland upload scripts

#+BEGIN_SRC powershell function Upload-ToKland { param([String]$bucket = "", [String]$Image, [String]$Url = "https://kland.smilebasicsource.com/uploadimage") $ImageName = [regex]::Match($Image,"[^\\/]+\.(png|PNG|gif|GIF|jpe?g|JPE?G)").Value $Image = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetString([IO.File]::ReadAllBytes($Image)) $ImageType = [System.Web.MimeMapping]::GetMimeMapping($Image) $boundary = [guid]::NewGuid().ToString() $PostBody = @" --$boundary Content-Disposition: form-data; name="image"; filename="$ImageName" Content-Type: $ImageType $Image --$boundary Content-Disposition: form-data; name="bucket" $bucket --$boundary-- "@ return Invoke-RestMethod -Method Post -Uri $Url -ContentType "multipart/form-data; boundary=$boundary" -Body $PostBody } function Take-Screenshot { param([Drawing.Rectangle]$bounds = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds, [string]$path = "image.png" ) $BMP = New-Object Drawing.Bitmap $bounds.width, $bounds.height $Graphics = [Drawing.Graphics]::FromImage($BMP) $Graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size) $BMP.Save($path, [System.Drawing.Imaging.ImageFormat]::Png) $Graphics.Dispose() $BMP.Dispose() return $path } function KlandScreenshot([String]$Bucket) { while ([System.Windows.Forms.UserControl]::MouseButtons -eq "None"){} $pos1 = [System.Windows.Forms.Cursor]::Position while ([System.Windows.Forms.UserControl]::MouseButtons -ne "None"){} # wait for mouse release while ([System.Windows.Forms.UserControl]::MouseButtons -eq "None"){} $pos2 = [System.Windows.Forms.Cursor]::Position $region = [Drawing.Rectangle]::new($pos1, $pos2 - $pos1) $path = "$env:TEMP\klandimage.png" $path = Take-Screenshot -bound $region -path $path $file = Upload-ToKland -bucket $Bucket -image $path Remove-Item $path Set-Clipboard $file return $file } #+END_SRC
#+BEGIN_SRC javascript // Chemicalex chatjs paster (maybe chrome only) var dataUrl=""; document.onpaste = function(event){ var items = (event.clipboardData || event.originalEvent.clipboardData).items; console.log(JSON.stringify(items)); // will give you the mime types for (index in items) { var item = items[index]; if (item.kind == 'file') { var blob = item.getAsFile(); var reader = new FileReader(); reader.onload = function(event){ console.log(dataUrl); dataURL = reader.result; console.log(dataURL); xhttp3.open("POST", "https://kland.smilebasicsource.com/uploadimage"); var fd=new FormData(); fd.append("image", blob, blob.type == "image/jpeg" ? "blob.jpeg" : "blob.png"); fd.append("bucket","PasteLog"+username); fd.append("paste","true"); xhttp3.send(fd); }; reader.readAsDataURL(blob); } } }; #+END_SRC
ACTUALLY this needs to be added to the start of that var xhttp3 = new XMLHttpRequest(); xhttp3.onreadystatechange = function() { console.log("done!"); if (xhttp3.readyState == 4 && xhttp3.status == 200) { sendMessage("/img "+xhttp3.responseText); //document.write(''); } };