-
Notifications
You must be signed in to change notification settings - Fork 15
/
mb-edit-change_release_quality.user.js
90 lines (83 loc) · 3.37 KB
/
mb-edit-change_release_quality.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
/* global $ requests edits helper */
'use strict';
// ==UserScript==
// @name MusicBrainz edit: Change release quality
// @namespace mbz-loujine
// @author loujine
// @version 2023.3.10
// @downloadURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-edit-change_release_quality.user.js
// @updateURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-edit-change_release_quality.user.js
// @supportURL https://github.com/loujine/musicbrainz-scripts
// @icon https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/icon.png
// @description musicbrainz.org: Change release quality
// @compatible firefox+tampermonkey
// @license MIT
// @require https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mbz-loujine-common.js
// @match *://*.musicbrainz.org/release/*
// @grant none
// @run-at document-end
// ==/UserScript==
const editNote = `GM script: "${GM_info.script.name}" (${GM_info.script.version})\n`;
const qualities = {
normal: 1,
low: 0,
high: 2,
};
function success(xhr) {
document.getElementById('text_quality').textContent = 'Success (code ' + xhr.status + ')'
document.getElementById('text_quality').style.color = 'green';
document.getElementById('upgrade_quality').style.color = 'gray';
document.getElementById('downgrade_quality').style.color = 'gray';
}
function fail(xhr) {
document.getElementById('text_quality').textContent = 'Error (code ' + xhr.status + ')'
document.getElementById('text_quality').style.color = 'red';
document.getElementById('upgrade_quality').style.color = 'gray';
document.getElementById('downgrade_quality').style.color = 'gray';
}
function _changeQuality(offsetQuality) {
const url = helper.wsUrl('release', []);
requests.GET(url, resp => {
const quality = qualities[JSON.parse(resp).quality];
if (quality + offsetQuality > 2 || quality + offsetQuality < 0) {
console.log(`Quality is already set to ${quality}`);
return;
}
const mbid = helper.mbidFromURL();
requests.POST(
`/release/${mbid}/change-quality`,
edits.formatEdit('change-release-quality', {
'quality': quality + offsetQuality,
'edit_note': editNote,
}),
success,
fail
);
});
}
(function displayArrows() {
if (!document.querySelector('a[href*="/change-quality"]')) {
return;
}
document.querySelector('a[href*="/change-quality"]').insertAdjacentHTML('afterend', `
<span id="upgrade_quality">▲</span>
<span id="downgrade_quality">▼</span>
<span id="text_quality"></span>
`);
document.getElementById('upgrade_quality').style.color = 'green';
document.getElementById('upgrade_quality').style.cursor = 'pointer';
document.getElementById('downgrade_quality').style.color = 'red';
document.getElementById('downgrade_quality').style.cursor = 'pointer';
})();
$(document).ready(function () {
if (!helper.isUserLoggedIn()) {
return false;
}
document.getElementById('upgrade_quality')?.addEventListener('click', () => {
_changeQuality(1);
});
document.getElementById('downgrade_quality')?.addEventListener('click', () => {
_changeQuality(-1);
});
return false;
});