| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /*******************************/
- /* 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);
- }
-
- /***********/
- /* UTILITY */
- /***********/
-
- String.prototype.hasPrefix = function (prefix) {
- return (this.lastIndexOf(prefix, 0) === 0);
- }
-
- /***********/
- /* HELPERS */
- /***********/
-
- /* This function sends a message to the background script (background.js),
- which then updates the page action icon (i.e., the browser toolbar icon)
- to reflect whether killing stickies is enabled on the current page.
- */
- function updateIcon(shouldKillSticky, tabID) {
- chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky, "tabID": tabID });
- }
-
- /* This is the code that actually does the sticky killing! It simply selects
- all elements whose 'position' CSS property has a computed value of either
- 'sticky' or 'fixed', and removes those elements.
- */
- function killSticky() {
- console.log("Killing all stickies!");
- document.querySelectorAll('body *').forEach(element => {
- if (getComputedStyle(element).position === 'fixed' ||
- getComputedStyle(element).position === 'sticky') {
- element.remove();
- }
- });
- }
|