I'm writing a Chrome extension that needs to change/add link to matching words. It gets the word from what is stored inside contentscript on specific pages I have chosen.
My extension won't work and I don't understand what's wrong. My coding is not good. Would love to see it work.
The most important from manifest.json:
{
"content_scripts": [ {
"all_frames": true,
"js": [ "jquery.min.js", "contentscript.js" ],
"matches": [ "*://portal.example.no/*", "*://*.portal.example.no/*" ],
"run_at": "document_end"
} ],
"permissions": [ "*://portal.example.no/*", "*://*.portal.example.no/*", "activeTab", "storage" ],
}
The whole contentscript.js:
const data = [
//place
{
word: "Rom: A1-030",
url: "https://tv.example.com/64318737"
},
{
word: "Rom: B2-010",
url: "https://tv.example.com/64318841"
},
];
$.get(data).appendTo($('body')); })
startWorkLoop();
function getUrl(rom) {
let found = data.filter(d => {
return d.word === rom;
});
if (found.length)
return found[0].url;
else
return false;
}
function startWorkLoop(){
setInterval(function(){
work();
}, 1500);
}
async function work() {
let all = document.body.querySelectorAll("span");
if(){
$('#ext-unpaid-popup').show();
}else {
$('#ext-unpaid-popup').hide();
}
for (let i = 0; i < all.length; i++) {
let el = all[i];
if (el.innerHTML) {
let content = el.innerHTML;
let match = `${content}`.match(/Rom: [A-Z][0-9]-[0-9]+/gmi);
if (match && !el.classList.contains("rom-ext-done")) {
el.classList.add("rom-ext-done");
let m = match[0];
let url = getUrl(m);
if (url) {
content = content.replace(m, `<a style="background: green;color: #fff; padding: 2px 3px" href="${ ? url : '#'}">${m}</a>`);
} else {
content = content.replace(m, `<a style="background: red;color: #fff; padding: 2px 3px">${m} No streaming</a>`);
}
el.innerHTML = content;
}
}
}
}