--By GigaAshley 11.0.5
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
    local isInstance, instanceType = IsInInstance()
    local hasQuestsWatched = C_QuestLog.GetNumQuestWatches() > 0
    local hasWorldQuestsWatched = C_QuestLog.GetNumWorldQuestWatches() > 0
    local watchedQuestsAreVisible = QuestObjectiveTracker.ContentsFrame:IsVisible()
    local watchedWorldQuestsAreVisible = WorldQuestObjectiveTracker.ContentsFrame:IsVisible()

    if event == "PLAYER_ENTERING_WORLD" then
        C_Timer.After(1, function()
            if isInstance then
                if hasQuestsWatched and watchedQuestsAreVisible then
                    QuestObjectiveTracker.Header.MinimizeButton:Click()
                elseif not hasQuestsWatched then
                    -- Do nothing if no quests
                end

                if hasWorldQuestsWatched and watchedWorldQuestsAreVisible then
                    WorldQuestObjectiveTracker.Header.MinimizeButton:Click()
                elseif not hasWorldQuestsWatched then
                    -- Do nothing if no quests
                end
            else -- Exiting instance
                if hasQuestsWatched and not watchedQuestsAreVisible then
                    QuestObjectiveTracker.Header.MinimizeButton:Click()
                elseif not hasQuestsWatched then
                    -- Do nothing if no quests
                end

                if hasWorldQuestsWatched and not watchedWorldQuestsAreVisible then
                    WorldQuestObjectiveTracker.Header.MinimizeButton:Click()
                elseif not hasWorldQuestsWatched then
                    -- Do nothing if no quests
                end
            end
        end)
    end
end)
