Last active
August 23, 2024 03:07
-
-
Save kebien6020/6e709478155f41901a2f2bd7197f78bd to your computer and use it in GitHub Desktop.
Sankaku ads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Sankaku ads | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.16 | |
| // @description Auto close sankaku ads | |
| // @author Baku | |
| // @match https://beta.sankakucomplex.com/* | |
| // @match https://www.sankakucomplex.com/* | |
| // @match https://sankaku.app/* | |
| // @updateURL https://gist.github.com/kebien6020/6e709478155f41901a2f2bd7197f78bd/raw/sankaku-ads.user.js | |
| // @downloadURL https://gist.github.com/kebien6020/6e709478155f41901a2f2bd7197f78bd/raw/sankaku-ads.user.js | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const onAttributeChanged = () => { | |
| clickCloseOnAdsPopup() | |
| removeHideAdsInSearch() | |
| removeUpgradeInSearch() | |
| removeRecommendedSeriesInSearch() | |
| removeAiThingyInSearch() | |
| removeNonPostsMixedWithPostsInSearch() | |
| removeRecommendedSeriesInPost() | |
| removeAiThingyInPost() | |
| removeAiThingyInPostOnVideos() | |
| clickNotYet() | |
| // removeAntiAdBlock() // Disabled because it's now hiding the filter dialog | |
| clickRequestLimitNotNow() | |
| removeCompanionFloatingButton() | |
| restoreClickThroughTooltips() | |
| } | |
| setInterval(onAttributeChanged, 200) | |
| const clickCloseOnAdsPopup = () => { | |
| const hideAdsButton = [...document.querySelectorAll('.MuiDialog-root .MuiButton-root')].find(containsText('hide ads')) | |
| if (!hideAdsButton) return | |
| const hideAdsBox = up(5, hideAdsButton) | |
| const hideAdsClose = hideAdsBox.querySelector('button[aria-label=close]') | |
| if (!hideAdsClose) return | |
| console.log('clicking the close button on hide ads popup') | |
| hideAdsClose.click() | |
| } | |
| const removeHideAdsInSearch = () => { | |
| if (!inSearchPage()) return | |
| const hideAdsLink = adLinks().find(and(containsText('hide ads'), boxWidth100)) | |
| const hideAdsBox = findBox(hideAdsLink) | |
| if (!hideAdsBox || hideAdsBox.style.display === 'none') return | |
| const boxParent = hideAdsBox.parentElement | |
| console.log('removing hide ads in search', hideAdsBox) | |
| hideAdsBox.style.display = 'none' | |
| //boxParent.style.marginTop = '-250px' | |
| } | |
| const adLinks = () => [...document.querySelectorAll('a[href*="get.sankaku.plus"]')] | |
| const and = (fn1, fn2) => val => fn1(val) && fn2(val) | |
| const or = (fn1, fn2) => val => fn1(val) || fn2(val) | |
| const width100 = elem => getComputedStyle(elem).width === getComputedStyle(elem.parentElement).width | |
| const boxWidth100 = elem => width100(findBox(elem)) | |
| const findBox = linkElem => { | |
| let box = linkElem | |
| box = box?.parentElement | |
| box = box?.parentElement | |
| box = box?.parentElement | |
| box = box?.parentElement | |
| return box | |
| } | |
| const removeUpgradeInSearch = () => { | |
| if (!inSearchPage()) return | |
| const badTxtElem = [...document.querySelectorAll('p'), ...document.querySelectorAll('span')].find(containsText('upgrade to sankaku plus')) | |
| const badBox = up(1, badTxtElem) | |
| const closeBtn = badBox?.querySelector('button') | |
| if (!closeBtn || !closeBtn.querySelector('svg')) return | |
| console.log('hiding upgrade in search', closeBtn) | |
| closeBtn.click() | |
| } | |
| const removeRecommendedSeriesInSearch = () => { | |
| if (!inSearchPage()) return | |
| const badTxtElem = h3s().find(containsText('recommended series')) | |
| const badBox = up(2, badTxtElem) | |
| if (!badBox || badBox.style.display === 'none') return | |
| console.log('hiding recommended series in search', badBox) | |
| badBox.style.display = 'none' | |
| } | |
| const inSearchPage = () => window.location.pathname === '/' | |
| const h3s = () => [...document.querySelectorAll('h3')] | |
| const containsText = txt => elem => elem.textContent.toLowerCase().includes(txt) | |
| const up = (n, elem) => { | |
| let res = elem | |
| for (let i = 0; i < n; ++i) res = res?.parentElement | |
| return res | |
| } | |
| const removeAiThingyInSearch = () => { | |
| if (!inSearchPage()) return | |
| const badTxtElem = [...document.querySelectorAll('p')] | |
| .find(or(containsText('artificial intelligence'), containsText('ai art'))) | |
| const badBox = up(5, badTxtElem) | |
| if (!badBox || badBox.style.display === 'none') return | |
| console.log('hiding AI thingy in search', badBox) | |
| badBox.style.display = 'none' | |
| } | |
| const removeNonPostsMixedWithPostsInSearch = () => { | |
| if (!inSearchPage()) return | |
| const postSelector = '[data-test=post-card]' | |
| const post = document.querySelector(postSelector) | |
| if (!post) return // still loading | |
| const postsParent = up(1, post) | |
| const nonPosts = [...postsParent.children].filter(el => !el.matches(postSelector)) | |
| for (const bad of nonPosts) { | |
| if (bad.style.display === 'none') continue | |
| console.log('hiding non-post mixed with posts') | |
| bad.style.display = 'none' | |
| } | |
| } | |
| const removeAiThingyInPost = () => { | |
| if (!inPostPage()) return | |
| const badTxtElem = [...document.querySelectorAll('button')] | |
| .find(or(containsText('create ai art'), containsText('transform this post'))) | |
| const badBox = up(1, badTxtElem) | |
| if (!badBox || badBox.style.display === 'none') return | |
| console.log('hiding AI thingy in post', badBox) | |
| badBox.style.display = 'none' | |
| } | |
| const removeAiThingyInPostOnVideos = () => { | |
| if (!inPostPage()) return | |
| const badTxtElem = [...document.querySelectorAll('p')] | |
| .find(containsText('make new art with this')) | |
| const badBox = up(2, badTxtElem) | |
| if (!badBox || badBox.style.display === 'none') return | |
| console.log('hiding AI thingy in post (videos)', badBox) | |
| badBox.style.display = 'none' | |
| } | |
| const removeRecommendedSeriesInPost = () => { | |
| if (!inPostPage()) return | |
| const badTxtElem = adLinks2().find(containsText('view all')) | |
| const badBox = up(6, badTxtElem) | |
| if (!badBox || badBox.style.display === 'none') return | |
| console.log('hiding recommended series in post', badBox) | |
| badBox.style.display = 'none' | |
| } | |
| const inPostPage = () => { | |
| const path = window.location.pathname | |
| return path.startsWith('/post/show/') || path.startsWith('/posts/') | |
| } | |
| const adLinks2 = () => [...document.querySelectorAll('a[href*="plus.sankakucomplex.com"]')] | |
| const clickNotYet = () => { | |
| if (!inSearchPage()) return | |
| const notYetBtn = [...document.querySelectorAll('button.MuiButtonBase-root')].find(containsNotYet) | |
| if (!notYetBtn) return | |
| console.log('clicking not yet') | |
| notYetBtn.click() | |
| } | |
| const containsNotYet = elem => elem.textContent.toLowerCase().includes('continue browsing') | |
| const removeAntiAdBlock = () => { | |
| const dialog = [...document.querySelectorAll('.MuiDialog-root')].find(el => el.style?.zIndex === '1301') | |
| if (!dialog) return | |
| if (dialog.style.display === 'none' && document.body.style.overflow === '') return | |
| console.log('hiding anti-adblock') | |
| dialog.style.display = 'none' | |
| document.body.style.overflow = '' | |
| } | |
| const clickRequestLimitNotNow = () => { | |
| const btn = [...document.querySelectorAll('.MuiSnackbar-root button')].find(containsText('not now')) | |
| if (!btn) return | |
| console.log('clicking not now') | |
| btn.click() | |
| } | |
| const removeCompanionFloatingButton = () => { | |
| const box = document.querySelector('.react-draggable:has(img[src$="Ii8+Cjwvc3ZnPgo="])') // Last few characters from the base64 heart shape | |
| if (!box || box.style.display === 'none') return | |
| console.log('hiding floating companion button') | |
| box.style.display = 'none' | |
| } | |
| const restoreClickThroughTooltips = () => { | |
| const id = 'kev-restore' | |
| if (document.querySelector(`style#${id}`)) return | |
| console.log('injecting styles for click-through tooltips') | |
| const style = document.createElement('style') | |
| style.id = id | |
| style.textContent = ` | |
| .MuiTooltip-popperInteractive { | |
| pointer-events: none !important; | |
| } | |
| ` | |
| document.head.appendChild(style) | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment