sjehuda Author


I'm attempting to add integrity attribute to a style I use for userscript Newspaper (ATOM/RDF/RSS)

Test page: https://mastodon.tedomum.net/@tedomum.rss

The error is this:

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' https://mastodon.tedomum.net 'nonce-FF4fvS9IB+e83sIyujPoyw=='". Either the 'unsafe-inline' keyword, a hash ('sha256-JjOHpf1r2ZHN4jxJdiFIgopy2yA5l3DibXaFr1c70F4='), or a nonce ('nonce-...') is required to enable inline execution.

I used the output of these commands: (also used sha256)

cat FILENAME.js | openssl dgst -sha384 -binary | openssl base64 -A
shasum -b -a 384 FILENAME.js | awk '{ print $1 }' | xxd -r -p | base64

This is the part where integrity is applied:

  if (isRTL) {
    stylesheet
    .textContent =
      stylesheet_ltr + stylesheet_rtl;
    stylesheet
      .setAttribute(
        'integrity',
        'I NEED HELP IN GETTING STRING CHECKSUM'
      );
  } else {
    stylesheet
    .textContent =
      stylesheet_ltr;
    stylesheet
      .setAttribute(
        'integrity',
        'I NEED HELP IN GETTING STRING CHECKSUM'
      );
  }


I'm attempting to add integrity attribute to a style I use for userscript Newspaper (ATOM/RDF/RSS)

Test page: https://mastodon.tedomum.net/@tedomum.rss

The error is this:

Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' https://mastodon.tedomum.net 'nonce-FF4fvS9IB+e83sIyujPoyw=='". Either the 'unsafe-inline' keyword, a hash ('sha256-JjOHpf1r2ZHN4jxJdiFIgopy2yA5l3DibXaFr1c70F4='), or a nonce ('nonce-...') is required to enable inline execution.

I used the output of these commands: (also used sha256)

cat FILENAME.js | openssl dgst -sha384 -binary | openssl base64 -A
shasum -b -a 384 FILENAME.js | awk '{ print $1 }' | xxd -r -p | base64
```

This is the part where integrity is applied:
```js
  if (isRTL) {
    stylesheet
    .textContent =
      stylesheet_ltr + stylesheet_rtl;
    stylesheet
      .setAttribute(
        'integrity',
        'I NEED HELP IN GETTING STRING CHECKSUM'
      );
  } else {
    stylesheet
    .textContent =
      stylesheet_ltr;
    stylesheet
      .setAttribute(
        'integrity',
        'I NEED HELP IN GETTING STRING CHECKSUM'
      );
  }


Hello,

I've made a Userscript inspired by a Userscript by @raingart.
I need help with MutationObserver.
This is the Userscript

Please don't write the name of the website, the brand name starts with A and ends with N.

Kindly,
Schimon


This is my attempt to apply your solution on another website:

//regex = '/^\s*\n/gm'
// .replace(regex, '');

function sumUp() {
//sumUp = (function sumUp(){
//sumUp = (function(){
// Uncaught TypeError: sumUp is not a function

  let
    tag, fee, sum;

  const
    // /questions/1183903/regex-using-javascript-to-return-just-numbers
    regex = /[-]{0,1}[\d]*[.]{0,1}[\d]+/g,
    prices = [],
    selectors = [
      '.a-price-whole',
      '.a-price-fraction',
      '.a-size-base.a-color-secondary',
      ],
    priceConfig = {
      minimumFractionDigits: 2,
      maximumFractionDigits: 2
      };

  for (let i = 0; i < selectors.length; i++) {
    try {
      prices[i] = document
        .querySelector(selectors[i])
        .textContent
        .trim();
    } catch {
      console.log(`No ${selectors[i]}`);
    }
  }

  tag = prices[0] + prices[1];
  tag = tag.match(regex).join('');
  tag = parseFloat(tag);
  fee = parseFloat(prices[2].match(regex).join(''));

  sum = tag + fee
  // Method .toFixed(2) might be preferable. See raingart.
  sum = sum.toLocaleString(navigator.language, priceConfig);

  priceSum = document.createElement('span');
  priceSum.style.fontWeight = 'bold';
  priceSum.style.padding = '6px';
  priceSum.style.margin = '20px';
  priceSum.style.outline = 'auto';
  priceSum.innerHTML = `∑${sum}`;
  document.querySelector('.priceToPay > span:nth-child(2)').append(priceSum);

  //for (const val of document.querySelectorAll('.a-price-whole')) {
  //  val.innerHTML = `${sum}<b>∑</b><sup><sup>(<sup>$</sup>${tag} + <sup>$</sup>${fee})</sup></sup>`;
  //}

//})();
}

sumUp()

/*
// define the target node
var targetNode = document.querySelector('.a-price-whole');
// configuration of the observer
const config = { childList: false, characterData: true, subtree: true, attributes: false, };

// callback function
const callback = function (mutationsList, observer) {
  console.log('Changes Detected');
  if (!targetNode.outerText.includes(' + ')) {
    sumUp();
  }
};
// Create observer instance
const observer = new MutationObserver(callback);

// pass in the target node and configuration observer.observe(targetNode, config);
observer.observe(targetNode, config);
*/

