<commit_before>
/*
 * yattuke shigoto.js
 * 酷いコードですね
 */

const B_URL = 'http://b.hatena.ne.jp/';
const CMD_EVENT_NAME = 'hBookmark-view-comments';
const SHOW_PREFS_NAME = 'extensions.hatenabookmark.commentviwer.allShow';
/*
 * comment.html から、外部 html リンクが開けてしまうと、セキュリティ的にまずいので注意
 */

window.addEventListener('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
    let link;
    let t = e.target;
    if (t.id == 'close-button-img') 
        return close();
    if (t.id == 'toggle-button-img') 
        return toggle();
    if (t.tagName == 'A') {
        link = t.href;
    } else if (t.tagName == 'IMG') {
        if (t.parentNode.tagName == 'A') {
            link = t.parentNode.href;
        }
    }
    // openUILink(link, e);
    if (link) {
        openUILinkIn(link, 'tab');
        close();
    }
}, false);

window.addEventListener('DOMContentLoaded', function() {
    setCommentView();
}, false);

var toggle = function() {
    Application.prefs.get(SHOW_PREFS_NAME).value = !Application.prefs.get(SHOW_PREFS_NAME).value;
    setCommentView();
    posCalc();
}

var posCalc = function() {
    // let rect = document.body.getBoundingClientRect();
    let rect = $('list').getBoundingClientRect();
    let height = parseInt(rect.bottom) - parseInt(rect.top) + 100; // うーん
    p('height: ' + height);
    window.scrollTo(0, 0);
    throwEvent('rendered', {
        height: parseInt(height),
    });
}

var setCommentView = function() {
    let src;
    if (Application.prefs.get(SHOW_PREFS_NAME).value) {
         src = "chrome://hatenabookmark/skin/images/comment-viewer-toggle-on.png";
         $('list').className = '';
         if ($('nocomment-message')) {
             $('nocomment-message').style.display = 'none';
         }
    } else {
         src = "chrome://hatenabookmark/skin/images/comment-viewer-toggle-off.png";
         $('list').className = 'nocommentall';
         if ($('nocomment-message')) {
             $('nocomment-message').style.display = 'block';
         }
    }
    $('toggle-button-img').src = src;
}

let lastEID = null;

