Said Achmiz преди 6 години
ревизия
554a0fd40f
променени са 4 файла, в които са добавени 139 реда и са изтрити 0 реда
  1. 26
    0
      contentScript.js
  2. 15
    0
      manifest.json
  3. 62
    0
      options.html
  4. 36
    0
      options.js

+ 26
- 0
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();
}
});
}

+ 15
- 0
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
}

+ 62
- 0
options.html Целия файл

@@ -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>

+ 36
- 0
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;
});

Loading…
Отказ
Запис