WoWInterface SVN ItemLinkRecolor

[/] [ItemLinkRecolor.lua] - Rev 7

Compare with Previous | Blame | View Log

--[[
Changelog:
    Version 3.0.4
        Removed some debugging info i forgot

    Version 3.0.3
        Updated TOC version number
        Fixed for MoP 11 sections itemlinks

    Version 3.0.2
        Tested on MoP
        Make two hooks secure
        Removed itemlink show hook as it nolonger seems needed
        Removed /it command as it was non functioning leftover from debugging
        
    Version 3.0.1
        Now the money colorling of ..K as 1000g should work
        TOC version updated to 4.3

    Version 3.0.0
        Updated for WoW 4.2, was about time id update it
        Updated silvanas addonlib
        Moneycoloring of Copper got removed
        Moneycoloring now sepport ..K as 1000g
        Mouseover tooltip now sepports instance lockout info
        Fixed the option to show or hide required levels to work again

    Version 2.4.3
        some achiements would break when money color was enabled this has been fixed
    
    Version 2.4.2
        u can now link BoA items :P

    Version 2.4.1
        Updated TOC version

    Version 2.4.0
        Now works on WoW 3.0.2
        Updated Silvanas Addonlib
        Nolonger errors on player / channel links

    Version 2.3.4
        Hopefully fixed the bug that cased the settings to reset

    Version 2.3.3
        fixed a version number bug in silvanas addon lib

    Version 2.3.2
        fixed a bug reported whit ItemLinkRecolor_ChatFrame_OnHyperlinkEnter()

    Version 2.3.1
        updated for wow version 2.4.3
        updated silvanas addonlib
        fixed time delay functions in silvanas addonlib
                
    Version 2.3.0
        now works even on itmes u havent seen before
        updated for wow version 2.4.1
        added abelity to show mini item icons
        interface moved to the wow option panel
        when an item link is not your local cache it will be load for next time

    Version 2.2.1
        made compatable whit SuperiorEpix

    Version 2.2.0
        code updated for WoW 2.3
        added optional sepport for the Superior Epix addon

        version 2.1.9
                minor bugfix where items whit 3 sockets got showns asif they had 4

    Version 2.1.8
                Specail items id's are now also colored
        toc updated for patch 2.1.3
        updated silvanas addonlib

    Version 2.1.7
        Added a new optional function to enable 'mouseover' item tooltips
        
    Version 2.1.6
        Updated toc version for patch 2.1.2
        New scanning methot for recipies and seppport for the yellow colored links

        Version 2.1.4
                Updated toc version for patch 2.0.8
        Fixed coloring of recipy that allow the user ot create socketed item
        
    Version 2.1.3
        Fixed relinking of socketed item links
        Refixed missing auctioneer tooltips

        Version 2.1.1
                Updated toc version for patch 2.0.4

    Version 2.1.0
        Fixed for wow version 2.0.3

        Version 2.0.2
                Fixed bug in the new SilvanasAddonLib

    Version 2.0.1
        Updated code for WoW 2.0
        Updated SilvanasAddonLib
        Updated interfcecode

    Version 2.0.0
        Burning Crusade Compatable
        nolonger colors m8s as 8 silver
        Added abiletie to show sockets info
        Added interface / removed commands
        money coloring now defauls to enabled
        updated silvanas addonlib

    Version 1.2.3
                nolonger shows the item level if item if minium level is 1
        orange now matches the orange color of legendairy items

    Version 1.2.2
        fixed shiftclick relinking of colored links
        this also fixed auctioneer item link tooltip bug and other posable addons bugs
        autiocneer compatabiletie removed since its nologer needed after the bugs have been fixed
        optimsied code a litle bit
        now also colors outgoing whispers
        
    Version 1.2.1
        fixed actioneer 3.6.1 compatibiletie
        optimsied OnEvent system

        Version 1.2.0
                fixed compeltely disapaering messages by a big moddification in the hook
                updated toc
                updated silvanaslib

        Version 1.1.8
                fixed a small scanning bug that would some unenquipable items show up as useable

        Version 1.1.7
                fixed 2 overflown bugs but in a bad way so the might be new probs atleast i tryed to fix it :p

        Version 1.1.5
                Fixed a small version number witch i forgot to update 

        Version 1.1.4
                now only works on chat messages or loot message

        Version 1.1.1
                small bug fix for iems whitout a level got shown whit a () level witch is now gone again

        Version 1.1.0
            basic sepport added for customiseable colors for some items witch can be set in the "CustomRecolor.lua"
        Money coloring now default to off becase of the many unforseen problems... :(
        added a new comand to get  he number of an item
        actioneer sepport fixed for actionneer version 3.6.1
        Setting now get saved and loaded back instead of jsut saved

        Version 1.0.8
                Fixed money coloring inside color strings
                Hopefully fixed the german stack overflow
                Fixed money enable or disable cmds

        Version 1.0.5
                Fixed money coloring system trigering on g2g
                Fixed error when a nil message was send
                Fixed compatibiltie whit Nerfed Combatlog (but not the actual prob that was casing the bug)

        Version 1.0.3
            Fixed bug where some item strings where nolonger localised
            Fixed a bug where multiple item links in 1 chat message all would link to the first item
            Money / itemlink coloing can now be turned on / off seperately

        Version 1.0.0
                First working version, after lots of debugging :p

Known Bugs:
        Sometimes the itemlinks dont get colored but there is nothing i can do about it

Todo:
        None
--]]

--main global var
ItemLinkRecolor = {
        ["NAME"]                = "|TInterface\\Icons\\Spell_unused:0|t |cFF33CC66Item Link Recolor|r",
        ["VERSION"]     = "(|cFF9900003|cFFFFFFFF.|cFF9900000|cFFFFFFFF.|cFF9900004|cFFFFFFFF)|r",
}
--

--events that we will color
local ItemLinkRecolor_AllowedEvents = {
        ["CHAT_MSG_CHANNEL"]        = true,
        ["CHAT_MSG_LOOT"]                   = true,
        ["CHAT_MSG_OFFICER"]        = true,
        ["CHAT_MSG_PARTY"]                  = true,
        ["CHAT_MSG_RAID"]                   = true,
        ["CHAT_MSG_RAID_LEADER"]    = true,
        ["CHAT_MSG_SAY"]                    = true,
        ["CHAT_MSG_WHISPER"]        = true,
        ["CHAT_MSG_YELL"]                   = true,
        ["CHAT_MSG_GUILD"]                  = true,
    ["CHAT_MSG_WHISPER_INFORM"] = true,
}
local ItemLinkRecolor_AllowedLinks = {
    ["item:"]                   = true,
    ["spell"]                   = true,
    ["encha"]                   = true,
    ["talen"]                   = true,
    ["achie"]                   = true,
    ["quest"]                   = true,
    ["insta"]                   = true,
}
--

--local hook pointers
local ILR_ChatFrame_MessageEventHandler_Hook    --hooks chatframe events
local ILR_ChatFrame_OnHyperlinkShow_Hook        --hooks clicked chat hyper links
--

--local global vars
local ItemLinkRecolor_MissingData = false
--

-------------------
--event triggered--
-------------------
--onload
function ItemLinkRecolor_Load(self)
        --register events
        self:RegisterEvent("VARIABLES_LOADED")
end

--on event
function ItemLinkRecolor_Event()
        --basic chatframe event hook
        ILR_ChatFrame_MessageEventHandler_Hook = ChatFrame_MessageEventHandler
        ChatFrame_MessageEventHandler = ItemLinkRecolor_ChatFrame_MessageEventHandler

    --hook event for mouse over hyperlinks
    local i,cframe
    
    --for each chat window
    for i=1,NUM_CHAT_WINDOWS do
        --get the chatframe
        cframe = _G["ChatFrame".. i]
        
        --if the chat frame exists
        if cframe then
            --overwrite general xml chat hooks
            cframe:HookScript("OnHyperlinkEnter",ItemLinkRecolor_ChatFrame_OnHyperlinkEnter)
            cframe:HookScript("OnHyperlinkLeave",ItemLinkRecolor_ChatFrame_OnHyperlinkLeave)
        end
    end
    
    --call other files
    ItemLinkRecolor_Interface_Event()
    
        --load up saved variables
        if not ItemLinkRecolorSavedVars then
                --if there are no saved vars then well reload the default
        ItemLinkRecolor_Reset()
        else
            if not ItemLinkRecolorSavedVars["VERSION"] or (ItemLinkRecolorSavedVars["VERSION"] ~= ItemLinkRecolor["VERSION"]) then
                        --if there are saved vars but under the wrong version then reload the default
                        ItemLinkRecolor_Reset()
                end
        end
    
    --use delayed functions
    Silvanas.InitTimeDelay()
    
    --set up commands
    Silvanas.AddCmd("ITEMLINKRECOLOR_CMD",ItemLinkRecolor_Cmd_ItemLinkRecolor,{"ilr","ItemLinkRecolor"})
    Silvanas.AddCmd("ITEMLINKRECOLOR_CMD_INSTACETEST",ItemLinkRecolor_Cmd_FakeInstanceLock,{"it"})

        --loaded message
        Silvanas.Print(ItemLinkRecolor["NAME"] .." |cFFFFFFFFBy: ".. Silvanas.Author .." |cFFFFFFFFversion: ".. ItemLinkRecolor["VERSION"] .." |cFFFFFFFFloaded.|r")
end
-------------------
-------------------
-------------------

-----------------------
--chat hook functions--
-----------------------
--this function takes over the real "ChatFrame_MessageEventHandler" and calls the real one afterwards
function ItemLinkRecolor_ChatFrame_MessageEventHandler(frame,event,msg,...)
    --if we got this addon enabled
        if ItemLinkRecolorSavedVars["ENABLED"] then
    
                --if we allow this event
        if (string.sub(event,1,8) == "CHAT_MSG") and ItemLinkRecolor_AllowedEvents[event] then

            --if we got money coloring enabled
                        if ItemLinkRecolorSavedVars["MLENABLED"] then
                                --Parse money strings and return them in color
                        msg = string.gsub(msg,"([%.,gGkK]-%d+%s-[kKgGsS]%a*)",ItemLinkRecolor_Moneyrize)
                        end
            --if we got item icons enabled
            if ItemLinkRecolorSavedVars["MIENABLED"] then
                                --find an item links and return a new item link whit an icon
                        msg = string.gsub(msg,"(|Hitem:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+:%d+|h)",ItemLinkRecolor_Iconise)
            end
            
            --if we got itemlink coloring enabled
                        if ItemLinkRecolorSavedVars["ILENABLED"] then
                ItemLinkRecolor_MissingData = false
                msg = string.gsub(msg,"(|Hitem:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+:%d+|h[^:]-|h)",ItemLinkRecolor_FindMissingData)
                                
                if ItemLinkRecolor_MissingData then
                    --call dalayed function
                    Silvanas.DelayFunc(1,ItemLinkRecolor_ChatFrame_MessageEventHandler_Delayed,frame,event,msg,1,...)
                    
                    --dont call the hook we do it at the delayed function
                    return
                else
                    --find an item links and return new colored ones
                            msg = string.gsub(msg,"(|Hitem:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+:%d+|h[^:]-|h)",ItemLinkRecolor_Colorize)
                end
            end
        end
        end 
    
    ILR_ChatFrame_MessageEventHandler_Hook(frame,event,msg,...)
end

function ItemLinkRecolor_ChatFrame_OnHyperlinkEnter(self,link)
    --if we got mouseover hyperlinks enabled
    if ItemLinkRecolorSavedVars["MOUSEOVERLINK"] then
        --if something went wrong
        if not link then return; end
        
        --if its an acceptable link
        local shortlink = string.sub(link,1,5)
             
        if ItemLinkRecolor_AllowedLinks[shortlink] then
            --create the tooltip on cursor
            GameTooltip:ClearLines()
            GameTooltip:SetOwner(UIParent,"ANCHOR_NONE")
            GameTooltip:SetPoint("TOPLEFT",UIParent,"BOTTOMLEFT",GetCursorPosition())
            GameTooltip:SetHyperlink(link)
        end
    end
end

function ItemLinkRecolor_ChatFrame_OnHyperlinkLeave(self)
    --if we got mouseover hyperlinks enabled
    if ItemLinkRecolorSavedVars["MOUSEOVERLINK"] then
                GameTooltip:Hide()
    end
end
-----------------------
-----------------------
-----------------------

----------------------
--coloring functions--
----------------------
function ItemLinkRecolor_Colorize(texty)
    --parse elements of the link
        local link,itemnum,socket1,socket2,socket3,linklvl
        link,itemnum,socket1,socket2,socket3,linklvl = string.match(texty,"^|H(item:(%d+):%d+:(%d+):(%d+):(%d+):%d+:[-%d]+:[-%d]+:(%d+):%d+:%d+)|h")
    
    --renumber
    linklvl = tonumber(linklvl)
    
    --get the item atributes
        local x,itemquality,itemlevel,itemname,trys
    itemname,x,itemquality,x,itemlevel = GetItemInfo(link)
       
    --see if the item needs tobe request from server first
    if not itemquality then
        --data was not found so lets forget about it >.<        
        return texty
    end
    
    --superior epix seppport
    --incase its superior epix
    if SuperiorEpix_Quality and SuperiorEpix_Quality(link) then
        itemquality = SUPERIOREPIX_QUALITY_SUPERIOR
    end 
    --

        --get the quality color
        local itemqualitycolor
        itemqualitycolor = "|c".. Silvanas.Select(4,GetItemQualityColor(itemquality)) --|c was removed in 4.2

        --build the level display
        local itemlevelcolor,playerlevel
        playerlevel = UnitLevel("player")
        itemlevelcolor = nil

    if itemlevel == 0 or itemlevel == 1 then
        --see if its bind on acount
        if itemquality == 7 then
            itemlevel = linklvl
            itemlevelcolor = "|cFFFFFFFF"
        else
            --items that dont have a min level
            itemlevel = 0
            itemlevelcolor = ""
        end
        else
                if itemlevel > (playerlevel + 5) then
                        itemlevelcolor = "FF0000"
                elseif itemlevel > playerlevel then
                itemlevelcolor = "FF9933"
                elseif itemlevel == playerlevel then
                itemlevelcolor = "FFFF00"
                elseif itemlevel > (playerlevel - 5) then
                itemlevelcolor = "00FF00"
                else
                itemlevelcolor = "999999"
                end
                
                --finish the itemlevelcolor
                itemlevelcolor = "|cFF".. itemlevelcolor
        end
        
        --check if we can use it or not
        local brakcetcolor
        
        --if it isnt already se by the customiseable part
    if itemlevel > playerlevel then
            --if the level is already to high then make the brackets red
        brakcetcolor = "|cFFFF0000"
        else
        --use tooltip scanning
        --set the tooltiplink
        ItemLinkRecolor_SetToolTipLink(link)
            
         --see if its enquipable
                if ItemLinkRecolor_CanEnquip(link) then
                        brakcetcolor = itemqualitycolor
                else
                brakcetcolor = "|cFFFF0000"
                end
        end
        
    --socketinfo
    local socketinfo
    socketinfo = ""
    
    --if we got socketinfo enabled
    if ItemLinkRecolorSavedVars["SENABLED"] then
        --first see if the item is already filled so we dont have to scan the tooltip, only works on item that have 3 filled slots
        --scan backwards bcase its more likely to have a 0 at the 3rd slot instead of the first
        if (tonumber(socket3) > 0) and (tonumber(socket2) > 0) and (tonumber(socket1) > 0) then
            socketinfo = "|r |cFFFFFFFF*|r |cFFFFFFFF*|r |cFFFFFFFF*|r"
        else
            --set the tooltiplink
            ItemLinkRecolor_SetToolTipLink(link)
            
            --we got to scan the itemtooltip
            socketinfo = ItemLinkRecolor_GetSocketInfo(link)
        end
    end
    
    --build and return the return value
        if (itemlevel == 0) or not ItemLinkRecolorSavedVars["LENABLED"] then
                --dont dispaly he level for item whitout a minuim level
                return "|r|H".. link .."|h".. brakcetcolor .."[|r".. itemqualitycolor .. itemname .. socketinfo .."|r".. brakcetcolor .."]|r|h"
        else
                return "|r|H".. link .."|h".. brakcetcolor .."[|r".. itemlevelcolor .."(".. itemlevel ..")|r" .. itemqualitycolor .. itemname .. socketinfo .."|r".. brakcetcolor .."]|r|h"
        end
end

function ItemLinkRecolor_FindMissingData(texty)
    --parse elements of the link
        local link
        link = string.match(texty,"^|H(item:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+:%d+)|h")
    
    --get the item atributes
        local itemquality
    itemquality = select(3,GetItemInfo(link))
    
    --see if the item needs tobe request from server first
    if not itemquality then
        --data was not found so lets request it from the server
        --forcing it to display on a tooltip will case data tobe loaded
        ItemLinkRecolor_SetToolTipLink(link)
        
        --set the variable so we got to delay this message
        ItemLinkRecolor_MissingData = true
    else
        --see if the tooltip data is already available
        ItemLinkRecolor_SetToolTipLink(link)
        
        --see if we are still getting the red message on the tooltop
        if ItemLinkRecolorScanningTooltip:NumLines() == 1 then
            local TooltipTextFrame = getglobal("ItemLinkRecolorScanningTooltipTextLeft1")
        
            if ItemLinkRecolor_ToolTipTextIsRed(TooltipTextFrame) then
                --set the variable so we got to delay this message
                ItemLinkRecolor_MissingData = true
            end
        end
    end
    
    return texty
end

--the coloring fuction of money
function ItemLinkRecolor_Moneyrize(texty)
        --if it isnt a g2g or m8s message or a section of a link seperated whit a :
        if string.find(texty,":") or string.find(texty,"[gG]2[gG]") or string.find(texty,"[mM]8[sS]")then
                return texty
        end
        
        --if its contains a color code
        local colorcode,returntext
        colorcode = string.match(texty,"^|c(%x+)")
        
        --if we are trying to color inside the colorcode then ignore this money and return wutever txt we had
        if colorcode then
                if string.len(colorcode) < 8 then
                        return texty
                else
                        --cut off the color code but still and it in the end
                        colorcode = string.sub(texty,1,10)
                        returntext = string.sub(texty,11)
                end
        else
            returntext = texty
            colorcode = ""
        end

    --parse money
    local money1,money2,moneytype,moneystr
    money1,money2,moneytype,moneystr = string.match(texty,"^(%d-)[%.,]-(%d+)%s-([kKgGsS])(%a*)$")
    
    --if something went wrong ignore this chat link and return wutever text we recieved
    if moneytype then
        moneytype = string.upper(moneytype)
    else
        --if something went wrong ignore this chat link and return wutever text we recieved
        return texty
    end
    
    --see if moneystr is part of an other word
    if moneystr ~= "" then
        moneystr = string.lower(moneystr)
        --see if our moneytype and moneystr are valid
        if moneytype == "K" then
            if moneystr ~= 'g' then
                return texty
            end
        elseif moneytype == "G" then
                if moneystr ~= "old" then
                                return texty
                        end
                elseif moneytype == "S" then
                        if moneystr ~= "ilver" then
                                return texty
                        end
                end
        end 
    
    --if there is no comma or dot but only 1 number
    if money1 == "" then
        --if something went wrong ignore this chat link and return wutever text we recieved
                if money2 == "" then
            return texty
                end
                
                --if there is only 1 number then store it in money1 and make money2 0
        money1 = money2
        money2 = 0
        end
        
        --calc the money in copper
        local moneycopper,mcalc
        mcalc = {
        ["K"] = 10000000,
        ["G"] = 10000,
        ["S"] = 100,
        }
        moneycopper = (tonumber(money1)*mcalc[moneytype]) + (tonumber(money2)*(mcalc[moneytype] / 100))

    --get the player his money
        local playermoney
        playermoney = GetMoney()

        --do the money compare
        local moneycoler, quartplayermoney
    
    quartplayermoney = playermoney / 4
    
    if moneycopper > (playermoney + quartplayermoney) then
        moneycoler = "FF0000"
    elseif moneycopper > playermoney then
        moneycoler = "FF9933"
    elseif (moneycopper <= playermoney) and (moneycopper > (playermoney - quartplayermoney)) then
        moneycoler = "FFFF00"
    elseif (moneycopper <= (playermoney - quartplayermoney)) and (moneycopper > quartplayermoney) then
        moneycoler = "00FF00"
    else
        moneycoler = "999999"
    end

        --return the new text
        return "|cFF".. moneycoler .. returntext .."|r".. colorcode
end

--the fucntion to add item icons
function ItemLinkRecolor_Iconise(texty)
    --parse elements of the link
        local itemid
        itemid = string.match(texty,"^|H(item:%d+)")
    
    --see if it went correct
    if not itemid then
        return texty
    end
    
    return "|T".. GetItemIcon(itemid) ..":0|t".. texty
end
----------------------
----------------------
----------------------

---------------------
--Checkup Functions--
---------------------
function ItemLinkRecolor_CanEnquip()
        --oke we search in a hidden tooltip to find if there are any red lines so we cant use it :p
        local TooltipTextFrame,i
        
    --go over each line in the tooltip and search for things that are in red
        for i=1,ItemLinkRecolorScanningTooltip:NumLines(),1 do --go over each line
         --get one left text object
                TooltipTextFrame = getglobal("ItemLinkRecolorScanningTooltipTextLeft".. i)
                
        --if the text is red we return false since we assume we cant enquip it
                if ItemLinkRecolor_ToolTipTextIsRed(TooltipTextFrame) then
                        return false
                end
                
                if (i == 2) or (i == 3) then --2,3 RIGHT can be the armor type
                        --get the right text object
                    TooltipTextFrame = getglobal("ItemLinkRecolorScanningTooltipTextRight".. i)
                        
                        --if the text is red we return false since we assume we cant enquip it
                        if ItemLinkRecolor_ToolTipTextIsRed(TooltipTextFrame) then
                                return false
                        end     
                end
        end

        --if nothing in red was found we assume we can use use it
        return true
end

function ItemLinkRecolor_GetSocketInfo()
    --build the string shit sockets info to return
    local i,SocketString
    SocketString = ""
    
    --get over all sockets
    --MAX_NUM_SOCKETS = 3;
    for i=1,3,1 do
        --get one socket icon object
                TooltipIconFrame = getglobal("ItemLinkRecolorScanningTooltipTexture".. i)
       
        --get the color
        local scolor
        scolor = ItemLinkRecolor_GetSocketColor(TooltipIconFrame)

        --see if we got a color or something went wrong
        if scolor then
            SocketString = SocketString .." |cFF".. scolor .."*"
        end
    end
    
    --cancel the color of the itemlink
    if string.len(SocketString) > 0 then
            SocketString = "|r".. SocketString
    end
    
    --return the socketstring
    return SocketString
end
---------------------
---------------------
---------------------

------------------------------
--tooltip scanning functions--
------------------------------
function ItemLinkRecolor_SetToolTipLink(link)
    --if its a different link
    if ItemLinkRecolorScanningTooltip.curentlink ~= link then
        --set new link
        ItemLinkRecolorScanningTooltip.curentlink = link
        
            --first clear the tooltip
            ItemLinkRecolorScanningTooltip:ClearLines()
        
        --set the link
            ItemLinkRecolorScanningTooltip:SetHyperlink(link)
    end
end

function ItemLinkRecolor_ToolTipTextIsRed(TooltipFrame)
    --if we got a real frame
        if TooltipFrame and TooltipFrame:IsVisible() then --dont scan colors of invisable frames
                --gets its colors
                local ttca,ttcr,ttcg,ttcb
                ttcr,ttcg,ttcb,ttca = TooltipFrame:GetTextColor()
                        
        --if its red then we assume we cant use this item (yes its not a clean and save way but it saves cpu usage)
                --if (ttcr == 0.99999780301005) and (ttcg == 0.12548992037773) and (ttcb == 0.12548992037773) and (ttca == 0.99999779462814) then
                if (ttcr > 0.999) and (ttcg > 0.125 and ttcg < 0.126) and (ttcb > 0.125 and ttcb < 0.126) and (ttca > 0.99) then
                        return true
                end
        end
        return false
end

function ItemLinkRecolor_GetSocketColor(TooltipFrame)
    --table to convert strings to hexidecimal colors
    local ItemLinkRecolor_Socketcolors = {
        ["Red"] = "FF0000",
        ["Blue"] = "0000FF",
        ["Yellow"] = "FFFF00",
        ["Meta"] = "666666"
    }
    
    --if we got a real frame
    if TooltipFrame and TooltipFrame:IsVisible() then --dont scan hidden icon frames
                --get the texture
                local IconTexture,Socketcolor
                IconTexture = TooltipFrame:GetTexture()
        
        --get the socketcolor
        Socketcolor = string.match(IconTexture,"UI%-EmptySocket%-(%a+)$")
        
        if Socketcolor then
            --convert to hexidecimal color and see if something went wrong
            return ItemLinkRecolor_Socketcolors[Socketcolor] or false
        else
            --if socket if filled
            return "FFFFFF"
        end
    else
        --if that frame doesnt exist or item doesnt got a socket / gem
        return false
    end
end
------------------------------
------------------------------
------------------------------

-------------------
--timed functions--
-------------------
function ItemLinkRecolor_ChatFrame_MessageEventHandler_Delayed(frame,event,msg,count,...)
    --if we already delayed it 5 times we skip it
    if count <= 5  then
        --increment delay counter
        count = count + 1
        
        ItemLinkRecolor_MissingData = false
        msg = string.gsub(msg,"(|Hitem:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+:%d+|h[^:]-|h)",ItemLinkRecolor_FindMissingData)

        --if the data still didnt arive we delay it a bit more
        if ItemLinkRecolor_MissingData then
            --call dalayed function
            Silvanas.DelayFunc(1,ItemLinkRecolor_ChatFrame_MessageEventHandler_Delayed,frame,event,msg,count,...)
            return
        end
  
        --find an item links and return new colored ones
        msg = string.gsub(msg,"(|Hitem:%d+:%d+:%d+:%d+:%d+:%d+:[-%d]+:[-%d]+:%d+:%d+|h[^:]-|h)",ItemLinkRecolor_Colorize)
    end
    
        --Call the orriginal function
        ILR_ChatFrame_MessageEventHandler_Hook(frame,event,msg,...)
end
-------------------
-------------------
-------------------

---------
--reset--
---------
function ItemLinkRecolor_Reset()
        ItemLinkRecolorSavedVars = {
            ["VERSION"]         = ItemLinkRecolor["VERSION"],
                ["ENABLED"]         = true,
                ["ILENABLED"]       = true,
                ["MLENABLED"]       = true,
        ["MIENABLED"]       = true,
        ["LENABLED"]        = true,
        ["SENABLED"]        = false,
        ["MOUSEOVERLINK"]   = false,
        }
end
---------
---------
---------

------------
--commands--
------------
function ItemLinkRecolor_Cmd_ItemLinkRecolor()
    --show the options menu
    ShowUIPanel(InterfaceOptionsFrame)
    InterfaceOptionsFrame.lastFrame = GameMenuFrame
    
    --select our frame
    InterfaceOptionsFrame.selectedTab = 2 --addontab
    InterfaceOptionsFrame_TabOnClick()
    
    --find out our addonbutton and click on it
    local i = 1
    while InterfaceOptionsFrameAddOns.buttons[i] do
        --if its our button then clikc on it
        if InterfaceOptionsFrameAddOns.buttons[i]:GetText() == ItemLinkRecolor["NAME"] then
            InterfaceOptionsFrameAddOns.buttons[i]:Click()
            return
        end
        i = i + 1
    end
end
------------
------------
------------

Compare with Previous | Blame