Skip to content

Commit 16af9b1

Browse files
🤖 mb_blind_votes 2022.6.17
refactor: more TypeScript migration (#499)
1 parent 53de664 commit 16af9b1

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- **2022.6.17**: Internal changes: more TypeScript migration ([#499](https://github.com/ROpdebee/mb-userscripts/pull/499))

‎mb_blind_votes.meta.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// ==UserScript==
2+
// @name MB: Blind Votes
3+
// @description Blinds editor details before your votes are cast.
4+
// @version 2022.6.17
5+
// @author ROpdebee
6+
// @license MIT; https://opensource.org/licenses/MIT
7+
// @namespace https://github.com/ROpdebee/mb-userscripts
8+
// @homepageURL https://github.com/ROpdebee/mb-userscripts
9+
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues
10+
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_blind_votes.user.js
11+
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_blind_votes.meta.js
12+
// @match *://*.musicbrainz.org/edit/*
13+
// @match *://*.musicbrainz.org/*/edits*
14+
// @match *://*.musicbrainz.org/user/*/votes
15+
// @match *://*.musicbrainz.org/*/open_edits
16+
// @run-at document-end
17+
// @grant none
18+
// ==/UserScript==
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"2022.6.17"}

‎mb_blind_votes.user.js‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// ==UserScript==
2+
// @name MB: Blind Votes
3+
// @description Blinds editor details before your votes are cast.
4+
// @version 2022.6.17
5+
// @author ROpdebee
6+
// @license MIT; https://opensource.org/licenses/MIT
7+
// @namespace https://github.com/ROpdebee/mb-userscripts
8+
// @homepageURL https://github.com/ROpdebee/mb-userscripts
9+
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues
10+
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_blind_votes.user.js
11+
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_blind_votes.meta.js
12+
// @match *://*.musicbrainz.org/edit/*
13+
// @match *://*.musicbrainz.org/*/edits*
14+
// @match *://*.musicbrainz.org/user/*/votes
15+
// @match *://*.musicbrainz.org/*/open_edits
16+
// @run-at document-end
17+
// @grant none
18+
// ==/UserScript==
19+
20+
// For original source code, see https://github.com/ROpdebee/mb-userscripts/tree/main/src/mb_blind_votes
21+
(function () {
22+
'use strict';
23+
24+
/* minified: babel helpers, nativejsx */
25+
function _unsupportedIterableToArray(r,e){if(r){if("string"==typeof r)return _arrayLikeToArray(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return "Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,e):void 0}}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,o=function(){};return {s:o,n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,u=!1;return {s:function(){t=t.call(r);},n:function(){var r=t.next();return i=r.done,r},e:function(r){u=!0,a=r;},f:function(){try{i||null==t.return||t.return();}finally{if(u)throw a}}}}var appendChildren=function(r,e){(e=Array.isArray(e)?e:[e]).forEach((function(e){e instanceof HTMLElement?r.appendChild(e):(e||"string"==typeof e)&&r.appendChild(document.createTextNode(e.toString()));}));};
26+
27+
/* minified: lib */
28+
class AssertionError extends Error{}function assert(e,t){if(!e)throw new AssertionError(null!=t?t:"Assertion failed")}function assertNonNull(e,t){assert(null!==e,null!=t?t:"Assertion failed: Expected value to be non-null");}function qs(e,t){const n=qsMaybe(e,t);return assertNonNull(n,"Could not find required element"),n}function qsMaybe(e,t){return (null!=t?t:document).querySelector(e)}function qsa(e,t){return [...(null!=t?t:document).querySelectorAll(e)]}function onDocumentLoaded(e){"loading"!==document.readyState?e():document.addEventListener("DOMContentLoaded",e);}var USERSCRIPT_ID="mb_blind_votes";function insertStylesheet(e,t){if(void 0===t&&(t="ROpdebee_".concat(USERSCRIPT_ID,"_css")),null!==qsMaybe("style#".concat(t)))return;const n=function(){var n=document.createElement("style");return n.setAttribute("id",t),appendChildren(n,e),n}.call(this);document.head.insertAdjacentElement("beforeend",n);}function parseVersion(e){return e.split(".").map((e=>parseInt(e)))}function versionLessThan(e,t){let n=0;for(;n<e.length&&n<t.length;){if(e[n]<t[n])return !0;if(e[n]>t[n])return !1;n++;}return e.length<t.length}var CHANGELOG_URL="https://github.com/ROpdebee/mb-userscripts/blob/dist/mb_blind_votes.changelog.md",USERSCRIPT_FEATURE_HISTORY=[],css_248z=".ROpdebee_feature_list{font-weight:300;margin:0 auto;width:-moz-fit-content;width:fit-content}.ROpdebee_feature_list ul{margin:6px 28px 0 0;text-align:left}";const LAST_DISPLAYED_KEY="ROpdebee_".concat(USERSCRIPT_ID,"_last_notified_update");function maybeDisplayNewFeatures(){const e=localStorage.getItem(LAST_DISPLAYED_KEY),t=GM.info.script;if(!e)return void localStorage.setItem(LAST_DISPLAYED_KEY,t.version);const n=parseVersion(e),r=USERSCRIPT_FEATURE_HISTORY.filter((e=>versionLessThan(n,parseVersion(e.versionAdded))));0!==r.length&&showFeatureNotification(t.name,t.version,r.map((e=>e.description)));}function showFeatureNotification(e,t,n){insertStylesheet(css_248z,"ROpdebee_Update_Banner");const r=function(){var a=document.createElement("div");a.setAttribute("class","banner warning-header");var s=document.createElement("p");a.appendChild(s),appendChildren(s,"".concat(e," was updated to v").concat(t,"! "));var o=document.createElement("a");o.setAttribute("href",CHANGELOG_URL),s.appendChild(o);var i=document.createTextNode("See full changelog here");o.appendChild(i),appendChildren(s,". New features since last update:");var l=document.createElement("div");l.setAttribute("class","ROpdebee_feature_list"),a.appendChild(l);var d=document.createElement("ul");l.appendChild(d),appendChildren(d,n.map((e=>function(){var t=document.createElement("li");return appendChildren(t,e),t}.call(this))));var c=document.createElement("button");return c.setAttribute("class","dismiss-banner remove-item icon"),c.setAttribute("data-banner-name","alert"),c.setAttribute("type","button"),c.addEventListener("click",(()=>{r.remove(),localStorage.setItem(LAST_DISPLAYED_KEY,GM.info.script.version);})),a.appendChild(c),a}.call(this);qs("#page").insertAdjacentElement("beforebegin",r);}
29+
30+
if (document.location.hostname === 'musicbrainz.org' || document.location.hostname.endsWith('.musicbrainz.org')) {
31+
onDocumentLoaded(maybeDisplayNewFeatures);
32+
}
33+
34+
function setupStyle() {
35+
const style = document.createElement('style');
36+
style.id = 'ROpdebee_blind_votes';
37+
document.head.append(style);
38+
style.sheet.insertRule("\n /* Edit pages */\n div#content:not(.unblind) div.edit-header > p.subheader > a, /* Editor */\n div#content:not(.unblind) table.vote-tally tr:nth-child(n+3), /* Vote */\n div#content:not(.unblind) table.vote-tally tr:nth-child(n+3) a, /* Voter */\n div#content:not(.unblind) table.vote-tally tr:nth-child(1) td, /* Vote tally */\n div#content:not(.unblind) div.edit-notes h3 > a:not(.date), /* Edit note author */\n\n /* Edit lists */\n div.edit-list:not(.unblind) div.edit-header > p.subheader > a, /* Editor */\n div.edit-list:not(.unblind) div.edit-notes h3 > a:not(.date) /* Edit note author */\n {\n color: black;\n background-color: black;\n }");
39+
style.sheet.insertRule("\n /* Edit pages */\n div#content:not(.unblind) div.edit-header > p.subheader > a > img, /* Editor */\n div#content:not(.unblind) table.vote-tally th > a > img, /* Voter */\n div#content:not(.unblind) div.edit-notes h3 > a:not(.date) > img, /* Edit note author */\n div#content:not(.unblind) div.edit-notes h3 > div.voting-icon, /* Vote icon */\n\n /* Edit lists */\n div.edit-list:not(.unblind) div.edit-header > p.subheader > a > img, /* Editor */\n div.edit-list:not(.unblind) div.edit-notes h3 > a:not(.date) > img, /* Edit note author */\n div.edit-list:not(.unblind) div.edit-notes h3 > div.voting-icon /* Vote icon */\n {\n display: none;\n }");
40+
}
41+
42+
function onVoteSelected(evt) {
43+
var _target$closest, _target$closest2;
44+
45+
assertNonNull(evt.target);
46+
const target = evt.target;
47+
(_target$closest = target.closest('div.edit-list')) === null || _target$closest === void 0 ? void 0 : _target$closest.classList.add('unblind');
48+
(_target$closest2 = target.closest('div#content')) === null || _target$closest2 === void 0 ? void 0 : _target$closest2.classList.add('unblind');
49+
}
50+
51+
function onNoVoteSelected(evt) {
52+
var _target$closest3;
53+
54+
assertNonNull(evt.target);
55+
const target = evt.target;
56+
(_target$closest3 = target.closest('div.edit-list, div#content')) === null || _target$closest3 === void 0 ? void 0 : _target$closest3.classList.remove('unblind');
57+
}
58+
59+
function setupUnblindListeners() {
60+
var _iterator = _createForOfIteratorHelper(qsa('input[name^="enter-vote.vote"]:not([id$="-None"])')),
61+
_step;
62+
63+
try {
64+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
65+
const voteButton = _step.value;
66+
voteButton.addEventListener('change', onVoteSelected);
67+
}
68+
} catch (err) {
69+
_iterator.e(err);
70+
} finally {
71+
_iterator.f();
72+
}
73+
74+
var _iterator2 = _createForOfIteratorHelper(qsa('input[name^="enter-vote.vote"][id$="-None"]')),
75+
_step2;
76+
77+
try {
78+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
79+
const noVoteButton = _step2.value;
80+
noVoteButton.addEventListener('change', onNoVoteSelected);
81+
}
82+
} catch (err) {
83+
_iterator2.e(err);
84+
} finally {
85+
_iterator2.f();
86+
}
87+
}
88+
89+
setupStyle();
90+
setupUnblindListeners();
91+
onDocumentLoaded(() => {
92+
setupUnblindListeners();
93+
const unblindEdits = qsa("\n div.edit-header:not(.open),\n div.cancel-edit > a.negative[href*=\"/cancel\"],\n input[name^=\"enter-vote.vote\"]:checked:not([id$=\"-None\"])");
94+
95+
var _iterator3 = _createForOfIteratorHelper(unblindEdits),
96+
_step3;
97+
98+
try {
99+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
100+
var _unblindEdit$closest, _unblindEdit$closest2;
101+
102+
const unblindEdit = _step3.value;
103+
(_unblindEdit$closest = unblindEdit.closest('div.edit-list')) === null || _unblindEdit$closest === void 0 ? void 0 : _unblindEdit$closest.classList.add('unblind');
104+
(_unblindEdit$closest2 = unblindEdit.closest('div#content')) === null || _unblindEdit$closest2 === void 0 ? void 0 : _unblindEdit$closest2.classList.add('unblind');
105+
}
106+
} catch (err) {
107+
_iterator3.e(err);
108+
} finally {
109+
_iterator3.f();
110+
}
111+
});
112+
113+
})();

0 commit comments

Comments
 (0)