| @@ -0,0 +1,26 @@ | |||
| window.onload = () => { | |||
| chrome.storage.sync.get("patterns", (result) => { | |||
| killStickyIfMatch(result.patterns); | |||
| }); | |||
| }; | |||
| function killStickyIfMatch(patterns) { | |||
| if (typeof patterns == "undefined") return; | |||
| patterns = patterns.split("\n"); | |||
| var killSticky = false; | |||
| for (let pattern of patterns) { | |||
| if (location.href.match(new RegExp(pattern))) { | |||
| killSticky = true; | |||
| break; | |||
| } | |||
| } | |||
| if (!killSticky) return; | |||
| console.log("Killing all stickies!"); | |||
| document.querySelectorAll('body *').forEach(element => { | |||
| if (getComputedStyle(element).position === 'fixed' || | |||
| getComputedStyle(element).position === 'sticky') { | |||
| element.remove(); | |||
| } | |||
| }); | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| { | |||
| "name": "AlwaysKillSticky", | |||
| "version": "0.1", | |||
| "description": "Get rid of fixed elements on websites - permanently!", | |||
| "permissions": [ "activeTab", "storage" ], | |||
| "content_scripts": [ | |||
| { | |||
| "matches": [ "http://*/*", "https://*/*" ], | |||
| "run_at": "document_end", | |||
| "js": [ "contentScript.js" ] | |||
| } | |||
| ], | |||
| "options_page": "options.html", | |||
| "manifest_version": 2 | |||
| } | |||
| @@ -0,0 +1,62 @@ | |||
| <!DOCTYPE html> | |||
| <html> | |||
| <head> | |||
| <title>Always Kill Sticky - Options</title> | |||
| <meta name="viewport" content="width=device-width, initial-scale=1"/> | |||
| <style> | |||
| html { | |||
| box-sizing: border-box; | |||
| font-size: 16px; | |||
| } | |||
| *, *::before, *::after { | |||
| box-sizing: inherit; | |||
| } | |||
| body { | |||
| margin: 0 auto; | |||
| display: flex; | |||
| flex-flow: column; | |||
| max-width: 640px; | |||
| min-height: 100vh; | |||
| padding: 10px; | |||
| font-size: 1rem; | |||
| } | |||
| textarea { | |||
| min-height: 400px; | |||
| border: 1px solid #bbb; | |||
| font-family: Inconsolata, Courier, monospace; | |||
| font-size: 1.125rem; | |||
| } | |||
| form { | |||
| text-align: right; | |||
| } | |||
| button { | |||
| -webkit-appearance: none; | |||
| -moz-appearance: none; | |||
| border: 1px solid #99; | |||
| font-size: 1.5rem; | |||
| color: #fff; | |||
| margin: 1em auto; | |||
| padding: 10px 16px; | |||
| background-color: #16e; | |||
| cursor: default; | |||
| } | |||
| button:active { | |||
| transform: scale(0.95); | |||
| } | |||
| button:focus:active { | |||
| outline: none; | |||
| } | |||
| button:disabled { | |||
| filter: saturate(0); | |||
| opacity: 0.5; | |||
| } | |||
| </style> | |||
| </head> | |||
| <body> | |||
| <h1>Always Kill Sticky</h1> | |||
| <p>Enter a list of <a href='https://regexr.com/' rel='nofollow'>regular expression</a> patterns to match URLs, one per line. Stickies will be killed on pages matching those patterns.</p> | |||
| <textarea spellcheck="false"></textarea> | |||
| <form><button disabled type='button'>Save</button></form> | |||
| </body> | |||
| <script src="options.js"></script> | |||
| </html> | |||
| @@ -0,0 +1,36 @@ | |||
| /*******************************/ | |||
| /* EVENT LISTENER MANIPULATION */ | |||
| /*******************************/ | |||
| /* Adds an event listener to a button (or other clickable element), attaching | |||
| it to both "click" and "keyup" events (for use with keyboard navigation). | |||
| Optionally also attaches the listener to the 'mousedown' event, making the | |||
| element activate on mouse down instead of mouse up. */ | |||
| Element.prototype.addActivateEvent = function(func, includeMouseDown) { | |||
| let ael = this.activateEventListener = (event) => { if (event.button === 0 || event.key === ' ') func(event) }; | |||
| if (includeMouseDown) this.addEventListener("mousedown", ael); | |||
| this.addEventListener("click", ael); | |||
| this.addEventListener("keyup", ael); | |||
| } | |||
| /* Removes event listener from a clickable element, automatically detaching it | |||
| from all relevant event types. */ | |||
| Element.prototype.removeActivateEvent = function() { | |||
| let ael = this.activateEventListener; | |||
| this.removeEventListener("mousedown", ael); | |||
| this.removeEventListener("click", ael); | |||
| this.removeEventListener("keyup", ael); | |||
| } | |||
| document.querySelector("button").addActivateEvent((event) => { | |||
| event.target.blur(); | |||
| let text = document.querySelector("textarea").value; | |||
| chrome.storage.sync.set({ "patterns": text }, () => { | |||
| event.target.disabled = true; | |||
| }); | |||
| }); | |||
| document.querySelector("textarea").addEventListener("input", (event) => { | |||
| document.querySelector("button").disabled = false; | |||
| }); | |||