I have a Chrome extension that essentially removes a button and adds 2 other HTML elements in a 3rd party web page. It does this by observing what the URL is on the current tab and if it matches the regex, it will proceed and perform the HTML injection. However, even with a fairly high-end laptop, I see a small amount of latency. The button where I set the CSS to display:none
is appearing for a fraction of a second before it is removed and replaced by my 2 HTML elements.
Is it possible to remove this latency so that the user cannot see the original button display during that fraction of a second before the js script within my Chrome extension removes it? So far I made sure the js file responsible for setting the button's property to none has this code in its first 5 lines. Is there anything in the Chrome API that will allow me to remove that button before it loads the page?
My code.js
var tabURL = window.location.href;
var origBtn = document.getElementsByClassName("Btn Btn-short Btn-primary Mend-med")[0];
if(origBtn != null) origBtn.style.display = "none";
var canProceed = correctURL(); //external method check if it matches url regex
if(canProceed == true){
var rowElm = document.getElementsByClassName("Grid-table W-100 Fz-xs Py-lg")[0];
var div = document.createElement('div');
div.innerHTML = "<div class='extelms'>\
<div class='selectContainer'>\
<select required class='form-control' name='dayselect' id='days'>\
<option value='1'>1 Day</option>\
<option value='2'>2 Days</option>\
<option value='3'>3 Days</option>\
<option value='4'>4 Days</option>\
<option value='5'>5 Days</option>\
<option value='6'>6 Days</option>\
<option value='7'>7 Days</option>\
</select>\
<button id='submit'>Submit</button>\
</div>\
</div>\
</div>";
document.getElementsByClassName("Grid-u Px-med Fz-sm Va-mid")[0].appendChild(div);
document.getElementsByClassName("Grid-u Px-med Fz-sm Va-mid")[0].style.display = '-webkit-inline-box';
}
And my manifest.json
"content_scripts": [
{
"matches": ["https://basketball.fantasysports.yahoo.com/nba/*"],
"css": ["fantasy.css"],
"js": ["js/fantasy.js"],
"run_at": "document_end"
}
]
Assuming that the replacing of HTML elements doesn't occur because the web site's elements haven't been loaded yet when I'm trying to search for the element that I'm trying to delete from the web page.