Skip to content

Commit

Permalink
Repair scripts with new React redraw on recording merge page
Browse files Browse the repository at this point in the history
AcoustID have been added on recording merge page
as dynamic React redraw. https://tickets.metabrainz.org/browse/MBS-2768

So I patched my scripts to wait for React redraws
finish (all p.loading-message disappear).

- mb. MERGE HELPOR 2 (regressions may appear)
- mb. COLLECTION HIGHLIGHTER

Fixes #517 and #518.
  • Loading branch information
jesus2099 committed Nov 29, 2020
1 parent 51f4eb3 commit caec1d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
21 changes: 15 additions & 6 deletions mb. MERGE HELPOR 2.user.js
@@ -1,6 +1,6 @@
// ==UserScript==
// @name mb. MERGE HELPOR 2
// @version 2020.9.24.1247
// @version 2020.11.29
// @changelog https://github.com/jesus2099/konami-command/commits/master/mb.%20MERGE%20HELPOR%202.user.js
// @description musicbrainz.org: Merge helper highlights last clicked, shows info, indicates oldest MBID, manages (remove) entity merge list; merge queue (clear before add) tool; don’t reload page for nothing when nothing is checked
// @homepage http://userscripts-mirror.org/scripts/show/124579
Expand Down Expand Up @@ -31,6 +31,14 @@ var lastTick = new Date().getTime();
var WSrate = 1000;
if (mergeType) {
/* main merge tool */
var deferScript = setInterval(function() {
// Make sure no more React funny stuff will redraw content (on /recording/merge for the moment)
if (!document.querySelector("p.loading-message")) {
clearInterval(deferScript);
findUsefulMergeInfo();
}
}, 500);
function findUsefulMergeInfo() {
mergeType = mergeType[1].replace(/_/, "-");
var showEntityInfo = true;
var entities = {};
Expand Down Expand Up @@ -95,7 +103,7 @@ if (mergeType) {
var tbl = mergeForm.querySelector("table.tbl");
var entityRows = mergeForm.getElementsByTagName("li");
if (tbl) {
entityRows = mergeForm.querySelectorAll("form > table.tbl > tbody > tr");
entityRows = mergeForm.querySelectorAll("form table.tbl > tbody > tr");
var headers = tbl.querySelector("thead tr");
if (showEntityInfo && mergeType.match(/(release|release-group)/)) {
headers.appendChild(document.createElement("th")).appendChild(document.createTextNode("Information"));
Expand All @@ -116,7 +124,7 @@ if (mergeType) {
var rad = entityRows[row].querySelector("input[type='radio'][name='merge.target']");
if (a && rad) {
if (showEntityInfo) {
addZone(entityRows[row], "entInfo" + rad.value);
addZone(tbl, entityRows[row], "entInfo" + rad.value);
}
entities[rad.value] = {a: a, rad: rad, row: entityRows[row], rowid: parseInt(rad.value, 10)};
minrowid = row == 0 ? entities[rad.value].rowid : Math.min(minrowid, entities[rad.value].rowid);
Expand All @@ -137,10 +145,10 @@ if (mergeType) {
rad.click();
}
}
entities[rad.value].rowidzone = addZone(entityRows[row], "rowID"+row);
entities[rad.value].rowidzone = addZone(tbl, entityRows[row], "rowID"+row);
entities[rad.value].rowidzone.style.setProperty("text-align", "right");
entities[rad.value].rowidzone.appendChild(rowIDLink(mergeType.replace(/-/, "_"), rad.value));
var removeZone = addZone(entityRows[row], "remove" + row);
var removeZone = addZone(tbl, entityRows[row], "remove" + row);
var batchRemove = document.createElement("label");
var removeCB = batchRemove.appendChild(document.createElement("input"));
removeCB.setAttribute("type", "checkbox");
Expand Down Expand Up @@ -201,6 +209,7 @@ if (mergeType) {
}
}
}
}
} else {
/* merge queue (clear before add) tool */
var mergeButton = document.querySelector("div#content > form[action$='/merge_queue'] > table.tbl ~ div.row > span.buttons > button[type='submit'], div#page > form[action$='/merge_queue'] > table.tbl ~ div.row > span.buttons > button[type='submit']");
Expand Down Expand Up @@ -472,7 +481,7 @@ function loadimg(txt) {
}
return img;
}
function addZone(par, id) {
function addZone(tbl, par, id) {
par.appendChild(document.createTextNode(" "));
var zone = par.appendChild(document.createElement(tbl ? "td" : "span"));
zone.setAttribute("id", userjs + id);
Expand Down
16 changes: 13 additions & 3 deletions mb_COLLECTION-HIGHLIGHTER.user.js
Expand Up @@ -2,7 +2,7 @@
var meta = {raw: function() {
// ==UserScript==
// @name mb. COLLECTION HIGHLIGHTER
// @version 2020.10.18.3
// @version 2020.11.29
// @description musicbrainz.org: Highlights releases, release-groups, etc. that you have in your collections (anyone’s collection can be loaded) everywhere
// @compatible vivaldi(2.4.1488.38)+violentmonkey my setup (office)
// @compatible vivaldi(1.0.435.46)+violentmonkey my setup (home, xp)
Expand Down Expand Up @@ -56,7 +56,7 @@ if (cat) {
var MBWSRate = 999;
/* -------- CONFIGURATION END (don’t edit below) -------- */
var prefix = "collectionHighlighter";
var DEBUG = false;
var DEBUG = localStorage.getItem("jesus2099debug");
var dialogprefix = "..:: " + meta.nameAndVersion.replace(/ /g, " :: ") + " ::..\n\n";
var maxRetry = 20;
var retryPause = 5000;
Expand Down Expand Up @@ -210,6 +210,17 @@ if (cat) {
// ############################################################################
// # COLLECT LINKS TO HIGHLIGHT / DECORATE #
// ############################################################################
var deferScript = setInterval(function() {
debug("Interval " + deferScript);
// Make sure no more React funny stuff will redraw content (on /recording/merge for the moment)
if (!document.querySelector("p.loading-message")) {
clearInterval(deferScript);
findOwnedStuff();
}
}, 500);
}
}
function findOwnedStuff() {
stuff = {};
// Annotation link trim spaces and protocol + "//" + host
for (var annotationLinks = document.querySelectorAll("div#content div.annotation a"), l = 0; l < annotationLinks.length; l++) {
Expand Down Expand Up @@ -247,7 +258,6 @@ if (cat) {
}
debug("");
}
}
// ############################################################################
// # #
// # MAIN FUNCTIONS #
Expand Down

0 comments on commit caec1d6

Please sign in to comment.