Filter Lists local content and/or archive?

Everything about using Adblock Plus on Mozilla Firefox, Thunderbird and SeaMonkey
Post Reply
microshnik
Posts: 5
Joined: Tue Dec 13, 2022 3:53 pm

Filter Lists local content and/or archive?

Post by microshnik »

Getting ahead of myself for a moment, I'm posting because of an issue on eBay that started a few days ago and I managed to track down to the "EasyList" from https://easylist.to. I will contact that author about this too if necessary, but for right now...

I'm looking for a way to see the current content of the filters from a subscription on my local machine, *not* the most recent version from the author. I use multiple FF profiles and not all of them auto-update the filter lists, so if I could extract the various versions from the profiles and diff them, I might actually be able to tell the author precisely which rules are the problem.

If such extraction isn't possible, does there exist an archive of old versions of these filter lists? I suppose that would be up to each author to host, but if anyone could tell me where to find it, that would be the next best thing.

Thanks in advance for any info!
microshnik
Posts: 5
Joined: Tue Dec 13, 2022 3:53 pm

Re: Filter Lists local content and/or archive?

Post by microshnik »

Things I forgot:
  • I'm using Firefox 102.5.0esr with ABP version 3.14.2. I'm very leery of updating at this point, but if the feature I need is there, let me know!
  • I already tried this export method but the returned 'settings' object is empty.
User avatar
greiner
ABP Developer
Posts: 899
Joined: Mon Sep 03, 2012 5:29 pm
Location: Cologne, Germany

Re: Filter Lists local content and/or archive?

Post by greiner »

It's true that the way filters are stored has indeed change recently, in order to make the storage and retrieval more performant. Here are some updated instructions that I came up with based on the current Adblock Plus code, to retrieve the file that contains all of the filter lists and filters that Adblock Plus stores:

1. Open the settings page.
2. Open the JavaScript console (e.g. via the Firefox menu: More tools > Web Developer Tools > Console).
3. Enter the following code and press "Enter" to retrieve the file contents.

Code: Select all

data = await (async() => {
  let data = await new Promise((resolve, reject) => {
    indexedDB.open("EWE").onsuccess = dbEvent => {
      let db = dbEvent.target.result;
      let tx = db.transaction(["file-entries", "file-contents"], "readonly");
      let entryStore = tx.objectStore("file-entries");
      let contentStore = tx.objectStore("file-contents");

      entryStore.get("patterns.ini").onsuccess = entryEvent => {
        let entry = entryEvent.target.result;
        contentStore.get(entry.content).onsuccess = contentEvent => {
          resolve(contentEvent.target.result);
        };
      };
    };
  });
  let decoder = new TextDecoder();
  let start = 0;

  let content = [];

  while (true) {
    let index = data.indexOf(10 /* newline character */, start + 1000);
    let end = index != -1 ? index : data.length;
    let text = decoder.decode(data.subarray(start, end));

    content.push(text);

    if (index == -1)
      break;

    start = index + 1;
  }

  return content.join("");
})();
4. Enter the following code and press "Enter" to copy the file contents into your clipboard.

Code: Select all

copy(data);
5. Paste the file contents into a text file.

Source: https://gitlab.com/eyeo/adblockplus/abc ... idb.js#L69

Note that this method doesn't apply to Firefox when using Private Browsing Mode. There, Adblock Plus should still use the previous storage method.
microshnik wrote: Tue Dec 13, 2022 4:13 pm If such extraction isn't possible, does there exist an archive of old versions of these filter lists? I suppose that would be up to each author to host, but if anyone could tell me where to find it, that would be the next best thing.
It depends on the individual filter list authors. For example, EasyList publishes the source code from which the various EasyList filter lists are generated on GitHub, so you can find them at https://github.com/easylist, where you can browse its history and generate the lists from specific points in time.
microshnik
Posts: 5
Joined: Tue Dec 13, 2022 3:53 pm

Re: Filter Lists local content and/or archive?

Post by microshnik »

THANK YOU! This is OUTSTANDING! It gave me what I needed... after a tiny bug fix. ;) There's a fencepost error because the second argument to TypedArray.subarray is exclusive. Here's the diff:

Code: Select all

--- abp-export-orig.js	2022-12-14 19:44:26.458943600 -0500
+++ abp-export-final.js	2022-12-14 19:44:20.048831600 -0500
@@ -23,3 +23,3 @@
     let index = data.indexOf(10 /* newline character */, start + 1000);
-    let end = index != -1 ? index : data.length;
+    let end = index != -1 ? (index + 1) : data.length;
     let text = decoder.decode(data.subarray(start, end));
@@ -31,3 +31,3 @@
 
-    start = index + 1;
+    start = end;
   }
and the final product:

Code: Select all

data = await (async() => {
  let data = await new Promise((resolve, reject) => {
    indexedDB.open("EWE").onsuccess = dbEvent => {
      let db = dbEvent.target.result;
      let tx = db.transaction(["file-entries", "file-contents"], "readonly");
      let entryStore = tx.objectStore("file-entries");
      let contentStore = tx.objectStore("file-contents");

      entryStore.get("patterns.ini").onsuccess = entryEvent => {
        let entry = entryEvent.target.result;
        contentStore.get(entry.content).onsuccess = contentEvent => {
          resolve(contentEvent.target.result);
        };
      };
    };
  });
  let decoder = new TextDecoder();
  let start = 0;

  let content = [];

  while (true) {
    let index = data.indexOf(10 /* newline character */, start + 1000);
    let end = index != -1 ? (index + 1) : data.length;
    let text = decoder.decode(data.subarray(start, end));

    content.push(text);

    if (index == -1)
      break;

    start = end;
  }

  return content.join("");
})();
I can't thank you enough for such a quick and thorough reply; it would have taken me days if not weeks to find the relevant code!
Happy holidays! :D
User avatar
greiner
ABP Developer
Posts: 899
Joined: Mon Sep 03, 2012 5:29 pm
Location: Cologne, Germany

Re: Filter Lists local content and/or archive?

Post by greiner »

Glad to hear that it worked and thanks for the tip, I'll forward it to the other developers.

Happy holidays to you too!
Post Reply