forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mb_LOCAL-STORAGE-MANAGER.user.js
234 lines (234 loc) · 10.7 KB
/
mb_LOCAL-STORAGE-MANAGER.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
(function(){"use strict";var meta={rawmdb:function(){
// ==UserScript==
// @name mb. LOCAL STORAGE MANAGER
// @version 2015.2.18.16.28
// @description musicbrainz.org: Read, write, edit and delete key/values from your mb local storage (in About menu)
// @homepage http://userscripts-mirror.org/scripts/show/126475
// @supportURL https://github.com/jesus2099/konami-command/issues
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_LOCAL-STORAGE-MANAGER.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_LOCAL-STORAGE-MANAGER.user.js
// @author PATATE12
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2012-02-22
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include http*://*musicbrainz.org/*
// @include http://*.mbsandbox.org/*
// @exclude *//*/*mbsandbox.org/*
// @exclude *//*/*musicbrainz.org/*
// @run-at document-end
// ==/UserScript==
}};
if (meta.rawmdb && meta.rawmdb.toString && (meta.rawmdb = meta.rawmdb.toString())) {
var kv/*key,val*/, row = /\/\/\s+@(\S+)\s+(.+)/g;
while ((kv = row.exec(meta.rawmdb)) !== null) {
if (meta[kv[1]]) {
if (typeof meta[kv[1]] == "string") meta[kv[1]] = [meta[kv[1]]];
meta[kv[1]].push(kv[2]);
} else meta[kv[1]] = kv[2];
}
}
var userjs = "jesus2099userjs126475";
var lsm, lskeys;
var j2set = document.querySelector("div#header-menu li.about > ul > li.jesus2099");
if (!j2set && (j2set = document.querySelector("div#header-menu li.about > ul"))) {
j2set = j2set.appendChild(createTag("li", {a:{"class":"jesus2099 separator"}}));
}
if (j2set) {
addAfter(createTag("li", {a:{"class":"jesus2099"}},
createTag("a", {a:{title:meta.description.replace(/^[^:]+: /,"")},e:{click:function(e){
this.parentNode.parentNode.style.removeProperty("left");
if (lsm) { unloadLS(); } else {
lskeys = [];
lsm = document.body.insertBefore(createTag("div", {a:{id:userjs+"lsm"}}, createTag("h2", {}, [
meta.name+" (",
createTag("a", {a:{title:"Add a new key"},e:{click:function(e){
loadLS();
var key = prompt("Type new key name");
if (key) {
if (lskeys.indexOf(key) == -1 || confirm("THIS KEY ALREADY EXISTS\nDo you want to replace it\u00a0?\n\n“"+key+"”\u00a0:\n"+localStorage.getItem(key))) {
var newValue = prompt("Type value for key “"+key+"”");
if (newValue) {
localStorage.setItem(key, newValue);
loadLS();
}
}
}
}}}, "new"),
"/",
createTag("a", {a:{title:"Browse all local storage keys"},e:{click:function(e){loadLS();}}}, "reload"),
"/",
createTag("a", {a:{title:"Clear all local storage keys"},e:{click:function(e){
loadLS();
if (!e.shiftKey) { alert("SHIFT+CLICK\n\nIn order to avoid GROß MALHEUR,\nyou must hold down shift key\nif you really really want to erase\nall your local storage for this website."); return true; }
if (confirm("Are you sure you want to clear all those keys\nfrom your local storage memory\nfor this website?\nYOU CANNOT UNDO THIS ACTION.")) {
localStorage.clear();
loadLS();
}
}}}, "clear"),
"/",
createTag("a", {a:{title:"Close local storage manager"},e:{click:function(e){unloadLS();}}}, "close"),
")"
])), document.getElementById("page"));
if (self.opera) lsm.appendChild(createTag("p", {}, "☞ Opera 12 has its own local storage editor: CTRL+SHIFT+I (Dragon fly) > Storage > Local Storage."));
else if (navigator.userAgent.match(/firefox/i)) lsm.appendChild(createTag("p", {}, "☞ Firefox’s Firebug has its own local storage editor: DOM > localStorage."));
else if (navigator.userAgent.match(/chrom(ium|e)/i)) lsm.appendChild(createTag("p", {}, "☞ Chromium has its own local storage editor: F12 > Resources > Local Storage."));
document.addEventListener("storage", function(e) { loadLS(); }, false);/*does never trigger btw*/
loadLS();
lsm.scrollIntoView();
}
}}}, meta.name)
), j2set);
}
function unloadLS() {
lsm.parentNode.removeChild(lsm);
lsm = null;
lskeys = null;
}
function loadLS() {
var keylist = createTag("table", {a:{cellspacing:"0",cellpadding:"0"},s:{border:"2px dashed red","background-color":"#eee",padding:"8px",margin:"8px"}});
lskeys = [];
for (var ls=0; ls<localStorage.length; ls++) {
lskeys.push(localStorage.key(ls));
}
lskeys.sort();
addRow(keylist, ["#", "Key", "Content", "\u00a0", "Size (characters)"], "th");
var size = 0;
for (var k=0; k<lskeys.length; k++) {
var key = lskeys[k];
var content = localStorage.getItem(key);
size += content.length;
var tr = addRow(keylist, [
(k+1)+".\u00a0",
createTag("code", {}, key),
content.length>64||content.match(/(\n|\r)/)?content.substr(0, 64)+(content.length>64?"…":""):content,
concat([
" ",
createA(
"×",
function(e) {
stop(e);
var item = this.getAttribute("title").match(/^remove (.+)$/)[1];
if (confirm("Do you want to remove following item?\n"+item)) {
localStorage.removeItem(item);
}
loadLS();
},
"remove "+key
),
]),
content.length+""
]);
tr.setAttribute("title", "edit "+key);
tr.addEventListener("click", function(e){
function coolstuff(t,z,s,b,o) {
var truc = document.getElementsByTagName("body")[0].appendChild(document.createElement(t));
truc.style.setProperty("position", "fixed");
truc.style.setProperty("z-index", z);
truc.style.setProperty("top", (100-s)/2+"%");
truc.style.setProperty("left", (100-s)/2+"%");
truc.style.setProperty("width", s+"%");
truc.style.setProperty("height", s+"%");
if (b) { truc.style.setProperty("background-color", b); }
if (o) { truc.style.setProperty("opacity", o); }
return truc;
}
var bidule = coolstuff("div", "50", 100, "black", ".6");
bidule.setAttribute("title", this.getAttribute("title").match(/^edit (.+)$/)[1]);
bidule.addEventListener("click", function(e) {
this.nextSibling.setAttribute("disabled", "disabled");
var item = this.getAttribute("title");
var oval = localStorage.getItem(item);
var nval = this.nextSibling.value;
if (oval != nval && confirm("Do you want to save following item?\n"+item)) {
localStorage.setItem(item, nval);
}
this.parentNode.removeChild(this.nextSibling);
this.parentNode.removeChild(this);
loadLS();
}, false);
bidule = coolstuff("textarea", "55", 80);
bidule.addEventListener("keypress", function(e) {
if (e.keyCode == 27) { this.previousSibling.click(); }
}, false);
bidule.appendChild(document.createTextNode(localStorage.getItem(this.getAttribute("title").match(/^edit (.+)$/)[1])));
bidule.setAttribute("title", "press ESC to close");
bidule.select();
}, false);
}
addRow(keylist, ["\u00a0", "\u00a0", "\u00a0", "\u00a0", size+""]);
var lsm = document.getElementById(userjs+"lsm");
var lsmkeys = lsm.querySelector("table");
if (lsmkeys) { lsm.replaceChild(keylist, lsmkeys); }
else { lsm.appendChild(keylist); }
}
function decorate(event, tr, over) {
tr.style.setProperty("text-shadow", over?"1px 2px 2px #999":"none");
tr.style.setProperty("background-color", over?"white":"transparent");
}
function addRow(table, cells, type) {
var tr = table.appendChild(document.createElement("tr"));
if (type == "ev") { tr.className = "ev"; }
tr.addEventListener("mouseover", function(e){decorate(e,this,true);}, false);
tr.addEventListener("mouseout", function(e){decorate(e,this,false);}, false);
tr.style.setProperty("cursor", type=="th"?"default":"pointer");
for (var cell=0; cell<cells.length; cell++) {
var td = tr.appendChild(document.createElement(type=="th"?"th":"td"));
td.style.setProperty("padding", "0 4px");
td.appendChild(typeof cells[cell]=="string"?document.createTextNode(cells[cell]):cells[cell]);
}
return tr;
}
function concat(tstuff) {
var concats = document.createDocumentFragment();
var stuff = tstuff;
if (typeof stuff != "object" || !stuff.length) {
stuff = [stuff];
}
for (var thisStuff=0; thisStuff<stuff.length; thisStuff++) {
concats.appendChild(typeof stuff[thisStuff]=="string"?document.createTextNode(stuff[thisStuff]):stuff[thisStuff]);
}
return concats;
}
function createTag(tag, gadgets, children) {
var t = (tag=="fragment"?document.createDocumentFragment():document.createElement(tag));
if(t.tagName) {
if (gadgets) {
for (var attri in gadgets.a) if (gadgets.a.hasOwnProperty(attri)) { t.setAttribute(attri, gadgets.a[attri]); }
for (var style in gadgets.s) if (gadgets.s.hasOwnProperty(style)) { t.style.setProperty(style.replace(/!/g,""), gadgets.s[style].replace(/!/g,""), style.match(/!/)||gadgets.s[style].match(/!/)?"important":""); }
for (var event in gadgets.e) if (gadgets.e.hasOwnProperty(event)) { t.addEventListener(event, gadgets.e[event], false); }
}
if (t.tagName == "A" && !t.getAttribute("href") && !t.style.getPropertyValue("cursor")) t.style.setProperty("cursor", "pointer");
}
if (children) { var chldrn = children; if (typeof chldrn == "string" || chldrn.tagName) { chldrn = [chldrn]; } for(var child=0; child<chldrn.length; child++) { t.appendChild(typeof chldrn[child]=="string"?document.createTextNode(chldrn[child]):chldrn[child]); } t.normalize(); }
return t;
}
function createA(text, link, title) {
var a = document.createElement("a");
if (link && typeof link == "string") {
a.setAttribute("href", link);
}
else {
if (link && typeof link == "function") {
a.addEventListener("click", link, false);
}
a.style.setProperty("cursor", "pointer");
}
if (title){ a.setAttribute("title", title); }
a.appendChild(document.createTextNode(text));
return a;
}
function addAfter(n, e) {
if (n && e && e.parentNode) {
if (e.nextSibling) { return e.parentNode.insertBefore(n, e.nextSibling); }
else { return e.parentNode.appendChild(n); }
} else { return null; }
}
function stop(e) {
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
return false;
}
})();