Skip to content

Commit 27dbdbb

Browse files
authored
2.1 update
1 parent c81fca0 commit 27dbdbb

File tree

1 file changed

+63
-23
lines changed

1 file changed

+63
-23
lines changed

Weave/BrowserView.swift

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ struct BrowserView: View {
6161
WebView(webView: webView, pageTitle: $pageTitle, URLString: $URLString, faviconImage: $faviconImage, userAgent: $userAgent)
6262
// Everything to load at app start
6363
.onAppear {
64-
// Preparing accent color variables
64+
// Sets accent color variables to use in CSS
6565
let sysAccent = NSColor.systemAccentColor.hexString
6666
let sysAccentDim = NSColor.systemAccentColor.blended(withFraction: 1.4, of: .black)!.hexString
6767
let sysAccentBright = NSColor.systemAccentColor.blended(withFraction: 0.4, of: .white)!.hexString
68-
// CSS Stylesheet injection
68+
// CSS Stylesheet injection for text and color styling
6969
let styleSheet = """
7070
var style = document.createElement('style');
7171
style.innerHTML = `
@@ -74,49 +74,89 @@ struct BrowserView: View {
7474
letter-spacing: 0px !important;
7575
}
7676
77-
button, input[type="button"], input[type="submit"] {
78-
background-color:\(sysAccent);
79-
}
80-
8177
a {
8278
color:\(sysAccent);
83-
text-decaration: none !important;
79+
text-decoration: none !important;
80+
text-decoration-color: \(sysAccent);
8481
transition: 0.25s !important;
82+
font-weight: 500;
8583
}
8684
8785
a:visited {
86+
text-decoration: none !important;
87+
text-decoration-color: \(sysAccentDim);
8888
color:\(sysAccentDim);
89+
transition: 0.25s !important;
8990
}
9091
9192
a:link {
92-
text-decaration: none !important;
93+
text-decoration: none !important;
94+
transition: 0.25s !important;
9395
}
9496
95-
a:hover {
96-
text-decaration: underline !important;
97+
a:hover, a:active {
98+
text-decoration: none !important;
99+
text-decoration-color: \(sysAccentBright);
97100
color: \(sysAccentBright);
98101
transition: 0.25s !important;
102+
font-weight: 600;
103+
}
104+
105+
button, input[type="button"], input[type="submit"] {
106+
font-weight: 500;
107+
transition: 0.25s !important;
108+
}
109+
110+
button:hover, input[type="button"]:hover, input[type="submit"]:hover {
111+
font-weight: 600;
112+
transition: 0.25s !important;
113+
}
114+
115+
h1 {
116+
font-weight: 800 !important;
117+
}
118+
119+
h2 {
120+
font-weight: 700 !important;
121+
}
122+
123+
h3, h4, h5, h6 {
124+
font-weight: 600 !important;
125+
}
126+
127+
sub {
128+
font-weight: 300 !important;
99129
}
100130
`;
101131
document.head.appendChild(style);
102132
"""
103133

104-
// Extremely basic CSS Adblock Injection
134+
// Injecting a simple adblocker with CSS and JS, a bit more advanced than the old one.
105135
let adBlockerScript = """
106-
var adBlockStyle = document.createElement('style');
107-
adBlockStyle.innerHTML = `
108-
/* Hide common ad classes */
109-
.ad-banner, .ad-wrapper, .ad-container, .ad, .ads, .adsense, .adslot, .ad-badge {
110-
display: none !important;
111-
}
136+
function findAdsInDocument() {
137+
const adIDs = ["Ad","RadAd","bbccom","hbBHeaderSpon","hiddenHeaderSpon","navbar_adcode","pagelet_adbox","rightAds","rightcolumn_adcode","tracker_advertorial","adbrite","dclkAds","konaLayer","a.kLink span[id^='preLoadWrap'][class='preLoadWrap']","div[id='tooltipbox'][class^='itxt']","div[id='google_ads_div']","embed[flashvars*='AdID']","iframe[src*='clicksor.com']","img[src*='clicksor.com']","ispan#ab_pointer","#A9AdsMiddleBoxTop","#A9AdsOutOfStockWidgetTop","#A9AdsServicesWidgetTop","#Ad2","#Ad3Left","#Ad3Right","#AdBar1","#AdContainerTop","#AdHeader","#AdRectangle","#AdShowcase_F1","#AdSky23","#AdSkyscraper","#AdSponsor_SF","#AdTargetControl1_iframe","#Ad_Block","#Ad_Center1","#Ad_Top","#Adrectangle","#AdsContent","#AdsWrap","#AdvertMPU23b","#Advertorial","#BannerAdvert","#BigBoxAd","#CompanyDetailsNarrowGoogleAdsPresentationControl","#CompanyDetailsWideGoogleAdsPresentationControl","#ContentAd","#ContentAd1","#ContentAd2","#FP_Ad","#FooterAd","#FooterAdContainer","#HEADERAD","#HeaderAdsBlock","#HeroAd","#HomeAd1","#HouseAd","#Journal_Ad_125","#Journal_Ad_300","#LeftAdF1","#LeftAdF2","#PageLeaderAd","#RightSponsoredAd","#SectionAd300-250","#SidebarAdContainer","#SkyAd","#SponsoredAd","#TOP_ADROW","#TopAdPos","#VM-MPU-adspace","#VM-header-adwrap","#XEadLeaderboard","#XEadSkyscraper","#ad-160x600","#ad-250x300","#ad-300x250","#ad-300x250Div","#ad-728","#ad-banner","#ad-bottom","#ad-bottom-wrapper","#ad-footer","#ad-footprint-160x600","#ad-front-footer","#ad-front-sponsoredlinks","#ad-halfpage","#ad-label","#ad-leaderboard","#ad-leaderboard-bottom","#ad-leaderboard-top","#ad-left","#ad-lrec","#ad-medium-rectangle","#ad-middlethree","#ad-middletwo","#ad-module","#ad-mpu","#ad-placard","#ad-rectangle","#ad-righttop","#ad-side-text","#ad-skyscraper","#ad-space","#ad-splash","#ad-target","#ad-teaser","#ad-top","#ad-tower","#ad-typ1","#ad-wrap-right","#ad-wrapper1","#ad-yahoo-simple","#ad125BL","#ad125BR","#ad125TL","#ad125TR","#ad125x125","#ad160x600","#ad160x600right","#ad1Sp","#ad2Sp","#ad3","#ad300","#ad300-250","#ad300X250","#ad300x150","#ad300x250","#ad300x250Module","#ad300x60","#ad336","#ad375x85","#ad526x250","#ad600","#ad7","#ad728Wrapper","#adB","#adBadges","#adBanner120x600","#adBannerTable","#adBannerTop","#adBar","#adBlock125","#adBlocks","#adFps","#adFrame","#adHCM","#adHeader","#adHov01","#adHov02","#adHov03","#adHov04","#adHov05","#adImg","#adKona","#adLREC","#adLargeRectangle","#adLeaderboard","#adMPU","#adMRec","#adNewsRight1","#adNewsRight2","#adNewsRight3","#adRectangle","#adResult2","#adRight","#adSky","#adSky3"];
112138
113-
/* Hide ads from specific URLs */
114-
[href*="doubleclick.net"], [href*="googleadservices.com"], [href*="advertising.com"], [src*="adserver.com"] {
115-
display: none !important;
116-
}
117-
`;
118-
document.head.appendChild(adBlockStyle);
139+
const allElements = [...document.querySelectorAll('*')];
140+
const adElements = allElements.filter(element => {
141+
const id = element.id || '';
142+
const classes = element.className || '';
143+
return adIDs.some(adID => {
144+
const regex = new RegExp(`(^|\\s)${adID}(\\s|$)`, 'i');
145+
return regex.test(id) || regex.test(classes);
146+
});
147+
});
148+
149+
const css = adElements.map(element => `#${element.id} { display: none !important; }`).join('\n');
150+
151+
const style = document.createElement('style');
152+
style.type = 'text/css';
153+
style.appendChild(document.createTextNode(css));
154+
155+
document.head.appendChild(style);
156+
}
119157
"""
158+
159+
// Actually injects scripts into webview
120160
let adBlockInject = WKUserScript(source: adBlockerScript, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
121161
webView.configuration.userContentController.addUserScript(adBlockInject)
122162

0 commit comments

Comments
 (0)