Quantcast
WoWInterface - View Single Post - Code optimization and issue with hyperlinks in chat
View Single Post
10-12-18, 02:09 PM   #5
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
This is what I use for url copy
Lua Code:
  1. local DefaultSetItemRef = SetItemRef
  2.  
  3. --we replace the default setitemref and use it to parse links for alt invite and url copy
  4. function SetItemRef(link, ...)
  5.   local type, value = link:match("(%a+):(.+)")
  6.   if IsAltKeyDown() and type == "player" then
  7.     InviteUnit(value:match("([^:]+)"))
  8.   elseif (type == "url") then
  9.     local eb = LAST_ACTIVE_CHAT_EDIT_BOX or ChatFrame1EditBox
  10.     if not eb then return end
  11.     eb:SetText(value)
  12.     eb:SetFocus()
  13.     eb:HighlightText()
  14.     if not eb:IsShown() then eb:Show() end
  15.   else
  16.     return DefaultSetItemRef(link, ...)
  17.   end
  18. end
  19.  
  20. --AddMessage
  21. local function AddMessage(self, text, ...)
  22.   --channel replace (Trade and such)
  23.   text = text:gsub('|h%[(%d+)%. .-%]|h', '|h%1.|h')
  24.   --url search
  25.   text = text:gsub('([wWhH][wWtT][wWtT][%.pP]%S+[^%p%s])', '|cffffffff|Hurl:%1|h[%1]|h|r')
  26.   return self.DefaultAddMessage(self, text, ...)
  27. end
  28.  
  29. --skin chat
  30. for i = 1, NUM_CHAT_WINDOWS do
  31.   local chatframe = _G["ChatFrame"..i]
  32.   --adjust channel display
  33.   if (i ~= 2) then
  34.     chatframe.DefaultAddMessage = chatframe.AddMessage
  35.     chatframe.AddMessage = AddMessage
  36.   end
  37. end

https://github.com/zorker/rothui/blo...rChat/core.lua
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote