/**
* ログを取得
*/
const get_data = () => {
return $('.talk')
.map(function() {
if (
$(this)
.find('dd p')
.children('a')
.attr('href') != null
) {
return {
id: $(this).attr('id'),
room_name: $('input[name=room_name]').val(),
name: $(this)
.find('dt')
.text(),
message: `http://drrrkari.com${$(this)
.find('dd p')
.children('a')
.attr('href')}`,
kind: 0,
createdAt: new Date()
};
}
if (
$(this)
.attr('class')
.split(' ')[1] === 'system'
) {
return {
id: $(this).attr('id'),
room_name: $('input[name=room_name]').val(),
name: 'system',
message: $(this).text(),
kind: 1,
createdAt: new Date()
};
}
return {
id: $(this).attr('id'),
room_name: $('input[name=room_name]').val(),
name: $(this)
.find('dt')
.text(),
message: $(this)
.find('dd p')
.text(),
kind: 0,
createdAt: new Date()
};
})
.get()
.reverse();
};
/**
* ローカルストレージに保存
*/
const set_storage = () => {
get_data().map(m => {
if (localStorage.getItem(m.id) === null) {
localStorage.setItem(m.id, JSON.stringify(m));
}
});
};
/**
* ローカルストレージからログを抽出
*/
const get_storage = () => {
const ng = {
['__adm_uid']: '',
['OX_net_latency']: '',
['criteo_pt_cdb_metrics']: '',
['criteo_pt_cdb_metrics_expires']: '',
['criteo_silent_mode_expires']: '',
['test']: '',
['criteo_silent_mode']: '',
['undefined']: ''
};
let _ret = [];
for (let i = 0; i < localStorage.length; i++) {
try {
const key = localStorage.key(i);
ng[key] === undefined
? _ret.push(JSON.parse(localStorage.getItem(key)))
: '';
} catch (e) {}
}
return _ret;
};
/**
* オブザーバー
*/
new MutationObserver(() => {
set_storage();
}).observe($('#talks').get(0), {
childList: true
});