-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (75 loc) · 3.18 KB
/
script.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
// ==UserScript==
// @name AO3 auto-remove keywords
// @namespace http://tampermonkey.net/
// @version 0.1
// @description a script that detects whether or not certain the "additional fields" filter is set to the desired keywords and reloads the page with the filter set
// @author You
// @match https://archiveofourown.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=archiveofourown.org
// @grant none
// ==/UserScript==
(function() {
'use strict';
/*
* THIS IS WHERE YOU ADD KEYWORDS YOU WISH TO REMOVE
* you can add an asterisk * at any place as a wildcard (for potentially infinite letters)
*/
var filteredKeyWords = [
"futa*",
"futanari*",
"Jaune Arc/Everyone",
"Jaune Arc/Velvet Scarlatina",
"Jaune Arc/Blake Belladonna",
];
function isSiteFor(reg) {
return document.URL.match(RegExp(reg)) != null;
}
var websiteUrl = document.URL;
var worksOverviewRegex = "/works.*";
var tagsRegex = "/tags/.*/works.*";
var userRegex = "/users.*/works.*";
var bookmarksRegex = "/users.*/bookmarks.*"
var searchRegex = "/works.*/search";
var specificWorkRegex = "/works/\\d+$"
var specificWorkChapterRegex = "/works/\\d+/chapters"
var newWorkRegex = "/works/new$"
var newWorkPreviewRegex = "/works/\\d+/preview$"
var editWorkPreviewRegex = "/works/\\d+/edit"
if(!isSiteFor(specificWorkChapterRegex) && !isSiteFor(editWorkPreviewRegex) && !isSiteFor(newWorkPreviewRegex) && !isSiteFor(newWorkRegex) && !isSiteFor(specificWorkRegex) && !isSiteFor(searchRegex) && (isSiteFor(worksOverviewRegex) || isSiteFor(tagsRegex) || isSiteFor(userRegex) || isSiteFor(bookmarksRegex))){
var keyWords = filteredKeyWords.join();
var params = new URLSearchParams(window.location.search);
var excludedParams = params.get("work_search[excluded_tag_names]");
var isMissingParams = false;
if(excludedParams != null){
for(var i = 0; i < filteredKeyWords.length; ++i){
if(excludedParams.match(RegExp(filteredKeyWords[i])) == null){
isMissingParams = true;
break;
}
}
} else {
isMissingParams = true;
}
console.log("isMissingParams: "+isMissingParams);
if(isMissingParams){
var newUrl = new URL(document.URL);
if(newUrl.searchParams == null){
newUrl.searchParams = new URLSearchParams();
}
var newParams = newUrl.searchParams.get("work_search[excluded_tag_names]");
if(newParams == null){
newParams = [];
}else {
newParams = newParams.split(",");
}
for(var j = 0; j < filteredKeyWords.length; ++j){
if(newParams.indexOf(filteredKeyWords[j]) == -1){
newParams.push(filteredKeyWords[j]);
}
}
newUrl.searchParams.set("work_search[excluded_tag_names]",newParams.join());
console.log(newUrl.searchParams);
window.location = newUrl;
}
}
})();