<commit_before>var meaningDisplayFlag = false;
var meaning, word, context;

var backend = chrome.runtime.connect({name: "connectionToBackend"});

$(document).ready(function () {
    $(document).dblclick(function(e){
        // Don't show meaning on double click on input
        if ($(document.activeElement).is('input, textarea')) {
            return false;
        }

        var wordObject = window.getSelection();
        word = $.trim(wordObject.toString().toLowerCase());
        var result = word.split(/[\n\r\s]+/);
        // To disable multiple words selection
        // and null selection
        if (result.length != 1 || word == '') {
            return;
        }

        showQtip(document, e);
        fetchMeaningCambridge(word, function(message){
            meaning = message;
            changeQtipText(meaning);
            meaningDisplayFlag = true;
        });

        context = getContext(wordObject);
        console.log(context);
    });

    $(document).on('mousedown', function(){
        if (!meaningDisplayFlag) {
            return;
        }

        if (meaning === noMeaningFoundError || meaning == otherError) {
            // Don't save the word
            return;
        }

        backend.postMessage({type: "saveWord", word: word, meaning: meaning, context: context});
        meaningDisplayFlag = false;
    });
});

function showQtip(selector, e) {
    $(selector).qtip({
        id: 'meaningTooltip',
        content: {
            text: "Searching for meaning....."
        },

        position: {
            target: [e.pageX, e.pageY],
            viewport: $(window),
            adjust: {
                y: 12,
                mouse: false
            }
        },

        show: {
            ready: true
        },

        style: {
            width: "250px",
            height: "100px"
        },

        hide: {
            event: 'mousedown'
        },

        events: {
            hide: function(event, api) {
                api.destroy();
            }
        }
    });

    meaningDisplayFlag = true;
}


function changeQtipText(newText) {
    $('#qtip-meaningTooltip').qtip('option', 'content.text', newText);
}


// Listen for incoming requests from browser_action script
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.method == "getSelection") {
        sendResponse({data: window.getSelection().toString(), context:getContext(window.getSelection())});<commit_msg>Don't show meaning of word if it contains special symbols<commit_after>var meaningDisplayFlag = false;
var meaning, word, context;

var backend = chrome.runtime.connect({name: "connectionToBackend"});

$(document).ready(function () {
    $(document).dblclick(function(e){
        // Don't show meaning on double click on input
        if ($(document.activeElement).is('input, textarea')) {
            return;
        }

        var wordObject = window.getSelection();
        word = $.trim(wordObject.toString().toLowerCase());
        var result = word.split(/[\n\r\s]+/);
        // To disable multiple words selection
        // and null selection
        if (result.length != 1 || !isValidInput(word)) {
            return;
        }

        showQtip(document, e);
        fetchMeaningCambridge(word, function(message){
            meaning = message;
            changeQtipText(meaning);
            meaningDisplayFlag = true;
        });

        context = getContext(wordObject);
        console.log(context);
    });

    $(document).on('mousedown', function(){
        if (!meaningDisplayFlag) {
            return;
        }

        if (meaning === noMeaningFoundError || meaning == otherError) {
            // Don't save the word
            return;
        }

        backend.postMessage({type: "saveWord", word: word, meaning: meaning, context: context});
        meaningDisplayFlag = false;
    });
});

function showQtip(selector, e) {
    $(selector).qtip({
        id: 'meaningTooltip',
        content: {
            text: "Searching for meaning....."
        },

        position: {
            target: [e.pageX, e.pageY],
            viewport: $(window),
            adjust: {
                y: 12,
                mouse: false
            }
        },

        show: {
            ready: true
        },

        style: {
            width: "250px",
            height: "100px"
        },

        hide: {
            event: 'mousedown'
        },

        events: {
            hide: function(event, api) {
                api.destroy();
            }
        }
    });

    meaningDisplayFlag = true;
}


function changeQtipText(newText) {
    $('#qtip-meaningTooltip').qtip('option', 'content.text', newText);
}

function isValidInput(string) {
    if(/^[a-zA-Z]+$/.test(string) == false) {
        return false;
    } else {
        return true;
    }
}

// Listen for incoming requests from browser_action script
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
    if (request.method == "getSelection") {
        sendResponse({data: window.getSelection().toString(), context:getContext(window.getSelection())});
{'fraction_non_alphanumeric': 0.1352975382826129, 'fraction_numerical': 0.003489048265167668, 'mean_word_length': 1.8923766816143497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6913637', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1374, 'n_words': 306}