-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField Raider Firefox-1.77.user.js
69 lines (58 loc) · 2.11 KB
/
Field Raider Firefox-1.77.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// ==UserScript==
// @name Field Raider Firefox
// @namespace http://tampermonkey.net/
// @version 1.77
// @description Bypass field restrictions when pasting data from the clipboard (Ctrl + V and right-click paste)
// @author Seth@WiiPlaza
// @match *://*/*
// @icon https://pbs.twimg.com/media/FR11DSvX0AI1W44.png
// @grant none
// ==/UserScript==
(function () {
'use strict';
const excludeRegex = /https?:\/\/.*?\.(facebook\.com|messenger\.com|google\.com|github\.com|imgur\.com).*/;
const includeRegex = /https?:\/\/.*/;
const isRestrictedSite = () => {
const location = window.location.href;
return includeRegex.test(location) && !excludeRegex.test(location);
};
const pasteText = async (element, text) => {
element.value = text;
await simulateKeyPresses(text);
};
const simulateKeyPresses = async (text) => {
for (let i = 0; i < text.length; i++) {
await new Promise(resolve => setTimeout(resolve, 20)); // Adjust timing if necessary
const eventSpace = new KeyboardEvent('keydown', { key: ' ' });
const eventBackspace = new KeyboardEvent('keydown', { key: 'Backspace' });
document.dispatchEvent(eventSpace);
document.dispatchEvent(eventBackspace);
}
};
const allowCopyAndPaste = (e) => {
e.stopImmediatePropagation();
return true;
};
const triggerPaste = (event) => {
if (event.ctrlKey && event.key === "v") {
navigator.clipboard.readText().then(text => {
const activeElement = document.activeElement;
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
pasteText(activeElement, text);
}
});
}
};
const forceEnableCopyPaste = (e) => {
e.stopImmediatePropagation();
return true;
};
['paste', 'copy'].forEach(event => {
document.addEventListener(event, forceEnableCopyPaste, true);
});
document.addEventListener('keyup', triggerPaste, false);
if (isRestrictedSite()) {
document.addEventListener('copy', allowCopyAndPaste, true);
document.addEventListener('paste', allowCopyAndPaste, true);
}
})();