This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e

View file

@ -0,0 +1,53 @@
Tips
- Bypass caching
When injecting link element for css file, the problem of caching can be annoying so append something in the url like this
```js
// Create a link element for the CSS file
const linkElement = document.createElement('link');
linkElement.rel = 'stylesheet';
linkElement.href = browser.runtime.getURL('styles.css') + '?v=' + Date.now(); // Append a timestamp
document.head.appendChild(linkElement);
```
- Reset injected element
When we inject DOM element and reload extension previous one wont get removed unless page is reloaded so tag all those inserted element with extension name or by adding it in class.
`contentScript.js`
```js
// removing elements of class of ext_name
function reset1(){
const elements=document.querySelectorAll(`.${ext_name}`)
for(let ele of elements){
ele.remove()
}
}
reset1();
const navibar= document.createElement("div")
navibar.className=`${ext_name} navigation_bar`
navibar.innerHTML=`
<button class=" nav_btn"> All Replies </button>
`
console.log('navibar: ',navibar.outerHTML);
const app=document.querySelector("body")
app.insertBefore(navibar, app.children[0])
```
&nbsp;
in firefox to allow custom extensions for permanent without uploading in firefox
Type `about:config` in the address bar and press Enter
Search for `xpinstall.signatures.required`.
Ensure the value is set to false (toggle it by double-clicking if necessary).