Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\extension\\popup\\popup.js"
}
]
}
32 changes: 32 additions & 0 deletions extension/plugins/content/DeleteHighlightedText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ContentPlugin from "../../lib/ContentPlugin.js";

class DeleteHighlightedText extends ContentPlugin {
constructor() {
super("Deletes Highlighted Text");
}

id = "DTH";

settings = {
enabled: false,
};

run() {
function deleteContent() {
if (window.getSelection) {
var sel = window.getSelection();
if (sel.rangeCount) {
var range = sel.getRangeAt(0).cloneRange();
range.deleteContents();
sel.removeAllRanges();
sel.addRange(range);
}
}
}
document.onmouseup = deleteContent;
}

cleanup() {}
}

export default DeleteHighlightedText;
2 changes: 2 additions & 0 deletions extension/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RandomElementFocus from './content/RandomElementFocus.js';
import KeyRepeat from './content/KeyRepeat.js';
import HideCursorRandomly from './content/HideCursorRandomly.js';
import RedirectToRandomTranslation from './content/RedirectToRandomTranslation.js';
import DeleteHighlightedText from './content/DeleteHighlightedText.js';

export default [
new RandomDiscordNotification(),
Expand All @@ -32,4 +33,5 @@ export default [
new KeyRepeat(),
new HideCursorRandomly(),
new RedirectToRandomTranslation(),
new DeleteHighlightedText(),
];
81 changes: 52 additions & 29 deletions extension/popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
import plugins from '../plugins/index.js';
import plugins from "../plugins/index.js";

const contentElement = document.querySelector('#content-menu');
const backgroundElement = document.querySelector('#background-menu');
const contentElement = document.querySelector("#content-menu");
const backgroundElement = document.querySelector("#background-menu");

plugins.forEach((plugin) => {
const plugin_id = `plugin_${plugin.id}`;
chrome.storage.local.get(plugin_id, (savedSettings) => {
savedSettings = savedSettings[plugin_id] || plugin.settings;
const labelElement = document.createElement('label');
labelElement.setAttribute('for', plugin_id);
const inputElement = document.createElement('input');
inputElement.setAttribute('type', 'checkbox');
inputElement.setAttribute('id', plugin_id);
inputElement.setAttribute('name', plugin_id);
inputElement.setAttribute('role', 'switch');
inputElement.checked = savedSettings.enabled;
inputElement.addEventListener('input', () => {
savedSettings.enabled = inputElement.checked;
chrome.storage.local.set({
[plugin_id]: savedSettings,
const checkDay = function () {
const today = new Date();
const todayMonth = today.getMonth();
const todayDay = today.getDate();
const aprilFool = new Date(2022, 3, 1);
const foolMonth = aprilFool.getMonth();
const foolDay = aprilFool.getDate();

return foolMonth === todayMonth && foolDay === todayDay;
};

if (checkDay()) {
plugins.forEach((plugin) => {
const plugin_id = `plugin_${plugin.id}`;
chrome.storage.local.get(plugin_id, (savedSettings) => {
savedSettings = savedSettings[plugin_id] || plugin.settings;
const labelElement = document.createElement("label");
labelElement.setAttribute("for", plugin_id);
const inputElement = document.createElement("input");
inputElement.setAttribute("type", "checkbox");
inputElement.setAttribute("id", plugin_id);
inputElement.setAttribute("name", plugin_id);
inputElement.setAttribute("role", "switch");
inputElement.checked = savedSettings.enabled;
inputElement.addEventListener("input", () => {
savedSettings.enabled = inputElement.checked;
chrome.storage.local.set({
[plugin_id]: savedSettings,
});
});
const spanElement = document.createElement("span");
spanElement.textContent = plugin.name;
labelElement.append(inputElement);
labelElement.append(spanElement);
if (plugin.type === "background") {
backgroundElement.append(labelElement);
} else if (plugin.type === "content") {
contentElement.append(labelElement);
}
});
const spanElement = document.createElement('span');
spanElement.textContent = plugin.name;
labelElement.append(inputElement);
labelElement.append(spanElement);
if (plugin.type === 'background') {
backgroundElement.append(labelElement);
} else if (plugin.type === 'content') {
contentElement.append(labelElement);
}
});
});
} else {
document.body.innerHTML = "";
document.body.style.width = "500px";
document.body.style.height = "500px";
const header = document.createElement("h1");
header.textContent =
"CAN ONLY WORK ON APRIL FOOLS DAY!!! Come back then for more fun!";
header.style.textAlign = "center";
header.style.padding = "50px";
document.body.append(header);
}