简体   繁体   中英

toggle chrome extension on/off

I have an Extension that injects css to some websites I need to have an popup where I can toggle if the extention injects the css or not. So if it's toggled on my stylesheet should be injected and if toggled off It needs to stop injecting css so page looks like normal again.

This is the css that needs to be aplied

div.answerrow {
position: static !important;
clip: auto !important;

}

.solution-layer {
display: block !important;
clip: auto !important;

}

You can use Chrome.Storage api to save the state of the toggle. Then in your content script, have javascript load the status of the toggle by what is stored in local storage. If you toggle to a different state, just save the state again with the chrome api.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM