Created
April 18, 2018 02:24
-
-
Save xujenna/a697ea90f36f23db030523d920e33134 to your computer and use it in GitHub Desktop.
bookmarklet to chrome extension w3 hw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "%"; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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