Skip to content

Instantly share code, notes, and snippets.

@ahallora
Created May 25, 2022 06:50
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 ahallora/d3ded050e86b104d09ecb38019d3356c to your computer and use it in GitHub Desktop.
Save ahallora/d3ded050e86b104d09ecb38019d3356c to your computer and use it in GitHub Desktop.
Gem dine ønskelister fra AddWish.com til CSV
/*
Sådan gemmer du dine ønskelister fra AddWish.com til CSV
--------------------------------------------------------
1) Log ind på din ønskeliste på www.addwish.com
2) Start console i din browser (fx. tryk [ctrl+shift+i] i Chrome)
3) Copy/paste dette script ind i console og tryk [enter] for at køre det
4) Kopier CSV-teksten som vises i din browser prompt ind i Google sheets og tryk "Split text to columns" og vælg "Semicolon"
5) Din ønskeliste er nu gemt i Sheets
Du kan også gøre det med de ønskelister du følger. :)
*/
(() => {
if (location.host !== "addwish.com")
return alert("Du skal logge ind på www.addwish.com");
const uuid =
document.querySelector("#giftlist[data-uuid]")?.getAttribute("data-uuid") ??
null;
if (!uuid) return alert("Navigér til din ønskeliste på addwish.com");
const isOther = document.querySelector(".giftlist-toolbar.unfollow");
const url = isOther
? "https://addwish.com/getOthersGiftList.html"
: "https://addwish.com/getList.html";
fetch(url, {
headers: {
accept: "application/json, text/javascript, */*; q=0.01",
"content-type": "application/x-www-form-urlencoded",
},
body: "giftListUuid=" + uuid,
method: "POST",
mode: "cors",
credentials: "include",
})
.then((response) => response.json())
.then((data) => {
if (!data) return alert("Beklager, vi kan ikke hente din ønskeliste.");
const wishes = data.wishList.wishes;
csv = [
{
sortOrder: 99999999,
Name: "Navn",
price: "Pris",
url: "URL",
largeImgUrl: "Foto",
},
...wishes,
]
.sort((a, b) => (a.sortOrder > b.sortOrder ? -1 : 1))
.map(
(wish) => `${wish.Name};${wish.price};${wish.url};${wish.largeImgUrl}`
)
.join("\n");
prompt("Kopier denne tekst og indsæt i Google sheets", csv);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment