Skip to content

New metablock @filetype #211

Closed
Closed

Description

@sjehuda

I think it would be most appropriate to incorporate the capability of the program Open in Browser into metablocks as follows:

// @filetype text/xml text/html
// @filetype application/xml text/html
// @filetype application/rss+xml text/html
// @filetype application/atom+xml text/html

@filetype: @mimetype would be good too
text/html: text/plain would be good too

About

This is a request to add new API to GM.xmlHttpRequest, or to the core of the Greasemonkey extension, that can influence a change in document.contentType.

Preface

I have wrote a userscript that converts structured data files (i.e. XML and JSON) into human readable HTML files.

Overhaul, the program works as expected; documents are processed and forged successfully into HTML.

All the extra functionalities work well when document.contentType (read only) does not contain xml.

However, when document.contentType has xml, any code that contains querySelector would fail because the document is believed to be whatever document.contentType has determined upon initial request (an XML file), and, apparently, the web browser doesn't check document once it has been loaded.

An error message from the program suggests the file processed is XML when in reality it is an HTML, hence hinders other functions to be executed:

Expected Behavior

Execute actions on document as as HTML.

Actual Behavior

Browser blocks HTML actions (throws errors) because it is believed to be an XML.

Script

https://greasyfork.org/en/scripts/465932-newspaper-native-rss-reader

Test Page

https://lzone.de/liferea/blog/feed.xml application/xml

Note

More information at greasemonkey/greasemonkey#3164

Activity

  1. changed the title [-]Add an equivalent to webRequest.onHeadersReceived[/-] [+]New metablock @filetype[/+] on Jun 29, 2023
  2. CodFrm commented on Jun 29, 2023

    @CodFrm
    Member

    This is an interesting script, I looked at Tampermonkey and Violentmonkey, it seems to be working, but Scriptcat is not working, let me first solve this problem 😂.

    In addition, can we solve this problem from other aspects? For example, Web Component, the style of this attribute will inherit from custom-card, but this seems troublesome

    image
  3. sjehuda commented on Jun 29, 2023

    @sjehuda
    Author

    This is an interesting script

    Thank you.

    I looked at Tampermonkey and Violentmonkey, it seems to be working, but Scriptcat is not working, let me first solve this problem 😂.

    It doesn't work with Greasemonkey neither.
    I think it stopped to work with Greasemonkey after I've added more GM.getValue and GM.setValue.

    In addition, can we solve this problem from other aspects? For example, Web Component, the style of this attribute will inherit from custom-card, but this seems troublesome

    I'm an Attorney at Law, not a programmer.

    Please kindly explain what do you mean by "Web Component".

    As I stated, I think that a metablock (@filetype or @mimetype) that would imitate "Open in Browser" should handle this task, not only for XML files, but also images archives and documents.

    See my comments at violentmonkey/violentmonkey#1842 (comment)

  4. sjehuda commented on Jun 29, 2023

    @sjehuda
    Author

    Please navigate to about:config
    Set devtools.jsonview.enabled to false

    And test this script with these pages:

    https://www.jsonfeed.org/feed.json

    https://nu.federati.net/api/statuses/user_timeline/2.as

    http://scripting.com/rss.json

    https://peertube.su/feeds/videos.json?sort=-trending

    https://librivox.org/feed/

    Video preview of the script in action in a page that document.contentType doesn't contain xml.

    simplescreenrecorder-2023-06-29_21.12.45.mp4
  5. CodFrm commented on Jun 30, 2023

    @CodFrm
    Member

    This is the document of Web Component: https://developer.mozilla.org/en-US/docs/Web/API/Web_components, my idea is to use its shadow DOM feature to change the outer custom-card style Inheritance, but I'm not sure if I can solve this problem, and it's very troublesome.

    What's weird is that some elements have element.style and some don't.

    In short, see if there is any other solution to this problem. If not, I will consider trying to add the metablock @filetype you mentioned (but maybe in this form: #54)

  6. sjehuda commented on Apr 8, 2024

    @sjehuda
    Author

    I have managed to overcome this setback, namely by passing the HTML element newDocument and processing it in all ways feasible (see preProcess) and then replacing document by newDocument. See v24.04.06 vs. v24.04.08.

    There was also another matter which required to create an element and change CSS Stylesheet in order to get the expected behaviour, because JavaScript attribute style does not work with document.contentType that ends with XML. See v24.04.08 vs. v24.04.09.

    The only functionality which remains not to work upon XML is mode switcher (bright and dark) due to attribute style, yet it might be possible to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions