var commentsInfo var tsvString var stopwords = ["妳", "的", "是", "在", "卻", "也", "了", "而", "要", "啊", "阿", "又", "有", "不", "我", "都", "就", "會", "完整", "新聞", "標題", "內文", "之", "你", "還", "人", "嗎", "沒", "跟", "說", "他", "我", "在", "被", "可以", "請", "來", "但", "沒有", "就是", "想", "讓", "自己", "對", "去", "到", "這", "大家", "才", "我們", "好", "用", "過", "啦", "後", "知道", "做", "很", "上", "她", "短", "網址", "備註", "連結", "或", "已", "把", "那", "只", "所以", "講"] var url = [ 'https://www.dcard.tw/f/mood/p/234367759', 'https://www.dcard.tw/f/relationship/p/234367304', 'https://www.dcard.tw/f/trending/p/234366829' ] init() function init() { $(window).on('mousemove', function(e) { $('#nodeTitle').css({ left: e.pageX, top: e.pageY }) }) changeData(1) $('#idfEditorLayer').click(function(e) { if ($('#idfEditorLayer').is(e.target)) { hideIdfEditor() } }) } 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 changeData(num) { $('#linkToPostButton').unbind() $('#linkToPostButton').click(() => { window.open(url[num - 1]) }) if (([1, 2, 3]).indexOf(num) >= 0) { $.ajax({ url: '/resource/dcardPosts/' + num + '.tsv', async: false, success: (data) => { tsvString = data } }) $.ajax({ url: '/resource/dcardPosts/' + num + '.json', async: false, success: (data) => { commentsInfo = data } }) buildSentetree() return } } 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($('