Skip to content

Instantly share code, notes, and snippets.

@jeremyredhead
Last active July 3, 2020 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyredhead/b022c511cd27fefbb04a0908cf486c82 to your computer and use it in GitHub Desktop.
Save jeremyredhead/b022c511cd27fefbb04a0908cf486c82 to your computer and use it in GitHub Desktop.
Unlock all the badges on StackEdit!

This is code which should allow one to unlock all badges in StackEdit, in order to prevent them from distracting you. The code is still a mess, apologies, but I will work on it. This seemed to work but some more testing should probably be done first.

Run this in the JS console (or some such):

  • run this code as instructed in stackedit-badges-gen.js
  • then run minimal-utils.js not stackedit-badges-gen.js
  • then run stackedit-badges-gen.js
  • you'll want to copy the string produced, and paste it into the "approprate location" in localStorage browsers vary in this area... // TODO: write better instructions of where to put the string produced
// https://github.com/benweet/stackedit/blob/master/src/services/utils.js
// The minimal necessary utils (for our purposes, anyway)
// Line 107
function serializeObject(obj) {
return obj === undefined ? obj : JSON.stringify(obj, (key, value) => {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return value;
}
// Sort keys to have a predictable result
return Object.keys(value).sort().reduce((sorted, valueKey) => {
sorted[valueKey] = value[valueKey];
return sorted;
}, {});
});
}
// Line 134
function hash(str) {
// https://stackoverflow.com/a/7616484/1333165
let hash = 0;
if (!str) return hash;
for (let i = 0; i < str.length; i += 1) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char; // eslint-disable-line no-bitwise
hash |= 0; // eslint-disable-line no-bitwise
}
return hash;
}
// Line 145
function getItemHash(item) {
return hash(serializeObject({
...item,
// These properties must not be part of the hash
id: undefined,
hash: undefined,
history: undefined,
}));
}
function addItemHash(item) {
return {
...item,
hash: getItemHash(item),
};
}
// first run the code at https://github.com/benweet/stackedit/blob/master/src/data/features.js
// either "properly" (as a module) & import as `badges`; or replace `export default` with `badges =`
// this code is still bad, lol; `flat` acts a global acculmuator
var flat = []
var push = (badge) => flat.push(badge.id) && flat
var push_childs = (b) => b.children.reduce((_, b) => push(b), flat)
badges.reduce((_, b) => push(b) && push_childs(b), flat)
data = {id: "badgeCreations", type: "data", data: {}, hash: 0}
flat.map(badge => data.data[badge] = {created: 0}) // do i need created?
JSON.stringify( addItemHash(data) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment