// When the popup HTML has loaded
window.addEventListener('load', function (evt) {
var btnGetKeyWord = document.getElementById('btnGetKeyWord');
var lblFeedback = document.getElementById('lblFeedback');
var txtResult = document.getElementById('txtResult');
var btnCopy = document.getElementById('btnCopy');
// Get Keyword
btnGetKeyWord.onclick = function () { // Error
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { method: "getTag" }, function (response) {
if (response == undefined || response.method !== "getTag" || response.data == '') {
lblFeedback.innerHTML = 'Ключевые слова не найденны =(.';
lblFeedback.className = "alert alert-danger";
return;
}
txtResult.innerHTML = response.data;
lblFeedback.innerHTML = 'Найденно ' + response.count + ' ключевых слов.';
lblFeedback.className = "alert alert-success";
});
});
};
// Function Copy
btnCopy.onclick = function () {
if (txtResult.innerHTML.indexOf('How to Use') !== -1) {
lblFeedback.innerHTML = 'Active when keyword is detected.';
lblFeedback.className = "alert alert-danger";
return;
}
if (lblFeedback.innerHTML.indexOf('Copied') == -1 && lblFeedback.innerHTML.indexOf('Not found tag.') === -1) {
lblFeedback.innerHTML = lblFeedback.innerHTML + ' Скопированно!!';
lblFeedback.className = "alert alert-success";
}
txtResult.select();
document.execCommand('copy');
};
});