How to overwrite internal functions when developing plugins.

Hi, I am new to zotero plugin development. I want to modify an internal function in Zetero. To be more specific, I want to modify https://github.com/zotero/reader/blob/46c061d14271d03b6d323022ef94120b6f53b1ca/src/pdf/page.js#L326
Is this possible?
( I want to change the `scale = this.scale * (22 / 24);` to `scale = this.scale * (11 / 24);` so that the notes icon becomes smaller.)
  • Better to post questions like this to zotero-dev Google group. We try to keep technical discussions there.

    It should be possible to monkey patch that function, but it probably won't be easy because you would need to do it for all pages. Also there's another part of the code responsible for interacting with note annotation that also needs to be scaled down, which is even more complicated. Anyway, I don't recommend doing this.

    Why exactly you need to make the icon smaller?
  • Thank you for your comment.

    I think these icons are too big. I have seen several discussions complaining about this. (https://forums.zotero.org/discussion/106049/pdf-reader-add-note-icon-is-huge)(https://forums.zotero.org/discussion/94847/why-do-comment-markers-come-in-2-different-sizes-in-zotero-pdf-reader)

    I switched from mendeley to zotero recently. I import the files from mendeley. Those icons looks fine in mendeley, but they are too big in zotero, and obscure the text.

    Zotero:
    https://s3.amazonaws.com/zotero.org/images/forums/u14206840/bfoo22nr77a37ws77c7v.png

    Mendeley:
    https://s3.amazonaws.com/zotero.org/images/forums/u14206840/r7i0ew5uijn6t5xhqrex.png
  • @martynas_b

    May I ask what is the "another part to code"? I saw there is a `renderAnnotationOnCanvas`, but it seems to be used for visualizing the icons when dragging the icons to change their location. Is this what you mean? Could you please provide more information?

    I tried the following codes in the development console in zotero, which seems to work.
    ```
    const reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
    var page_i = reader._internalReader._primaryView._pages[0];
    page_i.constructor.prototype._renderNote=function(annotation) {
    let position = page_i.p2v(annotation.position);
    page_i.actualContext.save();
    let viewRect = position.rects[0];
    let scale = page_i.scale * (11 / 24);
    page_i.actualContext.transform(scale, 0, 0, scale, viewRect[0], viewRect[1]);
    page_i.drawNote(page_i.actualContext, annotation.color);
    page_i.actualContext.restore();
    }
    ```

    I am new to JavaScript writing extensions. I still struggle to develop a plugin to run these code snippets for every opened tab. Is my codes the correct way to monkey patch the function? (I will go to zotero-dev Google group as you suggested)
  • I think it's not only about the size, but also about where the note annotation is placed. I agree it can be a problem when importing existing annotations.

    But those note annotations in the screenshots seem to be linked to specific highlights, and in Zotero, we keep them as comments on highlights instead of standalone note annotations. So that's the main problem we should focus on.
  • @martynas_b Thank you for your reply.

    You are correct those notes correspond to highlights, but when created by Mendeley, they are not "linked". In Mendeley, the user can select a chunk of text, right-click, and select "add notes", then the text is highlighted automatically and a note is added. However, Mendeley seems to create a highlight without comment and a note, instead of a highlight linked with a comment.

    So I want to make the icons smaller, otherwise reading the PDFs imported from Mendeley is torture. I think the original place of the note annotation is fine since Mendeley placed it there and no obscure happened.
Sign In or Register to comment.