/**
*
* jquery.binarytransport.js
*
* @description. jQuery ajax transport for making binary data type requests.
* @version 1.0
* @author Henry Algus <henryalgus@gmail.com>
*
*/
(function($, undefined) {
"use strict";
// use this transport for "binary" data type
$.ajaxTransport("+binary", function(options, originalOptions, jqXHR) {
// check for conditions and support for blob / arraybuffer response type
if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) {
return {
// create new XMLHttpRequest
send: function(headers, callback) {
// setup all variables
var xhr = new XMLHttpRequest(),
url = options.url,
type = options.type,
async = options.async !== false,
// blob or arraybuffer. Default is blob
dataType = options.responseType || "blob",
data = options.data || null,
username = options.username || null,
password = options.password || null;
xhr.addEventListener('load', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.addEventListener('error', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async, username, password);
// setup custom headers
for (var i in headers) {
xhr.setRequestHeader(i, headers[i]);
}
xhr.responseType = dataType;
xhr.send(data);
},
abort: function() {}
};
}
});
})(window.jQuery);
// Загрузка файлов, Gregon
function getUnicodeCharacter2(cp) {
if (cp >= 0 && cp <= 0xD7FF || cp >= 0xE000 && cp <= 0xFFFF) {
return String.fromCharCode(cp);
} else if (cp >= 0x10000 && cp <= 0x10FFFF) {
// we substract 0x10000 from cp to get a 20-bits number
// in the range 0..0xFFFF
cp -= 0x10000;
// we add 0xD800 to the number formed by the first 10 bits
// to give the first byte
var first = ((0xffc00 & cp) >> 10) + 0xD800
// we add 0xDC00 to the number formed by the low 10 bits
// to give the second byte
var second = (0x3ff & cp) + 0xDC00;
return String.fromCharCode(first) + String.fromCharCode(second);
}
}
function GREGON_uploadFile2(fd, name, type){
console.log('uploading');
// create the request
const xhr = new XMLHttpRequest();
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
// we done!
}
};
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
console.log(xhr.response);
const json = JSON.parse(xhr.response);
const name2 = name.replace('&', '&.').replace(';', '&scl.').replace('[', '<.').replace(']', '>.');
let type2 = "application/octet-stream";
if (type != "") {
type2 = type;
}
smile('
');
}
};
// path to server would be where you'd normally post the form to
xhr.open('POST', encodeURI('https://matrix-client.matrix.org/_matrix/media/v3/upload?filename='+name), true);
xhr.setRequestHeader("content-type", "application/octet-stream");
xhr.setRequestHeader("Authorization", "Bearer токен"); /* Да у нас так же как у админа сделано */
xhr.send(fd);
}
function GREGON_downloadFile(code, name, type){
$.ajax({
url: 'https://matrix-client.matrix.org/_matrix/client/v1/media/download/'+code+'?allow_redirect=true',
type: 'GET',
dataType: 'binary',
headers: {"Authorization": "Bearer токен"}, /* Да у нас так же как у админа сделано */
xhr: function(){// Seems like the only way to get access to the xhr object
console.log('xhr');
var xhr = new XMLHttpRequest();
xhr.responseType='arraybuffer';
return xhr;
},
success: function(data) {
var blob = new Blob([data], {type: type});
console.log('url');
var windowUrl = window.URL || window.webkitURL;
var url = windowUrl.createObjectURL(blob);
console.log(url);
//$('a.download-link').attr('href', url);
//$('a.download-link').attr('download', 'test');
//$('a.download-link').get(0).click();
var anchor = $("<a></a>");
anchor.css("display", "none");
$("body").append(anchor);
anchor.prop('href', url);
anchor.prop('download', name);
anchor.get(0).click();
windowUrl.revokeObjectURL(url);
anchor.remove();
},
complete: function() {
console.log('complete');
},
error: function(a,b,c) {
console.log('error');
console.log(a);
console.log(b);
console.log(c);
}
});
}
function GREGON_RenderFiles(){
$('div.GREGON_file').each(function(i) {
console.log($(this));
console.log($(this).attr("alt"));
const array = $(this).attr("alt").replace("<.", "[").replace(">.", "]").split(';');
const name = array[1].replace("&scl.", ";").replace("&.", "&");
$(this).append('<button onclick="GREGON_downloadFile(\''+array[0].replace("mxc://", "")+'\', \''+name+'\', \''+array[2]+'\');">Скачать '+name+'</button>');
});
}
$(document).ready(function() {
$('#form-buttons>table>tbody>tr').append('<td><input type="file" class="GREGON_fileUpload" id="GREGON_fileUpload" style="color: transparent;" /></td>');
const GREGON_input = document.querySelector('.GREGON_fileUpload');
console.log(GREGON_input);
GREGON_input.addEventListener('change', (event) => {
console.log('input');
const fd = new FormData();
const file = event.target.files[0];
// add all selected files
fd.append(event.target.name, file, file.name);
file.arrayBuffer().then(
function(value) {
GREGON_uploadFile2(value, file.name, file.type);
},
function(error) { /* code if some error */ }
);
});
GREGON_RenderFiles();
});
- Подпись автора
Я администратор. Я сделал очень много вещей, например кнопку чата сверху (кстати заходите, если хотите дам вам пароль от пробного аккаунта), отправку файлов (через тот чат, не удаляйте пробный аккаунт пожалуйста, иначе отправка файлов перестанет работать), тёмную тему, нормальное цитирование, выбор смайликов и многое другое.
▶ Matrix ◈ Mastodo… ой то есть Misskey ◀
[html]<iframe src="https://shitpost.poridge.club/embed/user-timeline/a7w5npj75y?maxHeight=300" data-misskey-embed-id="v1_f2e81845-9b9f-4b1c-a8f8-4edd40b0171c" loading="lazy" referrerpolicy="strict-origin-when-cross-origin" style="border: none; width: 100%; width: 500px; height: 300px; color-scheme: light dark;"></iframe>
<script defer src="https://shitpost.poridge.club/embed.js"></script><a href=https://www.calend.ru target=_blank style="display: inline; position: absolute; margin-left: 20px;"><img src="https://www.calend.ru/img/export/informer.png" width="189" alt="Праздники сегодня" border="0"></a>[/html]