-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebLinks.lua
More file actions
91 lines (80 loc) · 2.27 KB
/
WebLinks.lua
File metadata and controls
91 lines (80 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local me = {
name = "WebLinks",
version = "0.11",
slashCommand = "/web",
enabled = true,
};
function me.parseHyperlink(s)
local link, type, data, text = string.match(s, "(|H(.+):(.+)|h(.+)|h)");
return type, string.gsub(data, ";//", "://"), text, link;
end
function me.OnLoad(this)
this:RegisterEvent("VARIABLES_LOADED");
_G[string.format("SLASH_%s1", me.name)] = me.slashCommand;
SlashCmdList[me.name] = me.ExecuteSlashCommand;
end
function me.OnEvent()
me.HookApi();
end
function me.HookApi()
local originalClickEventHandler = _G["ChatFrame_OnHyperlinkClick"];
_G["ChatFrame_OnHyperlinkClick"] = function(self, link, key)
if me.enabled and key == "LBUTTON" then
local linkType, linkData = me.parseHyperlink(link);
if linkType == "web" then
if IsShiftKeyDown() then
ChatEdit_AddItemLink(link);
elseif not IsCtrlKeyDown() then
--StaticPopupDialogs["OPEN_WEBROWER"].link = linkData;
--StaticPopup_Show("OPEN_WEBROWER");
GC_OpenWebRadio(linkData);
end
return;
end
end
originalClickEventHandler(self, link, key);
end;
local originalAddMessage = DEFAULT_CHAT_FRAME.AddMessage;
DEFAULT_CHAT_FRAME.AddMessage = function(self, txt, r, g, b)
if me.enabled then
txt = me.ConvertWebLinks(txt);
end
originalAddMessage(self, txt, r, g, b);
end;
-- hook other ChatFrames (thanks to tasquer)
for i = 3, 10 do
local frame = getglobal('ChatFrame' .. tostring(i))
if frame then
local orig = frame.AddMessage;
frame.AddMessage = function(self, txt, r, g, b)
if me.enabled then
txt = me.ConvertWebLinks(txt);
end
orig(self, txt, r, g, b);
end;
end
end
end
function me.ConvertWebLinks(txt)
if txt == nil then return end;
if string.find(txt, "://") then
local newTxt = string.gsub(txt, "([^%s]+://[^%s]+)", "|Hweb:%1|h|cffC6896D[%1]|r|h");
txt = string.gsub(newTxt, "(Hweb:%S-):/%/", "%1;//");
elseif string.find(txt, "www%..") then
txt = string.gsub(txt, "(www.[^%s]+)", "|Hweb:https;//%1|h|cffC6896D[%1]|r|h");
end
return txt;
end
function me.Enable(enable)
me.enabled = enable;
end
function me.ExecuteSlashCommand()
if me.enabled then
me.Enable(false);
DEFAULT_CHAT_FRAME:AddMessage("WebLinks "..OFF);
else
me.Enable(true);
DEFAULT_CHAT_FRAME:AddMessage("WebLinks "..ON);
end
end
_G[me.name] = me;