Skip to content
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

Extend addEventListenerDefuser to support defusing based on the element #3061

Closed
9 tasks done
MasterKia opened this issue Jan 8, 2024 · 8 comments
Closed
9 tasks done
Labels
enhancement New feature or request fixed issue has been addressed

Comments

@MasterKia
Copy link
Member

MasterKia commented Jan 8, 2024

Prerequisites

  • I verified that this is not a filter list issue. Report any issues with filter lists or broken website functionality in the uAssets issue tracker.
  • This is NOT an issue with YouTube, Facebook or Twitch.
  • This is not a support issue or a question. For support, questions, or help, visit /r/uBlockOrigin.
  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue.
  • The issue is not present after disabling uBO in the browser.
  • I checked the documentation to understand that the issue I am reporting is not normal behavior.

I tried to reproduce the issue when...

  • uBO is the only extension.
  • uBO uses default lists and settings.
  • using a new, unmodified browser profile.

Description

Go to:
https://subkade.ir/%D8%AF%D8%A7%D9%86%D9%84%D9%88%D8%AF-%D8%B2%DB%8C%D8%B1%D9%86%D9%88%DB%8C%D8%B3-%D8%B3%D8%B1%DB%8C%D8%A7%D9%84-prison-break/

Click on "دانلود زیرنویس" (##a.indirect), you'll get another page where you have to click on "برای ادامه اینجا کلیک کنید" (##a.sk-dl), then you'll get a 6 seconds timer to download the subtitles.

The main download link looks like this:

<a data-get="https://dl1.subkade.ir/wp-content/uploads/2019/07/Prison-Break-S01-Complete.zip" target="_self" oncontextmenu="return false;" class="indirect">دانلود</a>

Add this to fix the link:

subkade.ir##+js(set-attr, a.indirect[data-get], href, [data-get])

The download link is still not working, because of the following "click" event listener:
image

Add this to fix it:

subkade.ir##+js(aeld, click, return"undefined")

The download link is working, but now the "زیرنویس انگلیسی" (##.lock.sk-download-list) section is broken because it used the same "click" event listener.

Solution:

// ==UserScript==
// @name        Subkade.ir
// @namespace   Violentmonkey Scripts
// @match       http://*.subkade.ir/*
// @match       https://*.subkade.ir/*
// @grant       none
// @author      PersianBlocker
// @run-at      document-start
// ==/UserScript==


(function() {
  'use strict';

  self.EventTarget.prototype.addEventListener = new Proxy(self.EventTarget.prototype.addEventListener, {
    apply(target, thisArg, args) {
      const node = thisArg;
      if (args[0] === 'click' && node.nodeName === 'A' && node.className && node.className === 'indirect') {
        if (args[1].toString().includes('return"undefined"') === true) {
          return;
        }
      };
      return Reflect.apply(target, thisArg, args);
    }
  })

}) ();

Maybe add a forth optional positional argument?

subkade.ir##+js(aeld, click, return"undefined", a.indirect)
@MasterKia
Copy link
Member Author

It's may also be useful in the annoyances list to be able to limit the scope of aeld to specific elements, where we currently have broad filters like this:

zippyupload.com##+js(aeld, contextmenu, preventDefault)
streamvid.net##+js(aeld, contextmenu)

@gwarser gwarser added the enhancement New feature or request label Jan 8, 2024
gorhill added a commit to gorhill/uBlock that referenced this issue Jan 10, 2024
If present, `elements` vararg must be a valid CSS selector, which will
be used to apply the scriptlet to only elements matching the
selector.

Related issue:
uBlockOrigin/uBlock-issues#3061

Example of usage:

[...]##+js(aeld, click, return"undefined", elements, a.indirect)
@MasterKia MasterKia added the fixed issue has been addressed label Jan 10, 2024
@MasterKia
Copy link
Member Author

Can uBO report the respective element when using the log vararg?

@D4niloMR
Copy link

D4niloMR commented Feb 12, 2024

Doesn't defuse the event listener here: https://comikey.com/read/that-inferior-knight-level-999-manga/DQYlaD/chapter-1-1/

comikey.com##+js(aeld, contextmenu, , elements, #br-book) doesn't work while manually disabling the event listener works.

Add to test (first one is to disable the filter in ublock-annoyances):

comikey.com#@#+js(aeld, contextmenu, undefined)
comikey.com##+js(aeld, contextmenu, undefined, elements, #br-book)

@gorhill

p.s: mentioning just in case you haven't received the notification.

@gorhill
Copy link
Member

gorhill commented Feb 14, 2024

Can uBO report the respective element when using the log vararg?

log vararg doesn't exist anymore. In the next dev build, selector information for the element on which addEventListener is called will be output in the logger, after the function text.

Doesn't defuse the event listener here

Many quirks which should be fixed in next dev build:

  • The handler can be an interface with a handleEvent property -- the scriptlet was not taking this into account
  • The element may not have been added to the DOM yet, this needs to be taken into account
  • Use the now logged selector to find out how to target a specific element -- in the current instance the target element's id was not set when addEventListener is called.

gorhill added a commit to gorhill/uBlock that referenced this issue Feb 14, 2024
@D4niloMR
Copy link

Can japscan.lol##+js(aeld, load, _0x, elements, window) be supported? I want to defuse load events of obfuscated code, but this also defuses the load event of a bunch of images.

gorhill added a commit to gorhill/uBlock that referenced this issue Jun 11, 2024
@gorhill
Copy link
Member

gorhill commented Jun 11, 2024

gorhill/uBlock@91ee5bd

@MasterKia
Copy link
Member Author

A wrong selector can break the scriptlet:

lenz.ir##+js(aeld, contextmenu, preventDefault, elements, ##div#rmpPlayer)
Uncaught DOMException: Element.matches: '##div#rmpPlayer' is not a valid selector
    elementMatches blob
    shouldPrevent blob
    apply blob

image

@garry-ut99
Copy link

Worth to add, that when the scriptlet gets broken by an invalid selector, the whole page gets broken, empty and black, at least with this example filter: lenz.ir##+js(aeld, click, a, elements, ##.signup-button.clickable): SCREENSHOOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed issue has been addressed
Projects
None yet
Development

No branches or pull requests

5 participants