var dispatchMethods = {
    'load-json': function(data) {
        if (!data) {
            clear();
            return;
        } else {
            // 同じ eid なら描画し直さない
            if (data.url && data.url == lastEID) {
                return;
            } else {
                lastEID = data.url;
                clear();
            }
        }
        $('favicon').src = data.favicon;
        $('title').appendChild(T(data.title || data.url));
        let cEL = $('count');
        setCommentView();

        p('hoge');
        if (data.count) {
            let c = data.count;
            cEL.innerHTML = '' + c + ' user' + ((c > 1) ? 's' : '');
            cEL.className = 'users';
            cEL.href = data.entry_url;
        } else {
            cEL.href = '';
            cEL.className = '';
        }
        p('huga');
        p.b(function() {
            if (data.bookmarks && data.bookmarks.length) {
                let commentFlag = false;
                let len = data.bookmarks.length;
                for (let i = 0;  i < len; i++) {
                    let b = data.bookmarks[i];
                    let li = E('li');
                    let userlink = B_URL + b.user + '/';
                    let ymd = b.timestamp.split(' ')[0];
                    let permalink = userlink + ymd.replace(/\//g, '') + '#' + data.eid;
                    let icon = userIcon(b.user);
                    li.appendChild(E('a', {href: permalink, className: 'user-permalink'}, icon));
                    li.appendChild(E('a', {href: permalink, className: 'username'}, b.user));
                    if (b.tags) b.tags.forEach(function(tag, index) {
                        let userlinkTag = userlink + '/t/' + encodeURIComponent(tag);
                        if (index) li.appendChild(T(', '));<commit_msg>truncate<commit_after>
/*
 * yattuke shigoto.js
 * 酷いコードですね
 */

const B_URL = 'http://b.hatena.ne.jp/';
const CMD_EVENT_NAME = 'hBookmark-view-comments';
const SHOW_PREFS_NAME = 'extensions.hatenabookmark.commentviwer.allShow';
/*
 * comment.html から、外部 html リンクが開けてしまうと、セキュリティ的にまずいので注意
 */


window.addEventListener('click', function(e) {
    e.preventDefault();
    e.stopPropagation();
    let link;
    let t = e.target;
    if (t.id == 'close-button-img') 
        return close();
    if (t.id == 'toggle-button-img') 
        return toggle();
    if (t.tagName == 'A') {
        link = t.href;
    } else if (t.tagName == 'IMG') {
        if (t.parentNode.tagName == 'A') {
            link = t.parentNode.href;
        }
    }
    // openUILink(link, e);
    if (link) {
        openUILinkIn(link, 'tab');
        close();
    }
}, false);

window.addEventListener('DOMContentLoaded', function() {
    setCommentView();
}, false);

var toggle = function() {
    Application.prefs.get(SHOW_PREFS_NAME).value = !Application.prefs.get(SHOW_PREFS_NAME).value;
    setCommentView();
    posCalc();
}

var posCalc = function() {
    // let rect = document.body.getBoundingClientRect();
    let rect = $('list').getBoundingClientRect();
    let height = parseInt(rect.bottom) - parseInt(rect.top) + 100; // うーん
    p('height: ' + height);
    window.scrollTo(0, 0);
    throwEvent('rendered', {
        height: parseInt(height),
    });
}

var setCommentView = function() {
    let src;
    if (Application.prefs.get(SHOW_PREFS_NAME).value) {
         src = "chrome://hatenabookmark/skin/images/comment-viewer-toggle-on.png";
         $('list').className = '';
         if ($('nocomment-message')) {
             $('nocomment-message').style.display = 'none';
         }
    } else {
         src = "chrome://hatenabookmark/skin/images/comment-viewer-toggle-off.png";
         $('list').className = 'nocommentall';
         if ($('nocomment-message')) {
             $('nocomment-message').style.display = 'block';
         }
    }
    $('toggle-button-img').src = src;
}

let lastEID = null;

var dispatchMethods = {
    'load-json': function(data) {
        if (!data) {
            clear();
            return;
        } else {
            // 同じ eid なら描画し直さない
            if (data.url && data.url == lastEID) {
                return;
            } else {
                lastEID = data.url;
                clear();
            }
        }
        $('favicon').src = data.favicon;
        let titleStr = data.title || data.url || '';
        if (titleStr.length > 60) titleStr = titleStr.substring(0, 58) + '...';
        $('title').appendChild(T(titleStr));
        let cEL = $('count');
        setCommentView();

        if (data.count) {
            let c = data.count;
            cEL.innerHTML = '' + c + ' user' + ((c > 1) ? 's' : '');
            cEL.className = 'users';
            cEL.href = data.entry_url;
        } else {
            cEL.href = '';
            cEL.className = '';
        }
        p.b(function() {
            if (data.bookmarks && data.bookmarks.length) {
                let commentFlag = false;
                let len = data.bookmarks.length;
                for (let i = 0;  i < len; i++) {
                    let b = data.bookmarks[i];
                    let li = E('li');
                    let userlink = B_URL + b.user + '/';
                    let ymd = b.timestamp.split(' ')[0];
                    let permalink = userlink + ymd.replace(/\//g, '') + '#' + data.eid;
                    let icon = userIcon(b.user);
                    li.appendChild(E('a', {href: permalink, className: 'user-permalink'}, icon));
                    li.appendChild(E('a', {href: permalink, className: 'username'}, b.user));
                    if (b.tags) b.tags.forEach(function(tag, index) {
                        let userlinkTag = userlink + '/t/' + encodeURIComponent(tag);
                        if (index) li.appendChild(T(', '));
{'fraction_non_alphanumeric': 0.1656293661882383, 'fraction_numerical': 0.002667344087387273, 'mean_word_length': 1.8091330717088834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799715', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2552, 'n_words': 469}