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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
Copyright (C) 2017 Nathan Nichols
Copyright (C) 2022 Ruben Rodriguez <ruben@gnu.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL NATHAN NICHOLS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
console.log("background.js");
var not_executing = true;
//passive_fix_css();
var notify_id = "submit-me";
function display_multiple_forms(){
browser.notifications.create(notify_id, {
"type": "basic",
"iconUrl": browser.extension.getURL("icons/48x48.png"),
"title": "Multiple possible forms",
"message": "The website uses a submit button outside of a form.<br> Please select which form you would like to attempt to submit."
});
};
function display_single_form(){
browser.notifications.create(notify_id, {
"type": "basic",
"iconUrl": browser.extension.getURL("icons/48x48.png"),
"title": "Multiple possible forms",
"message": "The website uses a submit button outside of a form.<br> Please select which form you would like to attempt to submit."
});
};
browser.contextMenus.create({
id: "passive-submit-me-css",
title: "Reveal hidden elements",
contexts: ["all"]
});
browser.contextMenus.create({
id: "submit-me",
title: "Force submit a form",
contexts: ["all"]
});
browser.contextMenus.create({
id: "submit-me-manual",
title: "Manually choose a form to submit",
contexts: ["all"]
});
browser.contextMenus.create({
id: "submit-me-css",
title: "Remove all CSS (Try this if the website is scrambled)",
contexts: ["all"]
});
function display_manual_dialog(){
function onExecuted(result) {
console.log("manual.js executed.");
not_executing = true;
}
function onError(error) {
console.log("Error in manual.js");
console.log(error);
}
var executing = browser.tabs.executeScript({
file: "/manual.js",
allFrames: true
});
executing.then(onExecuted, onError);
}
function passive_fix_css(){
function onExecuted(result) {
console.log("passive_improve_css.js executed.");
not_executing = true;
}
function onError(error) {
//not_executing = true;
console.log("Error in passive_improve_css.js");
console.log(error);
}
var executing = browser.tabs.executeScript({
file: "/passive_improve_css.js",
allFrames: true
});
//not_executing = false;
executing.then(onExecuted, onError);
}
function fix_css(){
function onExecuted(result) {
console.log("improve_css.js executed.");
not_executing = true;
}
function onError(error) {
console.log("Error in improve_css.js");
console.log(error);
not_executing = true;
}
var executing = browser.tabs.executeScript({
file: "/improve_css.js",
allFrames: true
});
not_executing = false;
executing.then(onExecuted, onError);
}
function input(message){
if(message["msg"] == "multiple-forms"){
display_manual_dialog();
}
if(message["msg"] == "add-on-invoked"){
browser.notifications.create(notify_id, {
"type": "basic",
"iconUrl": browser.extension.getURL("icons/48x48.png"),
"title": "Submit Me",
"message": "Please click the button you would normally click to submit the broken form."
});
}
};
browser.runtime.onMessage.addListener(input);
var show = false;
browser.contextMenus.onClicked.addListener(function(info, tab) {
console.log(info);
if(info.menuItemId == "submit-me-manual" && not_executing){
not_executing = false;
display_manual_dialog();
}
if(info.menuItemId == "submit-me-css" && not_executing){
not_executing = false;
fix_css();
}
if(info.menuItemId == "passive-submit-me-css" && not_executing){
not_executing = false;
passive_fix_css();
}
if (info.menuItemId == "submit-me") {
console.log("Context menu button clicked");
function onExecuted(result) {
console.log("Main.js executed.");
}
function onError(error) {
console.log("Error in main.js");
console.log(error);
}
var executing = browser.tabs.executeScript({
file: "/main.js",
allFrames: true
});
executing.then(onExecuted, onError);
}
});
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/create
|