/
popup.js
40 lines (36 loc) · 1.48 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Makes links work.
window.addEventListener('click',function(e){
if(e.target.href!==undefined){
chrome.tabs.create({url:e.target.href})
}
})
function setStatus(newstat) {
document.getElementById('status').textContent = newstat;
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('logo').setAttribute('src', ocra_logo_image);
setStatus(ocra_status_start);
chrome.tabs.executeScript({file: 'content.js'}, function(data) {
if ( undefined !== data && data[0].length > 0 ) {
data[0].forEach(function(m) {
el = document.getElementById(m.type);
el.removeAttribute('hidden');
lst = el.getElementsByTagName('ul')[0];
if ( 'page' == m.type ) {
document.getElementById('thispage').removeAttribute('hidden');
lnkurl = ocra_target_page+'?'+m.clas+'='+m.match;
lnk = '<b>'+m.label+':</b> <a href="'+lnkurl+'">'+m.match+'</a>';
} else {
document.getElementById('otherids').removeAttribute('hidden');
lnkurl = ocra_target_page+'?'+m.type+'='+m.match;
lnk = '<a href="'+lnkurl+'">'+m.match+'</a>';
}
lst.innerHTML += "<li>"+lnk+"</li>\n";
});
setStatus(ocra_status_ready);
$('#tabName').blur();
} else {
setStatus(ocra_status_nothing_to_do);
}
});
});