mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-02 11:34:08 +02:00
Add javascript injection with a bridge object to the website
This commit is contained in:
parent
6c53f10810
commit
d7a0f577d6
@ -4,6 +4,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using TweetDick.Configuration;
|
using TweetDick.Configuration;
|
||||||
using CefSharp;
|
using CefSharp;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace TweetDick.Core{
|
namespace TweetDick.Core{
|
||||||
public partial class FormBrowser : Form{
|
public partial class FormBrowser : Form{
|
||||||
@ -14,12 +16,17 @@ private static UserConfig Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly ChromiumWebBrowser browser;
|
private readonly ChromiumWebBrowser browser;
|
||||||
|
private readonly TweetDeckBridge bridge;
|
||||||
|
|
||||||
public FormBrowser(){
|
public FormBrowser(){
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
bridge = new TweetDeckBridge(this);
|
||||||
|
|
||||||
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/");
|
browser = new ChromiumWebBrowser("https://tweetdeck.twitter.com/");
|
||||||
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
browser.LoadingStateChanged += Browser_LoadingStateChanged;
|
||||||
|
browser.RegisterJsObject("$TD",bridge);
|
||||||
|
|
||||||
Controls.Add(browser);
|
Controls.Add(browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +61,9 @@ private void Browser_LoadingStateChanged(object sender, LoadingStateChangedEvent
|
|||||||
if (!e.IsLoading){
|
if (!e.IsLoading){
|
||||||
Invoke(new Action(SetupWindow));
|
Invoke(new Action(SetupWindow));
|
||||||
browser.LoadingStateChanged -= Browser_LoadingStateChanged;
|
browser.LoadingStateChanged -= Browser_LoadingStateChanged;
|
||||||
|
|
||||||
|
string js = File.ReadAllText("code.js",Encoding.UTF8);
|
||||||
|
browser.ExecuteScriptAsync(js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
Core/TweetDeckBridge.cs
Normal file
14
Core/TweetDeckBridge.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
namespace TweetDick.Core{
|
||||||
|
class TweetDeckBridge{
|
||||||
|
private readonly FormBrowser form;
|
||||||
|
|
||||||
|
public TweetDeckBridge(FormBrowser form){
|
||||||
|
this.form = form;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Log(string data){
|
||||||
|
System.Diagnostics.Debug.WriteLine(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Resources/code.js
Normal file
31
Resources/code.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
(function($,$TD){
|
||||||
|
//
|
||||||
|
// Variable: Says whether TweetDick events was initialized.
|
||||||
|
//
|
||||||
|
var isInitialized = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Function: Initializes TweetDick events. Called after the website app is loaded.
|
||||||
|
//
|
||||||
|
var initializeTweetDick = function(){
|
||||||
|
isInitialized = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Block: Observe the app <div> element and initialize TweetDick whenever possible.
|
||||||
|
//
|
||||||
|
var app = $("body").children(".js-app");
|
||||||
|
|
||||||
|
new MutationObserver(function(mutations){
|
||||||
|
if (mutations.some(mutation => mutation.attributeName === "class")){
|
||||||
|
if (isInitialized && app.hasClass("is-hidden")){
|
||||||
|
isInitialized = false;
|
||||||
|
}
|
||||||
|
else if (!isInitialized && !app.hasClass("is-hidden")){
|
||||||
|
initializeTweetDick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).observe(app[0],{
|
||||||
|
attributes: true
|
||||||
|
});
|
||||||
|
})($,$TD);
|
@ -97,6 +97,7 @@
|
|||||||
<Compile Include="Core\FormBackgroundWork.Designer.cs">
|
<Compile Include="Core\FormBackgroundWork.Designer.cs">
|
||||||
<DependentUpon>FormBackgroundWork.cs</DependentUpon>
|
<DependentUpon>FormBackgroundWork.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Core\TweetDeckBridge.cs" />
|
||||||
<Compile Include="Migration\FormMigrationQuestion.cs">
|
<Compile Include="Migration\FormMigrationQuestion.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -146,6 +147,12 @@
|
|||||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
</COMReference>
|
</COMReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ContentWithTargetPath Include="Resources\code.js">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
<TargetPath>code.js</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets" Condition="Exists('packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets')" />
|
<Import Project="packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets" Condition="Exists('packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets')" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
Loading…
Reference in New Issue
Block a user