-
Notifications
You must be signed in to change notification settings - Fork 0
/
spamcop-tweaks.js
188 lines (168 loc) · 6.78 KB
/
spamcop-tweaks.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// ==UserScript==
// @name Spamcop tweaks
// @namespace http://wikberg.fi/userscript/spamcop
// @version 0.6
// @description Add functionality to Spamcop reporting page
// @author Michael Wikberg
// @include /^https://www.spamcop.net/(sc(\?id.*)?)?$/
// @grant unsafeWindow
// @copyright 2016 Michael Wikberg \[email protected]>
// @license GPLv3
// @updateURL https://github.com/milkboy/userscripts/raw/master/spamcop-tweaks.js
// ==/UserScript==
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined')
{ window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; run(); }
}
GM_wait();
var JQueryScript = document.createElement("script");
JQueryScript.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js");
JQueryScript.setAttribute("type", "text/javascript");
document.body.appendChild(JQueryScript);
function run() {
var url = '' + window.location;
if(url.match(/^https:\/\/www\.spamcop\.net\/sc\?id.*$/)) {
runSend();
}
else {
runAutoadvance();
}
}
function runAutoadvance() {
$("a").each(function() {
if($(this).attr('href').match(/sc\?id=.*/)) {
$(this).click(function(e) {
e.preventDefault();
});
$(this).css('color', 'red');
$(this).text('Loading');
window.location.href = $(this).attr('href');
}
});
}
function runSend () {
'use strict';
var $ = jQuery;
var nosendto, nosendtosrc, nosendtoisrc, nosendtoweb, nosendtoiweb, nosendtointermediary, source;
var runningNumberRe = /[a-z]*(\d+)/;
//we have some data?
if(typeof localStorage.getItem('nosendtosrc') === 'undefined' || localStorage.getItem('nosendtosrc') === null) {
nosendtosrc = [];
} else {
nosendtosrc = JSON.parse(localStorage.getItem('nosendtosrc'));
}
if(typeof localStorage.getItem('nosendtoisrc') === 'undefined' || localStorage.getItem('nosendtoisrc') === null) {
nosendtoisrc = [];
} else {
nosendtoisrc = JSON.parse(localStorage.getItem('nosendtoisrc'));
}
if(typeof localStorage.getItem('nosendtoweb') === 'undefined' || localStorage.getItem('nosendtoweb') === null) {
nosendtoweb = [];
} else {
nosendtoweb = JSON.parse(localStorage.getItem('nosendtoweb'));
}
if(typeof localStorage.getItem('nosendtoiweb') === 'undefined' || localStorage.getItem('nosendtoiweb') === null) {
nosendtoiweb = [];
} else {
nosendtoiweb = JSON.parse(localStorage.getItem('nosendtoiweb'));
}
if(typeof localStorage.getItem('nosendtointermediary') === 'undefined' || localStorage.getItem('nosendtointermediary') === null) {
nosendtointermediary = [];
} else {
nosendtointermediary = JSON.parse(localStorage.getItem('nosendtointermediary'));
}
console.log("Don't send to sources: " + JSON.stringify(nosendtosrc));
console.log("Don't send to third party source: " + JSON.stringify(nosendtoisrc));
console.log("Don't send to www: " + JSON.stringify(nosendtoweb));
console.log("Don't send to third party web: " + JSON.stringify(nosendtoisrc));
console.log("Don't send to intermediary parties: " + JSON.stringify(nosendtointermediary));
$("input[name^='master']").each(function(index) {
source = $("[name^='type']", $(this).parent()).val();
console.log('Found email address for ' + source + ': ' + $(this).val());
nosendto = getList(source);
if($.inArray($(this).val(), nosendto) >= 0) {
if($("input[name^='master']").length <= 1 && source == 'source') {
//Only 0-1 recipient(s). don't uncheck
console.log("Less than 2 recipients, not unchecking " + $(this).val());
} else {
//Uncheck
var num = $(this).attr("name").match(runningNumberRe)[1];
console.log($(this).attr("name"));
console.log("Not sending to " + $(this).val());
$("[name='send" + num + "']", $(this).parent()).prop('checked', false);
}
}
});
$("[name^='send'] [type='checkbox']").change(function(asd) {
var num = $(this).attr("name").match(runningNumberRe)[1];
source = $("[name='type" + num + "']").val();
nosendto = getList(source);
console.log(source + ": " + $("[name='master" + num + "']").val() + " changed. ");
if($(this).prop('checked')) {
doSendTo(source, nosendto, $("[name='master" + num + "']").val());
} else {
dontSendTo(source, nosendto, $("[name='master" + num + "']").val());
}
});
function getList(source) {
console.log("Getting list for " + source);
switch(source) {
case 'i-source':
return nosendtoisrc;
case 'source':
return nosendtosrc;
case 'www':
return nosendtoweb;
case 'i-www':
return nosendtoiweb;
case 'intermediary':
return nosendtointermediary;
default:
alert("Unknown type: " + source);
return [];
}
}
function doSendTo(source, nosendto, address) {
var pos = nosendto.indexOf(address);
console.log(source + ": Will be sending alerts to " + address);
if(pos >= 0) {
nosendto.splice(pos, 1);
}
save(source, nosendto);
}
function dontSendTo(source, nosendto, address) {
var pos = nosendto.indexOf(address);
console.log(source + ": Will not be sending alerts to " + address);
if(pos == -1) {
nosendto.push(address);
}
save(source, nosendto);
}
function save(source, nosendto) {
console.log("Saving " + source + " data");
switch(source) {
case 'source':
localStorage.setItem('nosendtosrc', JSON.stringify(nosendto));
break;
case 'i-source':
localStorage.setItem('nosendtoisrc', JSON.stringify(nosendto));
break;
case 'www':
localStorage.setItem('nosendtoweb', JSON.stringify(nosendto));
break;
case 'i-www':
localStorage.setItem('nosendtoiweb', JSON.stringify(nosendto));
break;
case 'intermediary':
localStorage.setItem('nosendtointermediary', JSON.stringify(nosendto));
break;
}
}
}