-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 mb_qol_select_all_update_recordings 2022.6.17
refactor: more TypeScript migration (#499)
- Loading branch information
1 parent
b94bb20
commit 977b6c6
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- **2022.6.17**: Internal changes: more TypeScript migration ([#499](https://github.com/ROpdebee/mb-userscripts/pull/499)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ==UserScript== | ||
// @name MB: QoL: Select All Update Recordings | ||
// @description Add buttons to release editor to select all "Update recordings" checkboxes. | ||
// @version 2022.6.17 | ||
// @author ROpdebee | ||
// @license MIT; https://opensource.org/licenses/MIT | ||
// @namespace https://github.com/ROpdebee/mb-userscripts | ||
// @homepageURL https://github.com/ROpdebee/mb-userscripts | ||
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues | ||
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_qol_select_all_update_recordings.user.js | ||
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_qol_select_all_update_recordings.meta.js | ||
// @match *://*.musicbrainz.org/release/*/edit | ||
// @match *://*.musicbrainz.org/release/*/edit?* | ||
// @match *://*.musicbrainz.org/release/add* | ||
// @run-at document-idle | ||
// @grant none | ||
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"version":"2022.6.17"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// ==UserScript== | ||
// @name MB: QoL: Select All Update Recordings | ||
// @description Add buttons to release editor to select all "Update recordings" checkboxes. | ||
// @version 2022.6.17 | ||
// @author ROpdebee | ||
// @license MIT; https://opensource.org/licenses/MIT | ||
// @namespace https://github.com/ROpdebee/mb-userscripts | ||
// @homepageURL https://github.com/ROpdebee/mb-userscripts | ||
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues | ||
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_qol_select_all_update_recordings.user.js | ||
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_qol_select_all_update_recordings.meta.js | ||
// @match *://*.musicbrainz.org/release/*/edit | ||
// @match *://*.musicbrainz.org/release/*/edit?* | ||
// @match *://*.musicbrainz.org/release/add* | ||
// @run-at document-idle | ||
// @grant none | ||
// ==/UserScript== | ||
|
||
// For original source code, see https://github.com/ROpdebee/mb-userscripts/tree/main/src/mb_qol_select_all_update_recordings | ||
(function () { | ||
'use strict'; | ||
|
||
/* minified: nativejsx */ | ||
var appendChildren=function(e,n){(n=Array.isArray(n)?n:[n]).forEach((function(n){n instanceof HTMLElement?e.appendChild(n):(n||"string"==typeof n)&&e.appendChild(document.createTextNode(n.toString()));}));}; | ||
|
||
/* minified: lib */ | ||
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_qol_select_all_update_recordings";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_qol_select_all_update_recordings.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 o=document.createElement("p");a.appendChild(o),appendChildren(o,"".concat(e," was updated to v").concat(t,"! "));var s=document.createElement("a");s.setAttribute("href",CHANGELOG_URL),o.appendChild(s);var i=document.createTextNode("See full changelog here");s.appendChild(i),appendChildren(o,". 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);} | ||
|
||
if (document.location.hostname === 'musicbrainz.org' || document.location.hostname.endsWith('.musicbrainz.org')) { | ||
onDocumentLoaded(maybeDisplayNewFeatures); | ||
} | ||
|
||
function setCheckboxToTargetState(checkbox, targetState) { | ||
if (checkbox.checked === targetState) | ||
return; | ||
checkbox.checked = targetState; | ||
checkbox.dispatchEvent(new Event('click')); | ||
} | ||
function addButtons(pElement, classSelector) { | ||
let nextTargetState = true; | ||
function onSelectAllClicked() { | ||
qsa(classSelector).forEach(cbox => { | ||
setCheckboxToTargetState(cbox, nextTargetState); | ||
}); | ||
selectAllBtn.textContent = nextTargetState ? 'Deselect all' : 'Select all'; | ||
nextTargetState = !nextTargetState; | ||
} | ||
function onToggleAllClicked() { | ||
qsa(classSelector).forEach(cbox => { | ||
setCheckboxToTargetState(cbox, !cbox.checked); | ||
}); | ||
} | ||
const selectAllBtn = function () { | ||
var $$a = document.createElement('button'); | ||
$$a.setAttribute('type', 'button'); | ||
$$a.setAttribute('class', 'ROpdebee_select_all'); | ||
$$a.addEventListener('click', onSelectAllClicked); | ||
var $$b = document.createTextNode('Select all'); | ||
$$a.appendChild($$b); | ||
return $$a; | ||
}.call(this); | ||
const toggleAllBtn = function () { | ||
var $$c = document.createElement('button'); | ||
$$c.setAttribute('type', 'button'); | ||
$$c.setAttribute('class', 'ROpdebee_update_all'); | ||
$$c.addEventListener('click', onToggleAllClicked); | ||
var $$d = document.createTextNode('Toggle all'); | ||
$$c.appendChild($$d); | ||
return $$c; | ||
}.call(this); | ||
pElement.append(selectAllBtn); | ||
pElement.append(toggleAllBtn); | ||
} | ||
function addButtonsOnLoad() { | ||
if (qsa('button.ROpdebee_select_all').length > 0) | ||
return; | ||
const pElements = qsa('#recordings > .changes > fieldset > p'); | ||
if (pElements.length > 1) { | ||
addButtons(pElements[2], '.update-recording-title'); | ||
addButtons(pElements[3], '.update-recording-artist'); | ||
} | ||
} | ||
setInterval(addButtonsOnLoad, 500); | ||
|
||
})(); |