const observerConfig = { childList: false, characterData: true, subtree: true, attributes: false, };
new window.MutationObserver(sumUp).observe(document.querySelector('.a-price-whole'), observerConfig);


Please document your script.

I want to learn MutationObserver, yet all of the documentations I've read thus far are either not clear or over complicated.

Your script seems to be a good example for people who are new to MutationObserver.






This script works and uses localStorage.

Is it wise to use localStorage over GM.getValue/GM.setValue?

I guess a given website can read the localStorage value set by a userscript.

Can websites read values of GM.getValue?






Hello,

I've decided to rebrand FREEdirector to Proxy Redirect.

Is there an automated manner to do so?

Currently, I've changed the older program to direct users to it's project page, in the hope they will see the message and install the new one, but it doesn't seem to work as the installation amount of the older programs keeps growing.

Please advise,
Schimon



This is clearly an attempt to sabotage web feeds, as this article suggests.

To prove my claim, copy and paste one of these scripts to Console and execute.

https://openuserjs.org/scripts/sjehuda/Newspaper
https://openuserjs.org/scripts/sjehuda/Newspaper_(XMLHttpRequest)

Falkon, Otter, Qutebrowser etc. WILL render the XML file into an HTML.

Firefox, however, will produce the following error:

// ==UserScript== 
// @name        Newspaper (XMLHttpRequest)
// @namespace   io.github.sjehuda.syndication4human
// @description Native Feed Viewer. Render syndication web feeds (supports Atom, RDF and RSS)
// @homepageURL https://sjehuda.github.io/newspaper.html…
undefined
Uncaught 
Exception { name: "", message: "", result: 2153775105, filename: "debugger eval code", lineNumber: 210, columnNumber: 0, data: null, stack: "renderFeed@debugger eval code:210:4\ncheckMediaType@debugger eval code:157:13\nhttpGetAsync/xmlHTTPRequest.onreadystatechange@debugger eval code:97:15\nEventHandlerNonNull*httpGetAsync@debugger eval code:77:3\n@debugger eval code:57:13\n" }
debugger eval code:210
    renderFeed debugger eval code:210
    checkMediaType debugger eval code:157
    onreadystatechange debugger eval code:97
    (Async: EventHandlerNonNull)
    httpGetAsync debugger eval code:77
    <anonymous> debugger eval code:57
    getEvalResult resource://devtools/server/actors/webconsole/eval-with-debugger.js:251
    evalWithDebugger resource://devtools/server/actors/webconsole/eval-with-debugger.js:172
    evaluateJS resource://devtools/server/actors/webconsole.js:974
    evaluateJSAsync resource://devtools/server/actors/webconsole.js:865
    makeInfallible resource://devtools/shared/ThreadSafeDevToolsUtils.js:103

A specific mistake of such is very likely intentional, not accidental.

Of note: When I began with XSLT and Javascript (i.e. XSLTProcessor) the MDM documentations were the worst of all others I've found, as if it is intentional by MDM to make people reluctant to XSLT and eventually its great usefulness.

Mozilla officers are welcome to provide an explanation to the above.

Kindly,
Schimon


I need help making image loading better.

Concerning to userscript Newspaper.

Since document is processed while is "on load" (aka "on the fly"), I want to replace all attributes of src to src-data while program processes the document.

I've attempted to do so by adding to function renderFeed the following code which doesn't work for all images, or is it? (I might need to check again)

  for (const image of newDocument.querySelectorAll('img')) {
    //source = image.src;
    //image.removeAttribute('src');
    //image.setAttribute('src-data', source);
    image.setAttribute('src-data', image.src);
    image.removeAttribute('src');
  }

Yet, below the execution of code document.replaceChild(insertDocument,removeDocument); I've added this code:

  for (const image of document.querySelectorAll('img')) {
    image.addEventListener('mouseover', loadImage(image))
    image.onmouseover = () => {
      image.removeEventListener('mouseover',loadImage(image))
    }
  }

Which causes the infinite loop if the line of function loadImage is not commented out.

function loadImage(image) {
  console.log('onmouseover')
  source = image.getAttribute('src-data');
  image.removeAttribute('src-data');
  image.src = source;
  //image.removeEventListener('mouseover',loadImage(image)) // This line causes infinite loop.
}

Note that I use mouseover event so it would be easier to test, though I want the event to trigger when an image element is inside or close to viewport.

P.S.
"Provident Image Load" (PIL) is a better name, eh?
Much better than the stupid phrase "Lazy (so called) Load".




Reference: https://otter-browser.org/feed/

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
GET https://otter-browser.org/feed/ net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
(anonymous)	@	VM43 Newspaper:169
(anonymous)	@	VM43 Newspaper:156
(anonymous)	@	VM43 Newspaper:429

Of course not, the program never gets to

if (document.protocol == 'file:') {
  alert(document.protocol)
  mimeType = document.contentType;
} else {
  mimeType =
    request
    .getResponseHeader('Content-Type');
}