qutebrowser: greasemonkey: Scripts for youtube & reddit adblock

Taken from
https://github.com/afreakk/greasemonkeyscripts
This commit is contained in:
Sanchayan Maity 2023-03-06 16:11:01 +05:30
parent c25d97166f
commit 9bc237314f
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3
4 changed files with 94 additions and 20 deletions

View file

@ -0,0 +1,18 @@
// ==UserScript==
// @name remove ads from reddit
// @version 1.0.0
// @author afreakk
// @match *://*.reddit.com/*
// ==/UserScript==
const removeShit = () => {
// promoted posts has this class
document.querySelectorAll('.promotedlink').forEach((e) => e.remove());
// nagging about confirming email has this class
document
.querySelectorAll('.kEQVd8aneM1tVkcIKUyDT')
.forEach((e) => e.remove());
};
(trySetInterval = () => {
window.setInterval(removeShit, 1000);
})();

View file

@ -1,20 +0,0 @@
// ==UserScript==
// https://www.reddit.com/r/qutebrowser/comments/u05nix/skipping_youtube_ads/
// https://www.reddit.com/r/qutebrowser/comments/tue1gs/blocking_youtube_ads/
// u/name Auto Skip YouTube Ads
// u/version 1.0.0
// u/description Speed up and skip YouTube ads automatically
// u/author jso8910
// u/match *://*.youtube.com/*
// u/exclude *://*.youtube.com/subscribe_embed?*
// ==/UserScript==
const btn = document.querySelector('.videoAdUiSkipButton,.ytp-ad-skip-button')
if (btn) {
btn.click()
}
const ad = [...document.querySelectorAll('.ad-showing')][0];
if (ad) {
const vid = document.querySelector('video');
vid.currentTime = vid.duration;
}

View file

@ -0,0 +1,35 @@
// ==UserScript==
// @name Skip youtube ads
// @version 1.0.0
// @description Skips YouTube ads automatically
// @author afreakk
// @match *://*.youtube.com/*
// @exclude *://*.youtube.com/subscribe_embed?*
// ==/UserScript==
const skipAd = () => {
document
.querySelectorAll('.videoAdUiSkipButton,.ytp-ad-skip-button')
.forEach((b) => b.click());
if (document.querySelector('.ad-showing')) {
document.querySelectorAll('video').forEach((v) => {
Number.isNaN(v.duration) || (v.currentTime = v.duration);
});
}
document
.querySelectorAll('.ytd-display-ad-renderer#dismissible')
.forEach((el) =>
// remove the ad video in top left of recommended
el?.parentElement?.parentElement?.parentElement?.remove?.()
);
document
.querySelectorAll(
'ytd-promoted-sparkles-web-renderer, #player-ads, #masthead-ad, ytd-compact-promoted-video-renderer'
)
.forEach((el) => el.remove());
document
.querySelectorAll('.ytd-mealbar-promo-renderer#dismiss-button')
.forEach((el) => el.click());
};
if (!window.skipAdIntervalID) {
window.skipAdIntervalID = setInterval(skipAd, 333);
}

View file

@ -0,0 +1,41 @@
// ==UserScript==
// @name Sponsorblock
// @version 1.0.0
// @description Skip sponsor segments automatically
// @author afreakk
// @match *://*.youtube.com/*
// @exclude *://*.youtube.com/subscribe_embed?*
// ==/UserScript==
const tryFetchSkipSegments = (videoID) =>
fetch(`https://sponsor.ajay.app/api/skipSegments?videoID=${videoID}`)
.then((r) => r.json())
.then((rJson) =>
rJson.filter((a) => a.actionType === 'skip').map((a) => a.segment)
)
.catch(
(e) =>
console.log(
`Sponsorblock: failed fetching skipSegments for ${videoID}, reason: ${e}`
) || []
);
const skipSegments = async () => {
const videoID = new URL(document.location).searchParams.get('v');
if (!videoID) {
return;
}
const key = `segmentsToSkip-${videoID}`;
window[key] = window[key] || (await tryFetchSkipSegments(videoID));
for (const v of document.querySelectorAll('video')) {
if (Number.isNaN(v.duration)) continue;
for (const [start, end] of window[key]) {
if (v.currentTime < end && v.currentTime > start) {
v.currentTime = end;
return console.log(`Sponsorblock: skipped video to ${end}`);
}
}
}
};
if (!window.skipSegmentsIntervalID) {
window.skipSegmentsIntervalID = setInterval(skipSegments, 1000);
}