--[[ <HCExtension>@name Test@author truefriend-cz@version Beta@event BeforeViewInMonitor@event RequestHeaderReceived@event AnswerHeaderReceived@event BeforeAnswerHeaderSend</HCExtension> ]]function BeforeViewInMonitor() monitor_string = '' monitor_string_array = {}endfunction RequestHeaderReceived() if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array, 1, 'Load from Cache') else hc.action = 'save' table.insert(monitor_string_array, 1, 'Saved to Cache') endendfunction AnswerHeaderReceived() table.insert(monitor_string_array, 2, '(Test)')endfunction BeforeAnswerHeaderSend() for string_number, string_text in ipairs(monitor_string_array) do monitor_string = monitor_string..string_text end hc.monitor_string = monitor_stringend
--[[ <HCExtension>@name Test2@author truefriend-cz@version Beta@event RequestHeaderReceived@event AnswerHeaderReceived@event BeforeAnswerHeaderSend</HCExtension> ]]function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' monitor_string_array[hc.monitor_index] = 'Load from Cache' else hc.action = 'save' monitor_string_array[hc.monitor_index] = 'Save to Cache' endendfunction AnswerHeaderReceived() monitor_string_array[hc.monitor_index] = monitor_string_array[hc.monitor_index] .. '(Test)'endfunction BeforeAnswerHeaderSend() hc.monitor_string = monitor_string_array[hc.monitor_index]end
--[[ <HCExtension>@name Test 3@author truefriend-cz@version Beta@event BeforeViewInMonitor@event RequestHeaderReceived@event BeforeAnswerHeaderSend</HCExtension> ]]function monitor_add_string(d) if check_empty(monitor_string) then return d else return delimiter..d endendfunction monitor_show() if check_full(monitor_string) then hc.monitor_string = monitor_string end if check_full(monitor_color) then hc.monitor_text_color = monitor_color endendfunction check_empty(d) return d == '' or d == nilendfunction check_full(e) return e ~= '' or e ~= nilendfunction sort_table(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 local iter = function() i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iterendfunction BeforeViewInMonitor() monitor_string = '' monitor_string_array = {} delimiter = ' - ||| - 'endfunction RequestHeaderReceived() if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array, 10, 'Load from Cache') else hc.action = 'save' table.insert(monitor_string_array, 11, 'Saved to Cache') endendfunction BeforeAnswerHeaderSend() table.insert(monitor_string_array, 40, '(Test priority 2)') table.insert(monitor_string_array, 17, '(Test priority 1)') table.insert(monitor_string_array, 55, '(Test priority 4)') table.insert(monitor_string_array, 53, '(Test priority 3)') for string_number, string_text in sort_table(monitor_string_array) do monitor_string = monitor_string..monitor_add_string(string_text) end monitor_show()end
--[[ <HCExtension>@name Test4@author truefriend-cz@version Beta@event RequestHeaderReceived@event BeforeAnswerHeaderSend</HCExtension> ]]function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) endendfunction BeforeAnswerHeaderSend() local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = monitor_color end end table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=17, text='(Test priority 1)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=55, text='(Test priority 4)'}) table.insert(monitor_string_array[hc.monitor_index], {priority=53, text='(Test priority 3)'}) table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter))end
...function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} monitor_color_array = monitor_color_array or {} monitor_color_array = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) table.insert(monitor_color_array, {priority=10, color='102, 150, 0'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) end testa = monitor_color_array[#monitor_color_array].color -- for testing 1 hc.put_msg(1, 'Test OK: '..testa) -- for testing 2endfunction BeforeAnswerHeaderSend() local function rgb(r, g, b) local r = r local g = g*256 local b = b*256*256 return r+g+b end local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then rgb(monitor_color) hc.monitor_text_color = monitor_color end end table.insert(monitor_string_array[hc.monitor_index], {priority=5, text='('..type_define..')'}) table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'}) table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) table.sort(monitor_color_array, function(record1, record2) return record1.priority <= record2.priority end ) local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end for i,record in ipairs(monitor_color_array) do monitor_color_array[i] = record.color end monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), monitor_color_array[1].color)end
table.insert(monitor_color_array, {priority=10, color=102, 150, 0})
monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), rgb(255,0,0))
function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], { priority=10, text='Load from Cache', color={102,150,0} }) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], { priority=11, text='Saved to Cache' }) endendfunction BeforeAnswerHeaderSend() local function rgb(r, g, b) return r + g*256 + b*256*256 end local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = rgb(table.unpack(monitor_color)) end end table.insert(monitor_string_array[hc.monitor_index], { priority=40, text='(Test priority 2)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=17, text='(Test priority 1)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=55, text='(Test priority 4)' }) table.insert(monitor_string_array[hc.monitor_index], { priority=53, text='(Test priority 3)' }) table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) local texts = {} for i,record in ipairs(monitor_string_array[hc.monitor_index]) do texts[i] = record.text end local delimiter = ' - ||| - ' monitor_show(table.concat(texts, delimiter), monitor_string_array[hc.monitor_index][1].color)end
...function RequestHeaderReceived() monitor_string_array = monitor_string_array or {} monitor_string_array[hc.monitor_index] = {} monitor_color_array = monitor_color_array or {} monitor_color_array = {} if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(monitor_string_array[hc.monitor_index], {priority=10, text='Load from Cache'}) table.insert(monitor_color_array, {priority=20, color='102, 150, 0'}) else hc.action = 'save' table.insert(monitor_string_array[hc.monitor_index], {priority=11, text='Saved to Cache'}) end testa = monitor_color_array[#monitor_color_array].color -- for testing 1 hc.put_msg(1, 'Test OK: '..testa) -- for testing 2endfunction BeforeAnswerHeaderSend() local function rgb(r, g, b) local r = r local g = g*256 local b = b*256*256 return r+g+b end local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then rgb(monitor_color) hc.monitor_text_color = monitor_color end end table.insert(monitor_string_array[hc.monitor_index], {priority=5, text='('..type_define..')'}) table.insert(monitor_string_array[hc.monitor_index], {priority=40, text='(Test priority 2)'}) if re.match(hc.answer_header, [[^HTTP/1\.1\s403[^\r\n]+]]) and not re.match(hc.answer_header, [[^Server: HandyCache[^\r\n]+]]) then table.insert(monitor_color_array, {priority=1, color='153, 0, 0'}) end table.sort(monitor_string_array[hc.monitor_index], function(record1, record2) return record1.priority <= record2.priority end ) table.sort(monitor_color_array, function(record1, record2) return record1.priority <= record2.priority end ) local delimiter = ' - ||| - ' for i,record in ipairs(monitor_string_array[hc.monitor_index]) do monitor_string_array[hc.monitor_index][i] = record.text end for i,record in ipairs(monitor_color_array) do monitor_color_array[i] = record.color end monitor_show(table.concat(monitor_string_array[hc.monitor_index], delimiter), monitor_color_array[1].color)end
local function set_color(color, priority) local data = MY_EXTENSION_DATA[hc.monitor_index] local function rgb(r, g, b) return r + g*256 + b*256*256 end if not data.color_priority or priority < data.color_priority then data.color = rgb(table.unpack(color)) data.color_priority = priority endendfunction RequestHeaderReceived() MY_EXTENSION_DATA = MY_EXTENSION_DATA or {} MY_EXTENSION_DATA[hc.monitor_index] = { monitor_string_array={} } local data = MY_EXTENSION_DATA[hc.monitor_index] if hc.cache_file_name ~= '' then hc.action = 'dont_update' table.insert(data.monitor_string_array, {priority=10, text='Load from Cache'}) set_color({102,150,0}, 20) else hc.action = 'save' table.insert(data.monitor_string_array, {priority=11, text='Saved to Cache'}) end -- testa = monitor_color_array[#monitor_color_array].color -- for testing 1 -- hc.put_msg(1, 'Test OK: '..testa) -- for testing 2endfunction BeforeAnswerHeaderSend() local data = MY_EXTENSION_DATA[hc.monitor_index] local function monitor_show(monitor_string, monitor_color) hc.monitor_string = monitor_string if monitor_color then hc.monitor_text_color = monitor_color end end table.insert(data.monitor_string_array, {priority=5, text='(..type_define..)'}) table.insert(data.monitor_string_array, {priority=40, text='(Test priority 2)'}) if re.match(hc.answer_header, [[\A\S++\s++403\s(?!.*?^Server:\s*+HandyCache)]]) then set_color({153,0,0}, 1) end table.sort(data.monitor_string_array, function(record1, record2) return record1.priority <= record2.priority end ) local texts = {} for i,record in ipairs(data.monitor_string_array) do texts[i] = record.text end local delimiter = ' - ||| - ' monitor_show(table.concat(texts, delimiter), data.color)end