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
[Feature] New metablock @filetype #1842
Comments
I don't think the ability to change headers is within the scope of a userscript manager. @gera2ld? |
It is possible by Web Extension API.
So this API be called indirectly from GM.xmlHttpRequest
Code > GM.xmlHttpRequest > webRequest.onHeadersReceived > document.contentType
Otherwise, I think this can be done from metablock.
|
Judging by the description GM.xmlHttpRequest is entirely unrelated. You seem to want to change the content type of the web page. I don't see it as something a userscript manager should do. |
On Thu, 29 Jun 2023 07:36:54 -0700 tophf ***@***.***> wrote:
Judging by the description GM.xmlHttpRequest is entirely unrelated.
You seem to want to change the content type of the web page. I don't
see it as something a userscript manager should do.
Given that it is possible to open archives (e.g. GZip, ZIP and Tar),
process documents (PDF, DOCX, ODT), edit image files and even play
Macromedia Flash files (SWF) using Javascript alone, then I see no
reason why shouldn't a userscript manager be able to operate on
non-HTML files.
Please, do examine the userscript I've linked to (Newspaper) and test
it with JSON and XML files - There is a list of feeds inside the Help
page of the program itself.
|
Userscript managers shouldn't change the type of the document, it's beyond their scope. |
Who's to decide what Userscript managers should not do?
I think that Greasemonkey and USO (userscripts.org) are the greatest influencers of HTML5, and Greasemonkey was a not something that was expected to be. It is also discouraged by bigger web companies.
Moreover, I think it would be most appropriate to incorporate the
capability of the program Open in Browser into Userscript mangaer 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
https://github.com/Rob--W/open-in-browser
|
The deciding factor is common sense. Userscript manager's purpose is to inject and manage userscripts. This is the vision we implement. We regularly reject the temptation to add a feature that would be useful only to a couple of userscripts. |
This is the actual error:
Caused by function settingsPage() {
document.body.insertAdjacentHTML('beforeend', htmlSettings); // <-- Error!
let btn = document.querySelector('#about-settings');
let dia = document.querySelector('#page-settings');
btn.addEventListener ("click", function() {
if (document.contentType.endsWith('xml')) {
alert('Setting are disabled on this page.');
return;
}
dia.style.display = 'block';
});
} The value of <div class="about-newspaper" id="page-settings">
<h1>Settings</h1>
<p>Settings are saved instantly upon click.</p>
<table>
<!-- tr>
<td>
<span>Articles</span>
</td>
<td>
<span><input type="number" name="item-number" id="item-number" min="2" max="50"/> <label>№</label></span>
<p>Maximum number of articles to display (2 - 50)</p>
</td>
</tr -->
<tr>
<td>
<span>Text Size</span>
</td>
<td>
<span>
<input type="number" name="font-size" id="font-size" min="15" max="50"/>
<label>px.</label>
</span>
</td>
</tr>
<tr>
<td>
<span>Font Style</span>
</td>
<td>
<span>
<select name="font-type" id="font-type">
<option value="arial">Arial</option>
<option value="sans">Sans</option>
<option value="serif">Serif</option>
<option value="system-ui">System</option>
<select>
</span>
</td>
</tr>
<tr>
<td>
<span for="view-mode">Mode</span>
</td>
<td>
<span>
<select name="view-mode" id="view-mode">
<option value="bright">Bright</option>
<option value="dark">Dark</option>
<!-- option value="sepia">Sepia</option -->
<select>
</span>
</td>
</tr>
<!-- tr>
<td>
<span>Podcast</span>
</td>
<td>
<span>
<input type="checkbox" name="play-enclosure" id="play-enclosure"/>
<label for="play-enclosure">Play Audio</label>
</span>
<span>
<input type="checkbox" name="disable-enclosure" id="disable-enclosure"/>
<label for="disable-enclosure">Disable Enclosures</label>
</span>
</td>
</tr>
<tr>
<td>
<span>Hide</span>
</td>
<td>
<span>
<input type="checkbox" name="hide-audio" id="hide-audio"/>
<label for="hide-audio">Audio</label>
</span>
<span>
<input type="checkbox" name="hide-image" id="hide-image"/>
<label for="hide-image">Image</label>
</span>
<span>
<input type="checkbox" name="hide-media" id="hide-media"/>
<label for="hide-media">Media</label>
</span>
<span>
<input type="checkbox" name="hide-video" id="hide-video"/>
<label for="hide-video">Video</label>
</span>
</td>
</tr -->
</table>
<p>Click reload to apply changes.</p>
<button id="reload">Reload</button>
<button id="close">Close</button>
</div> If we run this through an XML validator to see why this isn't valid XML, we get this:
Which corresponds to this part of your html: 30 | <span>
31 | <select name="font-type" id="font-type">
32 | <option value="arial">Arial</option>
33 | <option value="sans">Sans</option>
34 | <option value="serif">Serif</option>
35 | <option value="system-ui">System</option>
36 | <select> <!-- ERROR HERE -->
37 | </span>
38 | </td>
39 | </tr>
40 | <tr>
41 | <td>
42 | <span for="view-mode">Mode</span> There is indeed an error in your settings page HTML. The only reason this works in regular HTML is because browsers will try to correct mistakes in html, which includes missing closing tags. The browser here sees the If we correct this error (and another identical one in line 51), the error disappears. |
While I'm already on the task of fixing your script errors:
This error can come not just from the Greasemonkey api being unavailable, but from the script settings not being populated - You loop through your input/select elements for (const controller of document.querySelectorAll('#page-settings input, #page-settings select')) { which are
and then on each call case ('number'):
controller.setAttribute('value', value); which then calls setAttribute on undefined. Since you wrapped way too much code in a try-catch, this still results in a "Greasemonkey API Not Available" error. |
Some other issues actually are caused by the document being XML, such as function createPage() {
let domParser = new DOMParser();
let newDocument =
domParser
.parseFromString('', 'text/html');
return newDocument;
} function renderActivityStream(jsonFile) {
let newDocument = createPage();
newDocument.title = jsonFile.title;
if (jsonFile.language) {
newDocument
.documentElement
.setAttribute('lang', jsonFile.language);
}
let feed = newDocument.createElement('div');
feed.id = 'feed'; however you then also need to use document.querySelector("#links-bar").style === undefined
document.querySelector("#title").style instanceof CSSStyleDeclaration since the different elements are created in different ways function linksBar() {
let divElement = document.createElement('div'); // document -> this creates an XML object
divElement.innerHTML = htmlBar; let title = newDocument.createElement('h1'); // newDocument -> this creates a HTML element
if (jsonFile.title) {
title.textContent = jsonFile.title;
} else {
title.textContent = document.location.hostname;
}
title.id = 'title';
feed.append(title); and why did i spend my time on this, i only wanted to check if @\run-at context-menu support was planned |
The Invalid XML error was fixed. I'm uploading a new version now. |
I did this so it would be easier to execute the script from Inspector in web browsers without Userscript enabled. I'd be glad to get some help on this. I'm not familiar with GM settings much. |
Yes, but only as long as the Funny to mention that the output of |
I have intentionally made the functions called from
Nice. I didn't know that. Please look into newDocument = purgeStylesheets(newDocument); // FIXME
newDocument = setCssStylesheet(newDocument); // FIXME TODO SET XML-STYLESHEET IF CONTENT-TYPE IS XML
if (xmlStylesheet) {
stylesheetMessage(newDocument)
} |
Video preview of the script in action in a page that simplescreenrecorder-2023-06-29_21.12.45.mp4 |
On Sun, 02 Jul 2023 05:54:12 -0700 tophf ***@***.***> wrote:
Closed #1842 as not planned.
Respectfully.
Thank you for your kind attention and analyses of this issue.
|
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 |
Motivation
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.
Proposed Solution
This is a request to add new API
to GM.xmlHttpRequest, or to the core of the Greasemonkey extension,that can influence a change indocument.contentType
.See #1842 (comment)
Use Cases
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
The text was updated successfully, but these errors were encountered: