-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmb_blind_votes.user.js
90 lines (84 loc) · 3.59 KB
/
mb_blind_votes.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
// ==UserScript==
// @name MB: Blind Votes
// @version 2021.3.30
// @description Blinds editor details before your votes are cast.
// @author ROpdebee
// @license MIT; https://opensource.org/licenses/MIT
// @namespace https://github.com/ROpdebee/mb-userscripts
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/main/mb_blind_votes.user.js
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/main/mb_blind_votes.user.js
// @match *://musicbrainz.org/*
// @match *://*.musicbrainz.org/*
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @run-at document-body
// ==/UserScript==
let $ = this.$ = this.jQuery = jQuery.noConflict(true);
function setupStyle() {
let style = document.createElement('style');
style.type = 'text/css';
style.id = 'ROpdebee_blind_votes';
document.head.appendChild(style);
// Names and votes
style.sheet.insertRule(`
/* Edit pages */
div#content:not(.unblind) div.edit-header > p.subheader > a, /* Editor */
div#content:not(.unblind) table.vote-tally tr:nth-child(n+3), /* Vote */
div#content:not(.unblind) table.vote-tally tr:nth-child(n+3) a, /* Voter */
div#content:not(.unblind) table.vote-tally tr:nth-child(1) td, /* Vote tally */
div#content:not(.unblind) div.edit-notes h3 > a:not(.date), /* Edit note author */
/* Edit lists */
div.edit-list:not(.unblind) div.edit-header > p.subheader > a, /* Editor */
div.edit-list:not(.unblind) div.edit-notes h3 > a:not(.date) /* Edit note author */
{
color: black;
background-color: black;
}`);
// Profile images
style.sheet.insertRule(`
/* Edit pages */
div#content:not(.unblind) div.edit-header > p.subheader > a > img, /* Editor */
div#content:not(.unblind) table.vote-tally th > a > img, /* Voter */
div#content:not(.unblind) div.edit-notes h3 > a:not(.date) > img, /* Edit note author */
div#content:not(.unblind) div.edit-notes h3 > div.voting-icon, /* Vote icon */
/* Edit lists */
div.edit-list:not(.unblind) div.edit-header > p.subheader > a > img, /* Editor */
div.edit-list:not(.unblind) div.edit-notes h3 > a:not(.date) > img, /* Edit note author */
div.edit-list:not(.unblind) div.edit-notes h3 > div.voting-icon /* Vote icon */
{
display: none;
}`);
}
function setupUnblindListeners() {
$('input[name^="enter-vote.vote"]:not([id$="-None"])').change((evt) => {
let $target = $(evt.currentTarget);
$target
.closest('div.edit-list')
.addClass('unblind');
// Make sure we also add .unblind to the content div on edit lists
// otherwise the CSS rules for the edit page still apply.
$target
.closest('div#content')
.addClass('unblind');
});
$('input[name^="enter-vote.vote"][id$="-None"]').change((evt) => {
$(evt.currentTarget)
.closest('div.edit-list, div#content')
.removeClass('unblind');
});
}
setupStyle();
setupUnblindListeners();
// Unblind any edits that aren't open, are your own, or on which you already voted
$(document).ready(() => {
setupUnblindListeners();
let $unblindEdits = $(`
div.edit-header:not(.open),
div.cancel-edit > a.negative[href*="/cancel"],
input[name^="enter-vote.vote"]:checked:not([id$="-None"])`);
$unblindEdits
.closest('div.edit-list')
.addClass('unblind');
$unblindEdits
.closest('div#content')
.addClass('unblind');
})