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
[Firemonkey] New metablock @filetype #568
Comments
Here is a test script: // ==UserScript==
// @name New metablock @filetype #568
// @match https://lzone.de/liferea/blog/feed.xml
// @version 1.0
// ==/UserScript==
console.log(document.querySelector('subtitle')); Scope of UserScriptsAs also mentioned in violentmonkey/violentmonkey#1842 (comment) , I also believe that the scope of userscripts is, and should be, limited to the webpage, as originally intended. GM functions were added to facilitate some of the common difficulties. HTTP headers are in the scope of the browser. TM provides some functionality beyond the scope of the webpage (e.g. `GM_webRequest, or GM_cookie.list, but that is not supported by other managers. Allowing userscripts that are meant to be page scripts, access to browser level API can pose a security risk, as well as interfere with functionality of the browser and/or other extensions. |
document.contentType
Then something else isn't working the same as it would, if the This is the problem violentmonkey/violentmonkey#1842 (comment) Even if by setting The following code, won't solve the issue. Tampermonkey/tampermonkey#1809 (comment)
Vendor bullyingAnother reason to add the proposed metablock is to overcome bullying from web browser vendors who decide upon technologies they want to censor. This userscript was born because of the attempt of the red lizard and globe fox to conceal RSS. They have done it by:
It makes no sense. This is censorship of independent media and people under the guise of UI improvements. JavaScript scopeHowever, due to the fact that we can process any file in Javascript, including documents (ODT and PDF), archives (7Zip and Gzip) and even databases, I suggest to add the @filetype / @MimeType metablocks. |
In order to investigate further, please provide a minimal userscript that demonstrate the issue. |
Because, technically, an example userscript won't be of use, the following example should be enough. If you insist, I will provide you a minimal script. Suppose I want to turn data into a table or I want to process a web feed, as I do with my script. Visit this page with Firefox https://reclaimthenet.org/feed |
In order to investigate further, please provide a minimal userscript
that demonstrate the issue.
Here is a simple script that doesn't appear to work with xml, because
some properties are exclusive to HTML and XML.
Uncaught TypeError: Cannot read property 'clientWidth' of null
Tested with Falkon web browser.
// ==UserScript==
// @name Falkon Image Fix
// @namespace i2p.schimon.falkon.image
// @description Script description
// @include *
// @Version 1.0.0
// ==/UserScript==
if (!document.contentType.startsWith('image/')) { return; };
const
ele = document.querySelector('img');
width = ele.clientWidth,
height = ele.clientHeight,
fileType = ['image/avif', 'image/png', 'image/png', 'image/svg+xml',
'image/webp'];
window.addEventListener('click',event => {
//if (ele.style.cursor == 'zoom-in') {
if (ele.style.cursor == 'zoom-out') {
if (height > width) {
ele.style.height = '100%';
ele.style.width = 'auto';
} else {
ele.style.height = 'auto';
//ele.style.width = '97vh';
ele.style.width = '100%';
}
}
});
for (let i = 0; i < fileType.length; i++) {
if (document.contentType.match(fileType[i])) {
// 808080 525c66 dddddd
// Source: /questions/35361986/css-gradient-checkerboard-pattern
document.body.style.backgroundImage = 'linear-gradient(45deg,
#a3a3a3 25%, transparent 25%), linear-gradient(-45deg, #a3a3a3 25%,
transparent 25%), linear-gradient(45deg, transparent 75%, #a3a3a3 75%),
linear-gradient(-45deg, transparent 75%, #a3a3a3 75%)';
document.body.style.backgroundSize = '20px 20px';
document.body.style.backgroundPosition = '0 0, 0 10px, 10px -10px,
-10px 0px'; } }
document.title = `${document.title} ${document.contentType}`
|
Can you give an example site to test? The script is meant to run only when tab is showing an image. |
PNG (HTML)
https://thirdeyemedia.wpmudev.host/wp-content/uploads/sites/7/2020/04/logo_sbb1.png
SVG (XML)
https://speek.network/static/img/speeklogo.svg
I tested with Falkon browser.
I don't know what the results with other web browsers.
|
On Wed, 05 Jul 2023 10:30:27 -0700 erosman ***@***.***> wrote:
`if (!document.contentType.startsWith('image/')) { return; };`
Pleaes comment/delete that first line.
The code should work with WebKit web browsers using console.
|
Here is a simple script, tested on Firefox. // ==UserScript==
// @name Falkon Image Fix
// @namespace i2p.schimon.falkon.image
// @description Script description
// @match *://*/*
// @version 1.0.0
// ==/UserScript==
// IIF anonymous function wrapper, for error checking & limiting scope
(() => {
if (!document.contentType.startsWith('image/')) { return; }
// get the image
const xml = document.contentType === 'image/svg+xml';
const img = xml ? document.documentElement : document.querySelector('img');
if (!img) { return; }
// limit the max size
img.style.maxHeight = '100vh';
img.style.maxWidth = '100vw';
// make some display changes
document.title += ' ' + document.contentType;
})(); |
Yes. It works with Falkon too, both html (png etc.) and xml (svg). I still insist that there are things that are specific to HTML which can not be done with HTML. See also violentmonkey/violentmonkey#1842 (comment) Yet, in any case, I will address this:
The problem is really the prompt which doesn't allow to open XML files of Atom, RSS and perhaps other formats like ODT and ODS which can be processed using Javascript. So I'm still in favor of metablock |
I would |
I didn't think of doing so. I'll look into it. |
Some feeds are located on different servers so I would likely need to use First observationIf script is executed from an HTML page, then I can Problem 1Upon pressing button Back, user skips the current page, instead of getting back to that page. Solution 1
Problem 2The current page might have Javascript running, and these running scripts can not be turned off. ConclusionRejected. Second observationUse ProblemThat may be annoying. Third observation
|
In any case, as mentioned earlier, changing headers is beyond the scope of userscripts. |
I have managed to overcome this setback, namely by passing the HTML element 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 The only functionality which remains not to work upon XML is mode switcher (bright and dark) due to attribute |
I think it would be most appropriate to incorporate the capability of the program Open in Browser into metablocks as follows:
@filetype
:@mimetype
would be good tootext/html
:text/plain
would be good tooAbout
This is a request to add new API to the core of the Firemonkey 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 containxml
.However, when
document.contentType
hasxml
, any code that containsquerySelector
would fail because thedocument
is believed to be whateverdocument.contentType
has determined upon initial request (an XML file), and, apparently, the web browser doesn't checkdocument
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 scriptscat/scriptcat#211
The text was updated successfully, but these errors were encountered: