hellow :3, it me again, your favorite femboy dev with another (def) banger, now introducin YTSTAB or Your Typical Scramjet Ad Blocker, its just an ad blocker mod for Scramjet v1.1.0, we will add v2 version eventually when i have time not working with Lunar OS. its also on npm now btw, as @crateredlabs/ytstab. if you want anything added, tell me in the official Cratered Labs Discord Server. (Update, YOU CAN INSTALL YTSTAB AS A NPM PACKAGE, CHECK INSTRUCTIONS.md
YTSTAB is a single-file Scramjet Ad Blocker Mod, thats it, it blocks 200+ domains, split into categories now so u can turn specific ones off/on instead of all or nothing.
- STAB fetches every request from the server SW usually gets
- Decodes the Scramjet URL into an actual URL it can reads
- Checks its hostname and sub-domain and matches it to a category in STAB's list
- If it matches AND that category is turned on, it gives the 204 Empty Response and never reaches the server
- if it doesn't match, or the category its in is turned off, it lets it though the wall and goes to the server and goes to your user
-
Copy the file into your project, wherever your Scramjet service worker is served from.
-
Match the prefix. Open the file and check the
PREFIXconstant near the top — it must match exactly theprefixyou passed into yourScramjetControlleron the client side:
const controller = new ScramjetController({ prefix: "/scramjet/service/" });-
Use the default codec. Make sure your
ScramjetControllerisn't passing a customcodecoption. This file decodes proxied URLs with plaindecodeURIComponent, matching Scramjet's default — a custom codec will break the decoding. -
Register it the way you'd register any Scramjet service worker, at the same scope as your prefix:
await navigator.serviceWorker.register("/scramjet.sw.js", { scope: "/scramjet/service/" });npm install @crateredlabs/ytstab
it wont just work after installing tho, npm just dumps the file in node_modules, u still gotta copy it into ur public folder and do steps 2-4 above. check INSTRUCTIONS.md in the package if u forget how.
STAB can also be turned off and on, whole thing or just one category, all through postMessage. state also actually sticks now (saved in IndexedDB) so it wont randomly reset when the browser kills the service worker in the background
turning it all on/off:
const reg = await navigator.serviceWorker.getRegistration("/scramjet/service/");
reg.active.postMessage({ type: "YTSTAB_SET", enabled: true }); // put false to turn it offturning off just one category:
reg.active.postMessage({ type: "YTSTAB_SET_CATEGORY", category: "ads", enabled: false });asking for current state (good for loadin ur settings page correctly instead of guessin):
reg.active.postMessage({ type: "YTSTAB_GET_STATE" });listening for state + blocked hits:
navigator.serviceWorker.addEventListener("message", (e) => {
if (e.data?.type === "YTSTAB_STATE") {
console.log("current state:", e.data.on, e.data.categories, e.data.categoryList);
}
if (e.data?.type === "YTSTAB_HIT") {
console.log("blocked:", e.data.url, "category:", e.data.category);
}
});all of this is needed or YTSTAB will be ass for your users
go to scramjet.sw.js (aka the single file) and find const CATEGORIES, its an array of category objects like this:
{
id: "ads", label: "Ads",
domains: [ "adzerk.com", "adroll.com", ... ],
}just add/remove domains inside whichever category's domains array, or make a whole new category object if it doesnt fit existing ones. follow the format and it wont break.
- STAB only blocks stuff going through your Scramjet proxy's prefix, it doesn't touch your site's own direct asset loads, thats on purpose, its not meant to be a full site-wide ad blocker, just a proxy one
- Right now STAB can't tell the difference between navigatin straight to a blocked domain vs a blocked subresource, so if u go directly to one you'll just get a blank page instead of somethin that actually tells you its blocked, contributions welcome here if anyone wants to fix that
If you want v2 beta version, idk dm me to do it or you merk me. :3 anyways, if you are using YTSTAB, thank you. >:D Plentfy, Femboy Dev and Owner of YTSTAB