浏览代码

Broke out shared code into functions.js

master
Said Achmiz 6 年前
父节点
当前提交
887c8a89e9
共有 4 个文件被更改,包括 44 次插入33 次删除
  1. 2
    9
      contentScript.js
  2. 41
    0
      functions.js
  3. 1
    0
      options.html
  4. 0
    24
      options.js

+ 2
- 9
contentScript.js 查看文件

@@ -29,12 +29,5 @@ function killStickyIfMatch(result) {
}
}
if (!killSticky) return;
console.log("Killing all stickies!");
document.querySelectorAll('body *').forEach(element => {
if (getComputedStyle(element).position === 'fixed' ||
getComputedStyle(element).position === 'sticky') {
element.remove();
}
});
}
killSticky();
}

+ 41
- 0
functions.js 查看文件

@@ -0,0 +1,41 @@
/*******************************/
/* 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);
}

/***********/
/* HELPERS */
/***********/

function killSticky() {
console.log("Killing all stickies!");
document.querySelectorAll('body *').forEach(element => {
if (getComputedStyle(element).position === 'fixed' ||
getComputedStyle(element).position === 'sticky') {
element.remove();
}
});
}

String.prototype.hasPrefix = function (prefix) {
return (this.lastIndexOf(prefix, 0) === 0);
}

+ 1
- 0
options.html 查看文件

@@ -208,5 +208,6 @@
</div>
<p>NOTE: Exclusion patterns override matching patterns; if a page is <em>both</em> matched <em>and</em> excluded, stickies will <strong>not</strong> be killed on that page.</p>
</body>
<script src="functions.js"></script>
<script src="options.js"></script>
</html>

+ 0
- 24
options.js 查看文件

@@ -1,27 +1,3 @@
/*******************************/
/* 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);
}

/*******************/
/* EVENT LISTENERS */
/*******************/

正在加载...
取消
保存