I have a .html which contains: My manifest.json looks like: } Content.js }); and finally background.js: Currently what I'm able to do it to show an alert with the names found in the page and which I'm trying to set a color to. My question is: How to set a specific color, visually visible on the screen to those elements.
Any manipulation is accepted including css/js injection, anything. I'm completly new to js and css and I'm sorry if something in the description doesn't make sense.
Opera addon, change url text color
112 Views
Asked by
Ahmed Ahmedov
At
<article class="<article ">
<div class="post">
<p>
<span class="class22">
<span class="class33">
<a class="class44" href="/whatever">TextToColor</a>
</span>
</span>
</p>
</div>
{
"manifest_version": 2,
"name": "Opera Extension",
"description": "description",
"version": "1.0"
, "background": {
"scripts": ["background.js"]
}
, "permissions": [
"tabs", "activeTab", "*://*/*", "http://*/*", "https://*/*", "file:///*/*"
]
, "web_accessible_resources": [
"fix.css"
]
, "content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"],
"all_frames": true
}]
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.text === 'getNames') {
var shouldBeColored = [];
var arrayWithNames = document.getElementsByClassName("class44");
for(var i=0; i<arrayWithNames.length; i++) {
shouldBeColored[i] = arrayWithNames[i].innerHTML;
if(shouldBeColored[i] == 'TextToColor') {
div = document.createElement( 'div' );
div.textContent = 'Upper text Should be red';
div.style['background-color'] = 'red';
arrayWithNames[i].appendChild( div );
}
}
sendResponse(shouldBeColored);
return true;
}
chrome.tabs.onUpdated.addListener(
function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.active) {
chrome.tabs.sendMessage(tab.id, {text: 'getNames'}, gotNames);
}
})
function gotNames(arrayOfNames) {
var shouldBeColored = ['TextToColor', 'TextToColor2'];
if(arrayOfNames){
for(var i=0; i<arrayOfNames.length; i++) {
if(shouldBeColored.includes(arrayOfNames[i])) {
alert(arrayOfNames[i]);
}
}
}}
There are 0 best solutions below
0