-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-tag-status.user.js
129 lines (106 loc) · 5.36 KB
/
check-tag-status.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
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
// ==UserScript==
// @name AO3: [Wrangling] Check Tag Status
// @description Adds a button to check if tags in your wrangling bins are in draft, on unrevealed works, etc.
// @version 1.3
// @updateURL https://raw.githubusercontent.com/kaerstyne/ao3-wrangling-scripts/master/check-tag-status.user.js
// @downloadURL https://raw.githubusercontent.com/kaerstyne/ao3-wrangling-scripts/master/check-tag-status.user.js
// @author kaerstyne
// @namespace https://github.com/kaerstyne/ao3-wrangling-scripts
// @license GPL-3.0 <https://www.gnu.org/licenses/gpl.html>
// @match *://*.archiveofourown.org/tags/*/wrangle?*&status=unwrangled
// @match *://*.archiveofourown.org/tag_wranglings*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @grant none
// ==/UserScript==
function convertDate(dateStr) {
var dateArray = dateStr.split(" ");
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var monthIndex = months.indexOf(dateArray[1]) + 1;
if (monthIndex < 10) {
monthIndex = "0" + monthIndex;
}
return dateArray[2] + "-" + monthIndex + "-" + dateArray[0];
}
(function($) {
// what kind of wrangling page is this?
var page_url = window.location.href;
var page_type = "regular";
if (page_url.includes("tag_wranglings")) {
if (page_url.includes("show=fandoms")) {
page_type = "fandoms";
} else {
page_type = "mass";
}
}
// add the button
var status_check_button = $('<ul class="actions" role="menu"><li><a id="check_status">Status?</a></li></ul>');
$("thead").find("th:contains('Taggings')").append(status_check_button);
// when button is pressed
$("a[id='check_status']").on("click", function() {
// check each tag on page
$("tbody tr").each(function(i, row) {
var tag_link = $(this).find("a[href$='/works']").attr("href").slice(0, -6);
var taggings_cell = $(this).find("td[title='taggings']");
if (page_type == "mass") {
var tag_date = new Date($(this).find("td[title='created']").text().split("-"));
}
// check the tag's landing page
$.get(tag_link, function(response) {
// console.log("checking page " + tag_link + " ...");
// check for works
if ($(response).find("div.work").length) {
// check for unrevealed works
if ($(response).find("div.mystery").length) {
// check if there are any revealed works present
var total_works = $(response).find("li.work").length;
var total_unrevealed = $(response).find("div.mystery").length;
if (total_works == total_unrevealed) {
taggings_cell.append(" [unrevealed]");
} else {
taggings_cell.append(" [\u2714]");
}
// check for Chinese works (fandom bins only)
} else if (page_type == "fandoms") {
var work_languages = $(response).find("div.work dd.language").toArray();
if (work_languages.every(lang => lang.innerHTML.startsWith("中文"))) {
taggings_cell.append(" [Chinese]");
} else {
taggings_cell.append(" [\u2714]");
}
// check for new works (non-fandom mass bins only)
} else if (page_type == "mass") {
// find the earliest date used on the works
var work_dates = $(response).find("div.work p.datetime").map(function() {
return convertDate($(this).text());
}).toArray();
work_dates.sort();
// compare tag creation date to earliest work date
var earliest_date = new Date(work_dates[0].split("-"));
var date_today = new Date();
var work_age = (date_today - earliest_date)/(1000*60*60*24);
// check if work only posted in the last two months
if (earliest_date > tag_date && work_age <= 62) {
taggings_cell.append(" [new]");
} else {
taggings_cell.append(" [\u2714]");
}
// just regular ol' works found
} else {
taggings_cell.append(" [\u2714]");
}
// check for bookmarks
} else if ($(response).find("div.bookmark").length) {
taggings_cell.append(" [bookmark]");
// nothing there; is it canonical?
} else if ($(response).find("p:contains('It\'s a common tag.')").length) {
taggings_cell.append(" [canonical]")
// must be a draft
} else {
taggings_cell.append(" [draft]");
}
});
});
// remove the button when finished
$("ul").remove(":has(li a[id='check_status'])");
});
})(jQuery);