Skip to content

Instantly share code, notes, and snippets.

@cocoastorm
Last active November 25, 2023 05:16
Show Gist options
  • Save cocoastorm/4fd1c9ef950912d9a2deca93e4899239 to your computer and use it in GitHub Desktop.
Save cocoastorm/4fd1c9ef950912d9a2deca93e4899239 to your computer and use it in GitHub Desktop.
Elfster Real Wishlist URLs
// ==UserScript==
// @name Replace Wishlist Links - elfster.com
// @namespace Violentmonkey Scripts
// @match https://www.elfster.com/profile/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=elfster.com
// @version 0.1
// @description strip elfster wishlist links so it doesn't die with an adblocker :skull:
// @author cocoastorm <cocoastorm@proton.me>
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// ==/UserScript==
(function() {
'use strict';
console.log('replacing elfster links userscript is running');
function parseURIComponents(path) {
var query = {};
path.split(/[\?&]/).forEach(part => {
var match = part.match(/(?<key>\w+)=(?<value>.*)$/);
if (match && match.groups) {
query[match.groups.key] = match.groups.value;
}
});
return query;
}
function getWishlistItems() {
var re = /https?:\/\/w+\.elfster.com\/v1\/links\/click\/?/i;
var items = document.querySelectorAll('div[idfield="wishId"] a');
for (var i = 0; i < items.length; i++) {
var anchor = items[i];
if (!(re.test(anchor.href || ''))) {
continue;
}
var query = parseURIComponents(anchor.href.replace(re, ''));
if (query && query.url) {
console.log('replacing product URL', anchor);
try {
var realURL = decodeURIComponent(query.url);
anchor.setAttribute('href', realURL);
anchor.href = realURL;
} catch (e) {
console.warn(e);
console.warn('failed to strip elfster link for', anchor);
}
}
}
if (items && items.length) {
return true;
} else {
console.warn('wishlist not found');
}
}
VM.observe(document.body, getWishlistItems);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment