forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmb_MASS-ISRC.user.js
77 lines (77 loc) · 4.3 KB
/
mb_MASS-ISRC.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
// ==UserScript==
// @name mb. MASS ISRC
// @version 2016.6.15
// @changelog https://github.com/jesus2099/konami-command/commits/master/mb_MASS-ISRC.user.js
// @description notlob.eu/isrc. BATCH SUBMIT ISRCs. Allows pasting all ISRCs at once (from Simonf’s mediatool on multi-disc releases or from 音楽の森/ongakunomori/minc) - does not work in Opera for AUTH bug reason :/
// @homepage http://userscripts-mirror.org/scripts/show/151040
// @supportURL https://github.com/jesus2099/konami-command/labels/mb_MASS-ISRC
// @compatible opera(12.18.1872)+violentmonkey my setup
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/mb_MASS-ISRC.user.js
// @updateURL https://github.com/jesus2099/konami-command/raw/master/mb_MASS-ISRC.user.js
// @author PATATE12
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2012-10-26
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @match *://*.kepstin.ca/magicisrc/*
// @match *://*.musicbrainz.org/ws/1/track/
// @match *://mb.lmfao.org.uk/isrc/*
// @match *://notlob.eu/isrc/*
// @run-at document-end
// ==/UserScript==
"use strict";
var home = "http://notlob.eu/isrc/";
var dummySkip = "JESUS2099999";
var inputs, submit = document.querySelector("form > input[type='submit']");
if (self.location.href.match(/^https?:\/\/[^/]+\/ws\/1\//)) {
var p = document.body.querySelector("pre, p");
if (p && p.textContent.trim() == "") {
document.body.appendChild(document.createTextNode("ISRC submission seems OK. "));
document.body.appendChild(document.createElement("a")).appendChild(document.createTextNode("Going back to submission page (in 4 seconds).")).parentNode.setAttribute("href", home);
setTimeout(function() { self.location = home; }, 4000);
}
} else if (inputs = document.querySelector("form input[name='mbid']")) {
inputs.addEventListener("focus", function(event) { this.select(); }, false);
inputs.focus();
} else if ((inputs = document.querySelectorAll("form table input[type='text'][name^='track'][name$='-isrc']")) && inputs.length > 0) {
for (var input = 0; input < inputs.length; input++) {
inputs[input].style.setProperty("font-family", "monospace");
inputs[input].setAttribute("maxlength", "12");
inputs[input].setAttribute("size", "12");
}
var f = document.querySelector("form");
f.appendChild(document.createElement("strong")).appendChild(document.createTextNode(" - Paste your batch of ISRCs below — dummy ISRC if you need to skip a track: " + dummySkip));
f.appendChild(document.createElement("br"));
var t = f.appendChild(document.createElement("textarea"));
t.style.setProperty("width", "100%");
t.style.setProperty("height", "400px");
t.addEventListener("keyup", function(event) {
var isrcs = this.value.match(/[a-z]{2}\-?[a-z0-9]{3}\-?[0-9]{2}\-?[0-9]{5}/gi);
if (isrcs && isrcs.length > 0 && inputs.length > 0) {
this.style.setProperty("background-color", arrHasDupes(isrcs) ? "pink" : "transparent");
for (var isrc = 0, input = 0; input < inputs.length; input++) {
inputs[input].value = (isrc < isrcs.length && isrcs[isrc] != dummySkip ? isrcs[isrc] : "");
if (isrc > 0) {
inputs[input].style.setProperty("background-color", inputs[input].value==inputs[input-1].value && inputs[input].value != "" ? "pink" : "transparent");
}
isrc++;
}
} else { this.style.setProperty("background-color", "transparent"); }
if (submit && event.ctrlKey && event.keyCode == 86) { submit.focus(); }
}, false);
t.select();
} else if (submit && (inputs = document.querySelectorAll("form input:not([type='submit']):not([type='hidden'])")) && inputs.length == 0) {
submit.focus();
}
/* http://www.groggyjava.tv/freebies/duplicates.html */
function arrHasDupes(arr) {
var i, j, n;
n = arr.length;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (arr[i] == arr[j] && arr[i] != dummySkip) return true;
}
}
return false;
}