﻿using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace TweetDck.Resources{
    static class ScriptLoader{
        private const string UrlPrefix = "td:";

        public static string LoadResource(string name){
            try{
                return File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,name),Encoding.UTF8);
            }catch(Exception ex){
                MessageBox.Show("Unfortunately, "+Program.BrandName+" could not load the "+name+" file. The program will continue running with limited functionality.\r\n\r\n"+ex.Message,Program.BrandName+" Has Failed :(",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return null;
            }
        }

        public static void ExecuteFile(ChromiumWebBrowser browser, string file){
            ExecuteScript(browser,LoadResource(file),"root:"+Path.GetFileNameWithoutExtension(file));
        }

        public static void ExecuteFile(IFrame frame, string file){
            ExecuteScript(frame,LoadResource(file),"root:"+Path.GetFileNameWithoutExtension(file));
        }

        public static void ExecuteScript(ChromiumWebBrowser browser, string script, string identifier){
            if (script == null)return;

            using(IFrame frame = browser.GetMainFrame()){
                frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier);
            }
        }

        public static void ExecuteScript(IFrame frame, string script, string identifier){
            if (script == null)return;

            frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier);
        }
    }
}

﻿using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace TweetDck.Resources{
    static class ScriptLoader{
        private const string UrlPrefix = "td:";

        public static string LoadResource(string name){
            try{
                return File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,name),Encoding.UTF8);
            }catch(Exception ex){
                MessageBox.Show("Unfortunately, "+Program.BrandName+" could not load the "+name+" file. The program will continue running with limited functionality.\r\n\r\n"+ex.Message,Program.BrandName+" Has Failed :(",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return null;
            }
        }

        public static void ExecuteFile(ChromiumWebBrowser browser, string file){
            ExecuteScript(browser,LoadResource(file),"root:"+Path.GetFileNameWithoutExtension(file));
        }

        public static void ExecuteFile(IFrame frame, string file){
            ExecuteScript(frame,LoadResource(file),"root:"+Path.GetFileNameWithoutExtension(file));
        }

        public static void ExecuteScript(ChromiumWebBrowser browser, string script, string identifier){
            if (script == null)return;

            using(IFrame frame = browser.GetMainFrame()){
                frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier,1);
            }
        }

        public static void ExecuteScript(IFrame frame, string script, string identifier){
            if (script == null)return;

            frame.ExecuteJavaScriptAsync(script,UrlPrefix+identifier,1);
        }
    }
}

Change starting line in script processor to 1 instead of 0 for easier debugging
Change starting line in script processor to 1 instead of 0 for easier debugging
