Added a request handler. Changed the way you block sites. Disabled GPU acceleration and GPU vsync. Enabled webgl. Removed the rick roll blocking because I see it pointless.
94 lines
No EOL
4.6 KiB
C#
94 lines
No EOL
4.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Bunifu.UI.WinForms;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
|
|
|
|
namespace XeroBrowser
|
|
{
|
|
public class RequestHandler : CefSharp.Handler.RequestHandler
|
|
{
|
|
|
|
// Define arrays with domain names only
|
|
private readonly string[] blockedDrms = { "netflix.com", "www.netflix.com", "disneyplus.com", "twitch.tv", "tiktok.com" };
|
|
private readonly string[] incompatibleExtSites = { "chrome.google.com", "addons.mozilla.org", "chromewebstore.google.com" };
|
|
private string[] adDomains;
|
|
|
|
public RequestHandler()
|
|
{
|
|
// Fetch the blocked domains asynchronously when the RequestHandler is instantiated
|
|
FetchAdDomainsAsync().ContinueWith(t => adDomains = t.Result);
|
|
}
|
|
|
|
public async Task<string[]> FetchAdDomainsAsync()
|
|
{
|
|
string[] adDomains = Array.Empty<string>();
|
|
|
|
try
|
|
{
|
|
using (HttpClient client = new HttpClient())
|
|
{
|
|
string url = "https://diamondcreeper.org/web-filtering/lists/ads.txt";
|
|
HttpResponseMessage response = await client.GetAsync(url);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string content = await response.Content.ReadAsStringAsync();
|
|
string[] adsDomains = content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Error fetching ad domains: {ex.Message}");
|
|
}
|
|
|
|
return adDomains;
|
|
}
|
|
|
|
protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
|
|
{
|
|
Uri requestUri = new Uri(request.Url);
|
|
string domain = requestUri.Host.ToLower();
|
|
|
|
if (blockedDrms.Contains(domain))
|
|
{
|
|
// Cancel the navigation or sub-request
|
|
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Error!</h1> <h3>The requested site requires a DRM (Digital Rights Management) which Xero Browser does not support!</h3> </div> </body></html>");
|
|
|
|
// Clear the txtSearchOrUrl text box
|
|
//txtSearchOrUrl.Text = string.Empty;
|
|
}
|
|
else if (incompatibleExtSites.Contains(domain))
|
|
{
|
|
// Cancel the navigation or sub-request
|
|
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Error!</h1> <h3>Browser extensions are not supported!</h3> </div> </body></html>");
|
|
|
|
// Clear the txtSearchOrUrl text box
|
|
//txtSearchOrUrl.Text = string.Empty;
|
|
}
|
|
else if (adDomains.Contains(domain))
|
|
{
|
|
chromiumWebBrowser.LoadHtml("<html> <head> </head> <style> body{ background-color: rgb(214, 214, 214); } .center{ text-align: center; } .text{ margin-top: 20%; font-family: Arial; } div{ background-color: #f5f5f5; border-radius: 15px; width: 500px; margin-left: 35%; padding: 10px; } </style> <body class=\"center\"> <div class=\"text\"> <h1>Ads are blocked!</h1> <h3>Ads are blocked in xero browser</h3> </div> </body></html>");
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |