{"size": 3003, "ext": "js", "max_stars_repo_path": "app/scripts/myft-follow.js", "max_stars_repo_name": "FTChinese/academy", "max_stars_repo_stars_event_min_datetime": "2017-03-14T07:42:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-21T07:28:00.000Z", "max_issues_repo_path": "app/scripts/myft-follow.js", "max_issues_repo_name": "FTChinese/academy", "max_issues_repo_issues_event_min_datetime": "2021-12-08T13:45:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-08T13:45:06.000Z", "max_forks_repo_path": "app/scripts/myft-follow.js", "max_forks_repo_name": "FTChinese/academy", "max_forks_repo_forks_event_min_datetime": "2016-07-02T07:17:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-24T07:31:29.000Z"}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 40.04, "max_line_length": 152, "alphanum_fraction": 0.5857475857}
// follow and unfollow topic

// click events
try {
    //var eleFollow;
    var key = 'my-ft-follow';
    if (typeof delegate === 'undefined') { 
        window.delegate = new Delegate(document.body);
    }
    delegate.on('click', '.myft-follow', function(){
        // MARK: - Since our server side developers can't figure out why the server-based MyFT doesn't work, use client side technology to enable this. 
        var isFollowed = (this.className.indexOf(' plus')>0) ? false : true;
        if (!localStorage) {
            alert ('亲爱的读者，您的浏览器不支持localStorage，请您更换现代浏览器来使用关注的功能。');
            return;
        }
        var savedFollowList = localStorage.getItem(key);
        var savedFollowListJSON = JSON.parse(savedFollowList) || {};
        var dataTag = this.getAttribute('data-tag') || '';
        var dataType = this.getAttribute('data-type') || 'tag';
        if (dataTag === '') {
            alert ('亲爱的读者，我们无法识别您关注的标签，请您刷新页面重新试试。');
            return;
        }
        if (typeof savedFollowListJSON[dataType] !== 'object') {
            savedFollowListJSON[dataType] = [];
        }
        if (isFollowed === false) {
            if (savedFollowListJSON[dataType].indexOf(dataTag)<0) {
                savedFollowListJSON[dataType].push(dataTag);
            }
        } else {
            var newSavedTags = [];
            for (var i=0; i<savedFollowListJSON[dataType].length; i++) {
                if (savedFollowListJSON[dataType][i] !== dataTag) {
                    newSavedTags.push(savedFollowListJSON[dataType][i]);
                }
            }
            savedFollowListJSON[dataType] = newSavedTags;
        }
        var newFollowList = JSON.stringify(savedFollowListJSON);
        localStorage.setItem(key, newFollowList);
        checkFollow();
    });
} catch (ignore) {

}
function checkFollow() {
    if (!localStorage) {
        alert ('亲爱的读者，您的浏览器不支持localStorage，请您更换现代浏览器来使用关注的功能。');
        return;
    }
    var savedFollowList = localStorage.getItem(key);
    var savedFollowListJSON = JSON.parse(savedFollowList) || {};
    var followButtons = document.querySelectorAll('button.myft-follow');
    for (var i=0; i < followButtons.length; i++) {
        var dataType = followButtons[i].getAttribute('data-type');
        var dataTag = followButtons[i].getAttribute('data-tag');
        if (dataTag.indexOf('%')>=0) {
            dataTag = decodeURIComponent(dataTag);
            followButtons[i].setAttribute('data-tag', dataTag);
        }
        if (typeof savedFollowListJSON[dataType] !== 'object') {
            continue;
        }
        if (savedFollowListJSON[dataType].indexOf(dataTag)>=0) {
            followButtons[i].innerHTML = '已关注';
            followButtons[i].className = followButtons[i].className.replace(/ plus/g, ' tick');
        } else {
            followButtons[i].innerHTML = '关注';
            followButtons[i].className = followButtons[i].className.replace(/ tick/g, ' plus');            
        }
    }
}
checkFollow();