mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-22 18:15:47 +02:00
Add response filter to restore global jQuery & unfreeze TweetDeck resources
This commit is contained in:
parent
77bc922d93
commit
0f41cb9dbc
20
Core/Handling/Filters/ResponseFilterVendor.cs
Normal file
20
Core/Handling/Filters/ResponseFilterVendor.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TweetDuck.Core.Handling.Filters{
|
||||
sealed class ResponseFilterVendor : ResponseFilterBase{
|
||||
private static readonly Regex RegexRestoreJQuery = new Regex(@"(\w+)\.fn=\1\.prototype", RegexOptions.Compiled);
|
||||
|
||||
public ResponseFilterVendor(int totalBytes) : base(totalBytes, Encoding.UTF8){}
|
||||
|
||||
public override bool InitFilter(){
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override string ProcessResponse(string text){
|
||||
return RegexRestoreJQuery.Replace(text, "window.$$=$1;$&", 1);
|
||||
}
|
||||
|
||||
public override void Dispose(){}
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
// Uncomment to force TweetDeck to load a predefined version of the vendor/bundle scripts
|
||||
#define FREEZE_TWEETDECK_SCRIPTS // TODO delaying the apocalypse
|
||||
// #define FREEZE_TWEETDECK_SCRIPTS
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Specialized;
|
||||
using CefSharp;
|
||||
using TweetDuck.Core.Handling.Filters;
|
||||
using TweetDuck.Core.Utils;
|
||||
|
||||
#if FREEZE_TWEETDECK_SCRIPTS
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
#endif
|
||||
|
||||
namespace TweetDuck.Core.Handling{
|
||||
@ -55,10 +56,10 @@ public override bool OnResourceResponse(IWebBrowser browserControl, IBrowser bro
|
||||
|
||||
if (match.Success && TweetDeckHashes.TryGetValue(match.Groups[1].Value, out string hash)){
|
||||
if (match.Groups[2].Value == hash){
|
||||
Debug.WriteLine($"accepting {request.Url}");
|
||||
System.Diagnostics.Debug.WriteLine($"accepting {request.Url}");
|
||||
}
|
||||
else{
|
||||
Debug.WriteLine($"rewriting {request.Url} to {hash}");
|
||||
System.Diagnostics.Debug.WriteLine($"rewriting {request.Url} to {hash}");
|
||||
request.Url = TweetDeckScriptUrl.Replace(request.Url, "dist/$1."+hash+".js");
|
||||
return true;
|
||||
}
|
||||
@ -68,5 +69,28 @@ public override bool OnResourceResponse(IWebBrowser browserControl, IBrowser bro
|
||||
|
||||
return base.OnResourceResponse(browserControl, browser, frame, request, response);
|
||||
}
|
||||
|
||||
public override IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response){
|
||||
if (request.ResourceType == ResourceType.Script && request.Url.Contains("dist/vendor")){
|
||||
NameValueCollection headers = response.ResponseHeaders;
|
||||
|
||||
if (int.TryParse(headers["x-ton-expected-size"], out int totalBytes)){
|
||||
return new ResponseFilterVendor(totalBytes);
|
||||
}
|
||||
#if DEBUG
|
||||
else{
|
||||
System.Diagnostics.Debug.WriteLine($"Missing uncompressed size header in {request.Url}");
|
||||
|
||||
foreach(string key in headers){
|
||||
System.Diagnostics.Debug.WriteLine($" {key}: {headers[key]}");
|
||||
}
|
||||
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return base.GetResourceResponseFilter(browserControl, browser, frame, request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,7 @@
|
||||
<Compile Include="Core\Handling\ContextMenuGuide.cs" />
|
||||
<Compile Include="Core\Handling\DragHandlerBrowser.cs" />
|
||||
<Compile Include="Core\Handling\Filters\ResponseFilterBase.cs" />
|
||||
<Compile Include="Core\Handling\Filters\ResponseFilterVendor.cs" />
|
||||
<Compile Include="Core\Handling\General\BrowserProcessHandler.cs" />
|
||||
<Compile Include="Core\Handling\ContextMenuBase.cs" />
|
||||
<Compile Include="Core\Handling\ContextMenuBrowser.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user