-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick-add-issue-bits.js
94 lines (74 loc) · 2.76 KB
/
quick-add-issue-bits.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
// ==UserScript==
// @name Quick add issue bits
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @description Take editor text credits and move to creators
// @author Adam Knights
// @match https://www.comics.org/series/*/add_issue/*
// @grant none
// ==/UserScript==
/* eslint-env jquery */
// @require https://code.jquery.com/jquery-3.5.1.js
function getWednesdayDate() {
let d = new Date();
d.setDate(d.getDate() + (3 + 7 - d.getDay()) % 7); // Get next wednesday or today if wednesday
return d;
}
function getWednesday() {
let d = getWednesdayDate();
let dd = d.getDate();
let mm = d.getMonth() + 1;
dd = (dd > 9 ? '' : '0') + dd;
mm = (mm > 9 ? '' : '0') + mm;
return `${d.getFullYear()}-${mm}-${dd}`;
}
function getPublicationDate(offset) {
const d = getWednesdayDate();
const m = (d.getMonth() + offset) % 12;
const addYear = m < d.getMonth() ? 1 : 0;
const p = new Date(d.getFullYear() + addYear, m, 1);
const monthName = p.toLocaleString('default', { month: 'long' });
return `${monthName} ${p.getFullYear()}`;
}
function getNextIssueNumber() {
const optionLen = $('#id_after option').length;
if (optionLen === 1) {
return '1';
}
let last = $('#id_after option:last').text();
let matches = last.match(/#(\d+)/g);
if (matches === null || matches.length === 0) {
return '';
}
let issue = matches[0].substring(1);
return Number(issue) + 1;
}
function getMarvelButtonHtml() {
return `<input id="marvelButton" type="button" value="Marvel for ${getWednesday()}" style="color: blue; margin-right:10px">`;
}
function getBoomButtonHtml() {
return `<input id="boomButton" type="button" value="Boom! Studios for ${getWednesday()}" style="color: blue">`;
}
function fillBoxesMarvel() {
let wednesday = getWednesday();
$('#id_number').val(getNextIssueNumber()).trigger('input');
$('#id_indicia_publisher').val("401").change();
$('#id_brand').val("5218").change();
$('#id_publication_date').val(getPublicationDate(2)).trigger('input');
$('#id_on_sale_date').val(wednesday).trigger('input');
}
function fillBoxesBoom() {
let wednesday = getWednesday();
$('#id_number').val(getNextIssueNumber()).trigger('input');
$('#id_indicia_publisher').val("75").change();
$('#id_brand').val("6418").change();
$('#id_publication_date').val(getPublicationDate(0)).trigger('input');
$('#id_on_sale_date').val(wednesday).trigger('input');
}
(async function() {
'use strict';
$(getMarvelButtonHtml()).insertBefore($('.edit').first());
$(getBoomButtonHtml()).insertBefore($('.edit').first());
$('#marvelButton').click(() => fillBoxesMarvel());
$('#boomButton').click(() => fillBoxesBoom());
})();