So, here is the code for running on a throttled OnUpdate (just change the update interval to whatever you want).
Note: I only really care about raid frames being highly accurate, and I left the target frame how it was.
Fair warning, it's quite a bit more taxing on your CPU. It's a lot more reliable though, and probably what I will be using. This code is for legion, but just remove the underscore next to buffName on line 21 and it will work for BfA.
Lua Code:
local ONUPDATE_INTERVAL = 0.5
local lastUpdate = 0
--Compact Unit Frames
hooksecurefunc("CompactUnitFrame_OnUpdate",function(frame, elapsed)
lastUpdate = lastUpdate + elapsed
if lastUpdate >= ONUPDATE_INTERVAL then
lastUpdate = 0
local index = 1
local frameNum = 1
local filter = nil
while ( frameNum <= frame.maxBuffs ) do
local buffNames = UnitBuff(frame.displayedUnit, index, filter)
if ( buffNames ) then
if ( CompactUnitFrame_UtilShouldDisplayBuff(frame.displayedUnit, index, filter) and not CompactUnitFrame_UtilIsBossAura(frame.displayedUnit, index, filter, true) ) then
local buffFrame = frame.buffFrames[frameNum]
local buffName, _, icon, count, debuffType, duration, expirationTime, caster, canStealOrPurge, nameplateShowPersonal,
spellId, canApplyAura, isBossDebuff, casterIsPlayer, nameplateShowAll, timeMod, _ = UnitBuff(frame.displayedUnit, index, filter)
if spellId == 33763 and casterIsPlayer then
local timeRemaining = (expirationTime - GetTime()) / timeMod
local refreshTime = duration * 0.3
if not buffFrame.highlight then
local highlight = buffFrame:CreateTexture(nil, "OVERLAY")
highlight:SetTexture([[Interface\TargetingFrame\UI-TargetingFrame-Stealable]])
highlight:SetPoint("TOPLEFT", -3, 3)
highlight:SetPoint("BOTTOMRIGHT", 3, -3)
highlight:SetBlendMode("ADD")
buffFrame.highlight = highlight
end
if timeRemaining <= refreshTime then
buffFrame.highlight:Show()
else
buffFrame.highlight:Hide()
end
elseif buffFrame.highlight then
buffFrame.highlight:Hide()
end
frameNum = frameNum + 1
end
else
break
end
index = index + 1
end
end
end)