New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: GM_xmlhttpRequest setting responseType support #1834
Comments
Hi, just wanting to say that I would love to have this feature :) It's still planned for version 1.16? As this hasn't got any comment in 3 months. |
👍 I need this function too |
@steelywing That's how I ended up doing it (coffeescript, but should be easy to get):
It's not nearly as nice as setting responseType to "blob" (and it's probably way slower as well), but it does work, at least for what I needed it (it will return a blob with the retrieved data). |
I was using ver2.2 and firefox32,and set : responseType: 'blob' , but what I get in the onload() function is not blob object,just some text like
my code:
|
See #2032 . |
Can I set responseType : "arraybuffer" now? |
Yes. See also http://www.greasespot.net/2015/05/greasemonkey-32-release.html |
I try to rip out the email info from online PDF and firstly the whole text should be get. So I find http://hublog.hubmed.org/archives/001948.html I use Greasemonkey version 4.1.10 to do a cross domain version with GM_xmlhttpRequest. Here's the script from that site, how can I make it working correctly? Especially here I update with
|
// ==UserScript==
// @name Greasemonkey - issue - 1834
// @include http://git.macropus.org/2011/11/pdftotext/example/
// @grant GM_xmlhttpRequest
// ==/UserScript==
// 1 - GM_xmlhttpRequest(), 2 - XMLHttpRequest()
var what = 1;
var pdfsrc = window.location.href;
// using a sample PDF for test now
if (what == 1) {
// pdfsrc = "http://www.cbu.edu.zm/downloads/pdf-sample.pdf";
pdfsrc = "http://git.macropus.org/2011/11/pdftotext/example/journal.pone.0026738.pdf";
} else if (what == 2) {
pdfsrc = "http://git.macropus.org/2011/11/pdftotext/example/journal.pone.0026738.pdf";
}
html = document.body.innerHTML + `
<div style="position: absolute; left: 10px; top: 200px; color: white; z-index: 100;">
Attention<br><iframe id="input" src="`+ pdfsrc +`"></iframe><br>
<iframe id="processor" src="http://hubgit.github.com/2011/11/pdftotext/"></iframe><br>
<div id="output"></div></div>
`;
document.body.innerHTML = html;
// document.getElementById("plugin").remove();
var input = document.getElementById("input");
var processor = document.getElementById("processor");
var output = document.getElementById("output");
// listen for messages from the processor
window.addEventListener("message", function (event) {
if (event.source != processor.contentWindow) return;
switch (event.data) {
// "ready" = the processor is ready, so fetch the PDF file
case "ready":
if (what == 1) {
GM_xmlhttpRequest({
method: "GET",
responseType: "arraybuffer",
// url: input.getAttribute("src"),
url: pdfsrc,
onload: function (event) {
var clonedArrayBuffer = new Uint8Array(event.response);
var clonedArrayBufferStr = "";
for (var i = 0, count = clonedArrayBuffer.byteLength; i < count; i++) {
clonedArrayBufferStr += clonedArrayBuffer[i]
+ (i == (count - 1) ? "" : " ");
}
console.log("GM_xmlhttpRequest():" + "\n" + clonedArrayBufferStr);
processor.contentWindow.postMessage(event.response, "*");
}
});
} else if (what == 2) {
var xhr = new XMLHttpRequest();
// var url = input.getAttribute("src");
var url = pdfsrc;
xhr.responseType = "arraybuffer";
xhr.onload = function (event) {
var clonedArrayBuffer = new Uint8Array(this.response);
var clonedArrayBufferStr = "";
for (var i = 0, count = clonedArrayBuffer.byteLength; i < count; i++) {
clonedArrayBufferStr += clonedArrayBuffer[i]
+ (i == (count - 1) ? "" : " ");
}
console.log("XMLHttRequest():" + "\n" + clonedArrayBufferStr);
processor.contentWindow.postMessage(this.response, "*");
};
xhr.open("GET", url);
xhr.send();
} else {
console.log("NOTHING!");
}
break;
// anything else is the text of the PDF
default:
output.textContent = event.data.replace(/\s+/g, " ");
break;
}
}, true); |
I want to use GM_xmlhttpRequest to get an image and store it in indexeddb.The responseText should be blob.
https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/
The text was updated successfully, but these errors were encountered: