Skip to content
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

How to handle cross domain? #4

Open
pendave opened this issue Oct 30, 2016 · 1 comment
Open

How to handle cross domain? #4

pendave opened this issue Oct 30, 2016 · 1 comment

Comments

@pendave
Copy link

pendave commented Oct 30, 2016

I try to use Greasemonkey GM_xmlhttpRequest but responseType : "arraybuffer" is not supported.

@pendave
Copy link
Author

pendave commented Oct 31, 2016

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
and its nice example:
http://git.macropus.org/2011/11/pdftotext/example

I use Greasemonkey version 4.1.10 to do a cross domain version with GM_xmlhttpRequest.
I see responseType : "arraybuffer" should be working but I can't get the script doing right from XMLHttpRequest to GM_xmlhttpRequest.

Here's the script from that site, how can I make it working correctly?
var pdfsrc = window.location.href;
//using a sample PDF for test now
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":
var xhr = new XMLHttpRequest();
//url: input.getAttribute("src"),
url: pdfsrc,
xhr.responseType = "arraybuffer";
xhr.onload = function(event) {
processor.contentWindow.postMessage(this.response, "*");
};
xhr.send();
break;
// anything else is the text of the PDF
default:
output.textContent = event.data.replace(/\s+/g, " ");
break;
}
}, true);

Especially here I update with

case "ready":
GM_xmlhttpRequest({
method: "GET",
url: input.getAttribute("src"),
onload: function(event) {
processor.contentWindow.postMessage(this.response, "*");
}
});
break;

qq 20161031104510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant