Skip to content

Instantly share code, notes, and snippets.

@hansogj
Last active June 17, 2024 08:46
Show Gist options
  • Save hansogj/5b2b5faafe18583b240d50799e1d219f to your computer and use it in GitHub Desktop.
Save hansogj/5b2b5faafe18583b240d50799e1d219f to your computer and use it in GitHub Desktop.
Edit all listed items in your discogs collection
const g = window || global;
const find = (selector, base = document) => Array.from(base.querySelectorAll(selector));
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
const hideHeaderAndPrice = () =>
['thead', '.rating', '.collection-date-added-column', '.pricing', '.hide_mobile']
.flatMap((cn) => find(cn))
.forEach((e) => e.setAttribute('style', 'display: none'));
const GRADES = {
'M': 'Mint (M)',
'NM': 'Near Mint (NM or M-)',
'VG_P': 'Very Good Plus (VG+)',
'VG': 'Very Good (VG)',
'G_P': 'Good Plus (G+)',
'G': 'Good (G)',
'F': 'Fair (F)',
'P': 'Poor (P)'
};
const PLACEMENT = {
O: "Oppe",
N: "Nede",
B: "Boden"
}
const SUBFOLDERS = {
HoG: "HoG",
IGM: "IGM",
OG: "OG",
Gj: "Gjerdrum",
Maus: "Maus",
Skiaker: "Skiaker"
}
const force = (elem) => true;
const ifEmpty = (elem) => Boolean(
find('.notes_text', elem)
.map((elem) => elem.textContent)
.filter((text) => text === '').length);
const equals = (comparator)=> (elem) => Boolean(
find('.notes_text', elem)
.map((elem) => elem.textContent)
.filter((text) => text === comparator).length);
const editField = async (field, val, strategy = ifEmpty) => {
return (
find(field)
//.filter((_, i) => i < 2)
.filter(strategy)
.map(async (e, i) => {
await timer(i * 700);
find('button', e)[0].click();
setTimeout(() => {
const s = find('select', e)[0];
find(`option[value]`, e)
.filter((option) => option.value.replace("\n","") === val)
.map((option) => {
s.value = option.value;
option.selected = true;
return [s, option].map((e) => e.click());
});
}, 200);
})
);
};
const dataHeader = (val) => `[data-header*="${val}"]`;
const dataField = (val) => `[data-field-name="${val}"]`;
g.discogs = g.discogs || {};
g.discogs.setOrigin = (val, force) => editField(dataHeader('Origin'), val, force);
g.discogs.setPlacement = (val, force) => editField(dataHeader('Placement'), val, force);
g.discogs.setMediaCondition = (val, force) => editField(dataField('Media Condition'), val, force);
g.discogs.setSleeveCondition = (val, force) => editField(dataField('Sleeve Condition'), val, force);
g.discogs.setMediaAndSleeveCondition = (val, force) =>
['Media Condition', 'Sleeve Condition'].map((selector) => editField(dataField(selector), val, force));
hideHeaderAndPrice();
/*
USAGE
* discogs.setPlacement(PLACEMENT.N, equals(PLACEMENT.B)) / set placement NEDE if items current placement is Boden
* discogs.setPlacement(PLACEMENT.N) // set placenement NEDE if current placement is empty
* discogs.setPlacement(PLACEMENT.N, force) // set placenement NEDE !!!
*/
('discogs loaded');
@hansogj
Copy link
Author

hansogj commented Oct 23, 2023

Put in you snippets with

const src = "COPY SHARED SRC URL"
fetch(src).then(e => e.text()).then(eval);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment