Goal
With Chrome extension, user-defined protocol and Windows API integrated in C#, the auto-look-up process when reviewing words on Shanbay can be even more cost-efficient and precise comparing with former methods.
- [x] Find a good Dictionary
- [x] Modify for better user experience
- [x] FInd a good Dictionary Software
- [x] Modify for better user experience
- [x] FInd a even better Dictionary Software and modify it for good
- [x] Integrate with Shanbay
- [x] Basic intergration by simulating user activity
- [x] Advanced intergration by combining webpage with local software
- [x] Triggered by user activity
- [ ] Triggered by page content update
- [x] Triggered by user activity
Chrome Extension
manifest.json
{
"name": "GoldenDictForShanbay",
"version": "0.9",
"manifest_version": 2,
"description": "GoldenDictForShanbay",
"icons": {"16":"16.png","48":"48.png","128":"128.png"},
"permissions": [
"https://www.shanbay.com/bdc/review/"
],
"browser_action": {
"default_icon": "16.png"
},
"content_scripts":[
{
"matches": ["https://www.shanbay.com/bdc/review/"],
"js":["main.js"]
}
]
}
main.js
document.addEventListener("keydown",callmain, false);
var formerword = null;
var word = null;
function callmain(){
document.addEventListener("keydown",callmain, false);
var formerword = null;
var word = null;
function callmain(){
if(
event.keyCode == 32 //space
|| event.keyCode == 49 //main 1
|| event.keyCode == 50 //main 2
|| event.keyCode == 68 //d
|| event.keyCode == 97 //numpad 1
|| event.keyCode == 98 //numpad 2
){
setTimeout(main, 200);
}
};
function main(){
word = document.getElementsByTagName("h1")[0].innerHTML
if(formerword != word){
window.location.href="GoldenDict://"+word;
formerword = word;
}
}
User-defined Protocol
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\GoldenDict]
"URL Protocol"="D:\\Users\\Mark\\Documents\\Mark\\Data\\Dictionary\\GoldenDict\\protocol\\GoldendictProtocol.exe"
@="protocol.exe"
[HKEY_CLASSES_ROOT\GoldenDict\DefaultIcon]
@="D:\\Users\\Mark\\Documents\\Mark\\Data\\Dictionary\\GoldenDict\\protocol\\GoldendictProtocol.exe,1"
[HKEY_CLASSES_ROOT\GoldenDict\shell]
[HKEY_CLASSES_ROOT\GoldenDict\shell\open]
[HKEY_CLASSES_ROOT\GoldenDict\shell\open\command]
@="\"D:\\Users\\Mark\\Documents\\Mark\\Data\\Dictionary\\GoldenDict\\protocol\\GoldendictProtocol.exe\" \"%1\""
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace GoldendictProtocol
{
class Program
{
static void Main(string[] args)
{
IntPtr hWnd = GetForegroundWindow();
if (args.Length > 0)
{
args[0] = args[0].Remove(0, 13);
args[0] = args[0].Replace("%20", " ");
System.Diagnostics.Process.Start("D:\\Users\\Mark\\Documents\\Mark\\Data\\Dictionary\\GoldenDict\\GoldenDict.exe", "\"" + args[0] + "\"");
}
System.DateTime beforDT = System.DateTime.Now;
System.DateTime afterDT = new System.DateTime();
do
{
if (hWnd == GetForegroundWindow())
{
afterDT = System.DateTime.Now;
System.Threading.Thread.Sleep(1);
continue;
}
else
{
break;
}
} while (afterDT.Subtract(beforDT).TotalMilliseconds < 200);
SetForegroundWindow(hWnd);
}
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern int SetForegroundWindow(IntPtr hwnd);
}
}