init()
var tsvPath = ''
var titlePath = ''
var defaultStartDate
var defaultEndDate
var totalPosts
var startDate
var endDate
var wordPushList
var randId
var globKeyword = ''
var stopwords = []
function init() {
$.ajax({
type: 'POST',
url: 'ptt_push/init',
dataType: 'json',
success: function(data) {
console.log(data)
tsvString = data.Result.tsv
wordPushList = JSON.parse(data.Result.json)
stopwords = data.Result.stopwords
console.log(wordPushList)
$('#idBox').val(data.Result.author)
buildSentetree(tsvString)
}
})
$(document).ready(function() {
$(window).keydown(function(event) {
if (event.keyCode == 13) {
event.preventDefault()
sendRequest()
}
});
});
$(window).on('mousemove', function(e) {
$('#nodeTitle').css({
left: e.pageX,
top: e.pageY
})
})
$('#titleListContainer').hover(
function() { // Run on hover/mouseenter
$(this).css('overflow', 'auto')
},
function() { // Run on mouseleave
$(this).css('overflow', 'hidden')
}
)
$('#titleListLayer').click(function(e) {
if ($('#titleListLayer').is(e.target)) {
hideTitles()
}
})
$('#stopWordEditorLayer').click(function(e) {
if ($('#stopWordEditorLayer').is(e.target)) {
hideStopWordEditor()
}
})
$('#idfEditorLayer').click(function(e) {
if ($('#idfEditorLayer').is(e.target)) {
hideIdfEditor()
}
})
}
function clearStopWord() {
stopwords = []
$('#sweContainer').html('')
}
function scrollIdfList() {
let targetWord = $('#idfTarget').val()
let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { return $($(a).find("td")[0]).html() }).get()
console.log({ "targetWord": targetWord, 'list': wordList })
if (targetWord != '') {
if (wordList.indexOf(targetWord) >= 0) {
} else {
wordList.push(targetWord)
$('#ieContainer').find('tbody').append($('
').attr('class', 'w3-display-container').append($('').attr('style', 'vertical-align: middle;').append(targetWord)).append($(' | ').attr('class', 'w3-right-align').attr('style', 'vertical-align: middle;').append($('').attr('type', 'number').val(Object.keys(idfTable).indexOf(targetWord) < 0 ? 0 : idfTable[targetWord]))))
}
console.log($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position())
$("#ieTableContainer").scrollTop($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position().top - 50)
}
$('#newStopWord').val('')
}
function addStopWord() {
newswRaw = $('#newStopWord').val()
newswList = newswRaw.split(' ')
for (newsw of newswList) {
if (newsw != '') {
if (stopwords.includes(newsw)) {
} else {
stopwords.push(newsw)
$('#sweContainer').append($('').attr('class', 'w3-display-container').append($('').append(newsw)).append($('').attr('class', 'w3-button w3-hover-red w3-transparent w3-display-right').click(function(e) {
var index = $(this).parent().index()
console.log(stopwords[index])
stopwords.splice(index, 1)
console.log(stopwords)
$('#sweContainer li').eq(index).remove()
}).append("×")))
console.log(document.getElementById('sweContainer').children[stopwords.indexOf(newsw)])
}
document.getElementById("sweContainer").scrollTop = document.getElementById('sweContainer').children[stopwords.indexOf(newsw)].offsetTop
}
}
$('#newStopWord').val('')
}
function showIdfEditor() {
$(window).unbind('keydown')
$(window).keydown(function(event) {
if (event.keyCode == 13) {
scrollIdfList()
}
})
$('#ieContainer').empty().append(
$('').append($('')
.append($('')
.attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞'))
.append($(' | '))
.append($(' | ').attr('class', 'w3-right-align')
.attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞頻率')
)
)
)
.append($(' | '))
for (word of Object.entries(idfTable).sort((a, b) => { return (b[1] - a[1]) }).map((a) => { return a[0] }).slice(0, 1000)) {
$('#ieContainer').find('tbody')
.append($('')
.attr('class', 'w3-display-container')
.append($('')
.attr('style', 'vertical-align: middle;')
.append(word))
.append($(' | ')
.attr('class', 'w3-right-align')
.append($(' | |