commit 554a0fd40fb21383ddb008a3189857727d205a6f Author: achmizs Date: Tue Jan 29 13:47:01 2019 -0500 Initial commit diff --git a/contentScript.js b/contentScript.js new file mode 100644 index 0000000..489dcdf --- /dev/null +++ b/contentScript.js @@ -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(); + } + }); +} \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..c0a719d --- /dev/null +++ b/manifest.json @@ -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 +} \ No newline at end of file diff --git a/options.html b/options.html new file mode 100644 index 0000000..b4a2dbe --- /dev/null +++ b/options.html @@ -0,0 +1,62 @@ + + + + Always Kill Sticky - Options + + + + +

Always Kill Sticky

+

Enter a list of regular expression patterns to match URLs, one per line. Stickies will be killed on pages matching those patterns.

+ +
+ + + \ No newline at end of file diff --git a/options.js b/options.js new file mode 100644 index 0000000..20c290b --- /dev/null +++ b/options.js @@ -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; +}); \ No newline at end of file