Skip to content

Instantly share code, notes, and snippets.

@xujenna
Created April 18, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xujenna/a697ea90f36f23db030523d920e33134 to your computer and use it in GitHub Desktop.
Save xujenna/a697ea90f36f23db030523d920e33134 to your computer and use it in GitHub Desktop.
bookmarklet to chrome extension w3 hw
console.log('Content Script via Browser Action background page, version 1');
// Docs for 'onClicked' are here:
// https://developer.chrome.com/extensions/browserAction#event-onClicked
chrome.browserAction.onClicked.addListener(function() {
console.log('Clicked the browser action!');
chrome.tabs.executeScript({file: 'content_script.js'}, function() {
console.log('background script injected content_script');
});
});
const e = document.createElement("div");
e.style.width="100%";
e.style.position="fixed";
e.style.bottom="0px";
e.style.backgroundColor="red";
e.style.height="10px";
document.body.appendChild(e);
window.addEventListener("scroll",function(){
var t = document.body.scrollHeight-innerHeight;
e.style.height= (pageYOffset / t) * 100 + "%";
});
{
"name": "Content Script Via Browser Action",
"manifest_version": 2,
"version": "0.1",
"description": "Append a progress bar that obscures the entire window as you scroll",
"browser_action": {
"default_icon": "rocket.png",
"default_title": "Make page red!"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment