sjehuda Author

Solved by:

function setNonceUponCSP() {
  window.addEventListener("securitypolicyviolation", (e) => {
    //let message = e.originalPolicy;
    //messageTruncated = message.substring(message.indexOf("'nonce-") + 7);
    //let nonceValue = messageTruncated.substring(0, messageTruncated.indexOf("'"));
    let nonceValue = e.originalPolicy.match(/'nonce-(.*?)'/)[1];
    cssStylesheet = document.getElementById(namespace);
    cssStylesheet.setAttribute('nonce', nonceValue);
  }, { passive : true, });
}

I didn't find a way to make it to work on first error.


Plan cancelled.

Thos program, now, takes the content, regardless of content-type header, and determines whether data is feed or is not.


GM.xmlHttpRequest (incorporated into Promise)

gmXmlhttpRequest({
  method: 'GET',
  url: document.documentURI,
  headers: {
    "Content-Type": "text/plain",
    "Accept": "text/plain"
  },
  onprogress: function(request) {
    request.responseType = 'text';
  },
  onload: function(request) {
    request.overrideMimeType = 'text/plain';
    if (document.URL.startsWith('file:') ||
        request.status == 200) {
      myResolve(request);
    }
    else {
      myReject("File not Found");
    }
  },
  onerror: function(request) {
    console.log('Error Error Error')
  }
})

Failed.



I'm attempting to forge content-type header.

I've attempted the followings:

XHR

request = new XMLHttpRequest();
request.open('GET', document.documentURI, false);
request.overrideMimeType('text/plain');
request.setRequestHeader('content-type', 'text/plain');
request.send();
//console.info(`all headers: ${request.getAllResponseHeaders()}`);
console.info(`content-type header: ${request.getResponseHeader('content-type')}`);
console.info(`content-type document: ${document.contentType}`);

Fetch

fetch(
  document.documentURI,
  {
    method: 'GET',
    headers: {
      "content-type" : "text/plain",
    },
  }
)
.then((response) => {
  console.info(response.headers.get('content-type'))
});

Both didn't work.



document.inputEncoding can achieve it.

let request = fetch(url)
  .then(response => response.arrayBuffer())
  .then(buffer => {
    let decoder = new TextDecoder(document.inputEncoding);
    let text = decoder.decode(buffer);
    handleText(text);
  });

https://furbo.org/feed/atom/


Setting arbitrary MIME Type (document.contentType) using Open in Browser will result in the following findings:

Opening as "text/plain", "text/html" will make everything work.

Opening as "text/xml" (including "application/xml" etc.) will only build HTML file, without CSS related additions.

Attempting to set MIME Type using this code has failed:

request.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');

Testing feeds:
https://www.kaidan.im/atom.xml
https://www.falkon.org/atom.xml
https://www.jsonfeed.org/feed.xml
https://furbo.org/feed/atom/


Setting arbitrary MIME Type (document.contentType) using Open in Browser will result in the following findings:

Opening as "text/plain", "text/html" will make everything work.

Opening as "text/xml" (including "application/xml" etc.) will only build HTML file, without CSS related additions.


Attempting to set MIME Type using this code has failed:

request.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8');

Testing feeds:
https://www.kaidan.im/atom.xml
https://www.falkon.org/atom.xml
https://www.jsonfeed.org/feed.xml



This is the function in question.

function extensionLoader(url) {
  purgeStylesheets();
  formatDate();
  setCssStylesheet();
  decorateEntry();
  linksBar();
  follow(url);
  subToMe(url);
  aboutPage();
  donatePage();
  settleFilters();
  scrollDown();
  statusBar();
  mailTo();
}

The functions formatDate(), linksBar(), aboutPage, donatePage and statusBar() do work for the XML feed, but not all the rest of the functions, such as setCssStylesheet();.

Styling functions tend to work in more cases when loading them to the generated document before setting it with the original document, but I'm interested in doing all the post-work after the HTML file is ready.


Hello,

I've rewrote Newspaper to work without XSLTProcessor, which turned out to be even easier and shorter, and now it works with all web browsers.

Background

Once a page is validated to be of type feed, the executes two main actions to generate an HTML page.

Function renderXML(xmlFile, atomRules) to gather data bfrom the file and generate an HTML out of it.

Function extensionLoader() which adds CSS stylesheet and some functions of accessibility and navigation.

This script has been tested successfully with all formats: Atom, ActivityStream, JSON, RDF and RSS.

Issue

However, the part of extensionLoader() doesn't always work, and the reason is unknown to me.

Below are two feeds on the same server of same content but different formats (one is XML and the other is JSON); the function extensionLoader() works only with the JSON feed.

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

This post is not related to this thread

Please help!

Kindly,
Schimon


Why was this closed?

Don't you think this is worth attention, especially when it is concerning to Userscripts and the news SRI policy?

What would be the best place to collaborate on this suggestion if not here?


Hello,

I'm attempting to build HTML from JSON by reading it with a loop statement.

This is what I came up with thus far:

feedItems = {
  "div": "feed",
         "attributes": {
           "style" : "language",
         },
         "children" : {
           "div": "title",
           "div": "subtitle",
           "div": "links-bar",
           "div": "entry", // multiple alike
                  "attributes": {
                    "style" : "language",
                  },
                  "children" : {
                    "div" : "title",
                    "attributes": {
                      "href" : ["url", "id"],
                      "id" : "id",
                    },
                    "div" : ["authors", "author"],
                    "div" : ["date_published", "date_modified"],
                    "div" : ["content_html", "content_text"],
                    "div" : "image",
                    "div" : "tags",
                  },
           }
};

/* NOTE Handling attributes
"attributes": {
  "style" : { 
    "direction" : "language"
  }
} */


Yes, I am; I've just checked if something has changed since then.

I'll look into it and add Feeds for OUJS (all, users, tags), and later add a Web Browser News like the one of USO.

I don't have (the time to establish) a node.js server.

Do we have a sandbox node.js server of OUJS to make tests on?


Metablock // @downloadURL seems to solve this issue to some extent.




🚥 Clean URL Improved (URL Control)

Clean URL Improved userscript has a special update.

Clean URL Improved has a popup box (aka tooltip) which suggests a selection of 4 links:

🔴 Original URL

🟡 Purged URL

🟢 URL with whitelisted parameters

⭕ URL with no parameters

🔗 URL found within a search parameter


TODO

Reduce amount of links when there are to identical links;

Event Listener Delegation doesn't always work (See hyperlink #4);

URL found within a search parameter (🔗) might need a check/verification that it's a valid URL.


Test hyperlinks with parameters:

Link #1 (orderBy, orderDir, ref) // Tooltip
Link #2 (orderBy, orderDir, v) // No tooltip
Link #3 (orderBy, orderDir, v, ref) // Tooltip
Link #4 (orderBy, orderDir, v, url) // FIXME no tooltip (event listener)

Test (plain) links with parameters:

https://openuserjs.org/?orderBy=updated&orderDir=desc&ref=sjehuda // Tooltip
https://openuserjs.org/?orderBy=updated&orderDir=desc&v=sjehuda // No tooltip
https://openuserjs.org/?orderBy=updated&orderDir=desc&v=sjehuda&ref=sjehuda // Tooltip
https://openuserjs.org/?orderBy=updated&orderDir=desc&v=sjehuda&ref=sjehuda&url=https://blacklistednews.com // Tooltip

Feedbacks are welcome!

Best,
Schimon




Here is a way to apply CSS style per element.

This is useful in case Subresource Integrity is enabled.

I might be missing here something or it is impossible to utilize pseudo-class in the fashion persented here.

Please pardon me for the mess (i.e. slice & replace).

jsonStyle = {
  // CSS stylesheet converted into JSON
}

list = Object.keys(jsonStyle);

for (let i = 0; i < list.length; i++) {
  for (const element of document.querySelectorAll(`${list[i]}`)) {
    element.style = JSON.stringify(jsonStyle[`${list[i]}`])
      .slice(2)
      .replace('"}','')
      .replace(/['"]+/g, '')
      .replace(/[',]+/g, ';');
    //console.log(list[i])
    //console.log(element.style)
  }
}

I've used this tool to convert CSS to JSON https://transform.tools/css-to-js