JustOff / github-wc-polyfill

Ensure that all GitHub and GitLab scripts required for UXP and SeaMonkey are loaded correctly
https://justoff.github.io
Mozilla Public License 2.0
103 stars 19 forks source link

"Copy the full SHA" no longer works... #49

Closed Vangelis66 closed 2 years ago

Vangelis66 commented 2 years ago

Platform: (forked) UXP Browser: (latest) Serpent 52.9.0 (2022-02-25) (32-bit) Extension version: 1.2.14b2 Browser profile: Fresh (with default settings), with only this extension installed

STR:

  1. Visit/load e.g. :

https://github.com/JustOff/github-wc-polyfill/commits/master

  1. Move cursor to the "Copy the full SHA" button of top commit,

CopySHA

, click button

  1. Expected behaviour: Full (40 chars) commit HASH copied to the clipboard (with a visual indication of a successful copy action)

  2. Actual result: Clipboard is empty (or contains whatever string was put there, via whatever, immediately previous, copy action)...

  3. In contrast, on a Chromium-based browser sanctioned by GitHub, this is the visual result of clicking the button in question:

CopySHA2

and the clipboard becomes populated with 1291c0573ddaa116c48386110ffe5c6a4fe751a3 ... Nothing I could spot stands out in Web/Error Console... :disappointed:

dirkf commented 2 years ago

Confirm in SM 2.5.10.2.

SeaHOH commented 2 years ago

~EventTarget.addEventListener failed on Custom Elements polyfill.~ It's working in current page. :confused: Maybe click events have been intercepted by button tag.

This code is working. click events triggered by parent button.

(function () {
  function addEventListener (type, listener, options) {
    const target = this, parent = target.parentNode,
          ael = EventTarget.prototype.addEventListener;
    ael.call(target, type, listener, options);
    // Limit applied scope, or break other functions
    if (!(type === "click" && parent.localName === "button")) return;
    if (!triggerMap.has(target))
      triggerMap.set(target, function () {target.dispatchEvent(new Event("click"))});
    ael.call(parent, type, triggerMap.get(target), options);
  }
  function removeEventListener (type, listener, options) {
    const target = this, parent = target.parentNode,
          rel = EventTarget.prototype.removeEventListener;
    rel.call(target, type, listener, options);
    if (!(type === "click" && parent.localName === "button")) return;
    rel.call(parent, type, triggerMap.get(target), options);
  }
  const oldCED = customElements.define, triggerMap = new Map();
  customElements.define = function (name, cls) {
    cls.prototype.addEventListener = addEventListener;
    cls.prototype.removeEventListener = removeEventListener;
    oldCED.call(customElements, name, cls);
  };
}());
Vangelis66 commented 2 years ago

I tested the latest snapshot, c2f2c72, of your fork and it does address successfully this issue, thanks 👍 , but... Can you please submit a proper PR for this here, that can cleanly apply on top of master branch (or a "patch" on top of latest beta, 1.2.14b2) ? (FWIW, you were kindly invited to do the same for another of your "fixes", but so far you seem reluctant to indulge... ). Using a UXP-based browser myself, I have the "luxury" of being able to try your own fork, but this original extension does also cater to SeaMonkey users, which are NOT covered, AFAICS, by your fork...

Kindest regards 😄

SeaHOH commented 2 years ago

I will tell you how to patch github-wc-polyfill, so I spend some time on writing digest tool.

Click here to expand and see tool's UI ![digest tool](https://user-images.githubusercontent.com/8470820/156357540-5610a95c-e044-443a-ab01-578216dfc5fb.png)

First, copy this html tool to your disk, named e.g. digest.html, then load it with your browser.

Click here to expand and copy ```html Get strings digest integrity

Input Strings

Output Digest Integrity

-

Output Wrapped Strings

```

Paste the script who will be injected, into input text area, then you can click buttons to copy the following needed values.

+++const pfFollowUp = WRAPPED STRINGS;
+++const hashFollowUp = "'DIGEST INTEGRITY'";

Add hashFollowUp digest integrity.

---              csp = csp.replace(/script-src /g, "script-src " + hashBase + " ");
+++              csp = csp.replace(/script-src /g, "script-src " + hashBase + " " + hashFollowUp + " ");

Inject pfFollowUp at first position, in result it's the last.

      if (this.site == "github") {
+++        data = data.replace("<head>", "<head><script>" + pfFollowUp + "</script>");

Remove unnecessary e.g.

---        data = data.replace(/<script.+chunk-index2-[a-z0-9]+\.js"><\/script>/, "......");
AroKol78 commented 2 years ago

it already works for me (Serpent52 + 1.2.15b1)


it's OK (Serpent52 + 1.2.15b3)