Greasy Fork is available in English.

議論 » 開発

Can't interact with pdf file elements

§
投稿日: 2021/07/31
編集日: 2021/07/31

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);
})();

§
投稿日: 2021/07/31

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

wOxxOmMod
§
投稿日: 2021/07/31

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

§
投稿日: 2021/07/31

Nevermind, he is right

§
投稿日: 2021/07/31
編集日: 2021/07/31

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

@Konf
Thanks for the try.

返信を投稿

返信を投稿するにはログインしてください。