Last active
May 27, 2023 13:24
-
-
Save MaxMatti/8c5cb7328cbc9cbe540b6fad56f9097a to your computer and use it in GitHub Desktop.
Geizhals filter price info - unfinished (but working) script to get an easier overview of prices for filters in geizhals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Geizhals filter price info | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description display price info on geizhals filters | |
// @author You | |
// @match https://geizhals.de/?* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=geizhals.de | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let price_list = []; | |
document.querySelectorAll('div.cell.productlist__price').forEach((e) => { price_list.push(e.innerText); }); | |
window.localStorage.setItem(window.location.href.split('/').at(-1), JSON.stringify(price_list)); | |
let preloading = window.localStorage.getItem('preloading'); | |
if (preloading) { | |
preloading = JSON.parse(preloading); | |
} | |
try { | |
if (preloading && preloading.length > 0) { | |
let preloading_url = preloading[0].split('/').at(-1).replace(/%E4/i, "ä").replace(/%F6/i, "ö").replace(/%DF/i, "ß"); | |
let own_url = window.location.href.split('/').at(-1).replace(/%E4/i, "ä").replace(/%F6/i, "ö").replace(/%DF/i, "ß"); | |
if (decodeURIComponent(preloading_url) == decodeURIComponent(own_url)) { | |
preloading.splice(0, 1); | |
window.localStorage.setItem('preloading', JSON.stringify(preloading)); | |
if (preloading.length > 0) { | |
window.location.href = preloading[0]; | |
} else { | |
window.close(); | |
} | |
} | |
} | |
} catch (err) { | |
console.log(preloading[0].split('/').at(-1), window.location.href.split('/').at(-1)); | |
console.log(err); | |
} | |
document.querySelectorAll('a.xf_i').forEach((e) => { | |
let price_list = window.localStorage.getItem(e.href.split('/').at(-1)); | |
if (price_list && price_list.length > 0) { | |
let elem = document.createElement('span'); | |
elem.innerHTML = JSON.parse(price_list)[0]; | |
elem.classList.add('xf_n'); | |
e.appendChild(elem); | |
} | |
}); | |
document.querySelectorAll('ul.filterbox__list>li.filterbox__list__item.fltrs_searchterm').forEach((e) => { | |
let urls = []; | |
document.querySelectorAll('a.xf_i').forEach((el) => { | |
urls.push(el.href); | |
}); | |
let elem = document.createElement('a'); | |
elem.innerHTML = 'preload all'; | |
elem.onclick = function (urls) { | |
return function () { | |
window.localStorage.setItem('preloading', JSON.stringify(urls)); | |
window.open(urls[0]); | |
}; | |
} (urls); | |
e.appendChild(document.createElement('br')); | |
e.appendChild(elem); | |
}); | |
document.querySelectorAll('ul.filterbox__list>li.filterbox__list__item.fltrs_searchterm').forEach((e) => { | |
let urls = []; | |
document.querySelectorAll('a.xf_i.xf_sel.xf_esel').forEach((el) => { | |
urls.push(el.href); | |
}); | |
let elem = document.createElement('a'); | |
elem.innerHTML = 'preload selected'; | |
elem.onclick = function (urls) { | |
return function () { | |
window.localStorage.setItem('preloading', JSON.stringify(urls)); | |
window.open(urls[0]); | |
}; | |
} (urls); | |
e.appendChild(document.createElement('br')); | |
e.appendChild(elem); | |
}); | |
document.querySelectorAll('th.xf_th').forEach((e) => { | |
let urls = []; | |
e.nextSibling.querySelectorAll('a.xf_i').forEach((el) => { | |
urls.push(el.href); | |
}); | |
let elem = document.createElement('a'); | |
elem.innerHTML = 'preload'; | |
elem.onclick = function (urls) { | |
return function () { | |
window.localStorage.setItem('preloading', JSON.stringify(urls)); | |
window.open(urls[0]); | |
}; | |
} (urls); | |
e.appendChild(document.createElement('br')); | |
e.appendChild(elem); | |
}); | |
})(); |
Added "preload all" and "preload selected" buttons.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Collects data from open tabs and inserts a "preload" button to open (and close) an entire row in tabs (you still need to reload your original page though).