Greasy Fork is available in English.

Συζητήσεις » Ανάπτυξη

Can't interact with pdf file elements

§
Δημοσιεύτηκε: 31/07/2021
Επεξεργάστηκε: 31/07/2021

I can't get the page number of a pdf file on edge chromium, I thought I would need unsafeWindow but that didn't change anything, then I thought I wasn't trying to do it on the correct time so I added the alert inside the setInterval, but I keep getting null all the time.

// ==UserScript==
// @name p
// @namespace p
// @version 0.1
// @include file://*
// @include *.pdf
// @include *.pdf?*
// @include *.pdf#*
// @include /file:\/\/\/.*(.pdf)/
// @run-at document-end
// @grant GM_getValue
// @grant GM_setValue
// @grant unsafeWindow
// ==/UserScript==

(function() {
'use strict';
setInterval(function(){
alert(unsafeWindow.document.querySelector("input#pageselector").value );
}, 1000);
})();

§
Δημοσιεύτηκε: 31/07/2021

I think I know how to do this. Wait a few minutes

woxxomΣυντονιστής
§
Δημοσιεύτηκε: 31/07/2021

What you see in devtools is DOM of the built-in chrome extension that shows PDF files (its URL and id is shown in the title of devtools). Userscripts can't run there and can't access those elements. The only thing you can do is to use the very limited communication API, which among a few useless things allows reading the currently selected text: https://stackoverflow.com/a/61076939/3959875

§
Δημοσιεύτηκε: 31/07/2021

Nevermind, he is right

§
Δημοσιεύτηκε: 31/07/2021
Επεξεργάστηκε: 31/07/2021

@wOxxOm
Yeah I supposed that was the case, that's sad.

@Konf
Thanks for the try.

Δημοσίευση απάντησης

Συνδεθείτε για να δημοσιεύσετε μια απάντηση.