Skip to content

Instantly share code, notes, and snippets.

@Kurotaku-sama
Last active June 26, 2024 15:21
Show Gist options
  • Save Kurotaku-sama/5624ebdb0290bdc95809ff1b52e60cbd to your computer and use it in GitHub Desktop.
Save Kurotaku-sama/5624ebdb0290bdc95809ff1b52e60cbd to your computer and use it in GitHub Desktop.
Einige Verbesserungen für kleinanzeigen.de
// ==UserScript==
// @name Kleinanzeigen improvements
// @name:de Kleinanzeigen Verbesserungen
// @namespace https://kurotaku.de
// @version 2.6
// @description Some improvements for kleinanzeigen.de
// @description:de Einige Verbesserungen für kleinanzeigen.de
// @author Kurotaku
// @license MIT
// @sandbox JavaScript
// @match https://www.kleinanzeigen.de/*
// @icon https://www.kleinanzeigen.de/favicon.png
// @updateURL https://gist.github.com/Kurotaku-sama/5624ebdb0290bdc95809ff1b52e60cbd/raw/Kleinanzeigen%2520Verbesserungen.user.js
// @downloadURL https://gist.github.com/Kurotaku-sama/5624ebdb0290bdc95809ff1b52e60cbd/raw/Kleinanzeigen%2520Verbesserungen.user.js
// @require https://gist.github.com/Kurotaku-sama/9ebeb659500f6eee2f780344948e1e8f/raw/kuros_library.user.js
// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// ==/UserScript==
let styles = ``; // Custom styles variable
let location = window.location.href;
await init();
async function init(reinit = false) {
await init_gm_config(); // Initialize the configuration
// Settings menu
if(GM_config.get("script_enabled")) { // Check if the script is disabled in config
location = window.location.href;
if(GM_config.get("remove_ads"))
adblock();
if(GM_config.get("enlarge_images"))
image_enlarge_preview();
if(GM_config.get("show_screenshot_mode_button") && location.includes("m-nachrichten.html"))
show_screenshot_mode_button();
if(GM_config.get("hide_paid_features"))
hide_paid_features();
if(GM_config.get("hide_newletter_checkbox"))
hide_newletter_checkbox();
if (location.includes("p-anzeige-aufgeben-schritt2.html"))
anzeige_aufgeben_seite();
if(GM_config.get("meins_to_nachrichten"))
meins_to_nachrichten();
if(location.includes("s-") && GM_config.get("filter_active"))
filter_search_containing_words();
// This is rquired to reinject the styles and the whole default values because the auto categorize would remove nearly all functions
if(reinit === true) {
let style_sheet = document.createElement("style");
style_sheet.innerText = styles;
document.head.appendChild(style_sheet);
}
else if(!GM_config.get("disable_auto_categorize") && location.includes("p-anzeige-aufgeben-schritt2.html")) // Add the ability to reinitialize the script when auto categorize would mess up the script functions
document.querySelector("#postad-title").addEventListener("focusout", async () => {
await Sleep(3000);
init(true);
});
}
}
function init_gm_config() {
GM_registerMenuCommand('Settings', () => {
GM_config.open();
});
let frame = document.createElement('div');
document.body.appendChild(frame);
GM_config.init(
{
'id': 'configuration',
'title': 'Kleinanzeigen Verbesserungen',
'fields':
{
'script_enabled':
{
'label': 'Aktiviere/Deaktiviere alle Verbesserungen',
'section': ['Allgemeine Einstellungen'],
'type': 'checkbox',
'default': true
},
'remove_ads':
{
'label': 'Werbungen verbergen<br>Ersetzt keinen richtigen Adblocker! Benutze lieber: Ublock Origin',
'type': 'checkbox',
'default': true
},
'enlarge_images':
{
'label': 'Bildvergrößerung beim Hovern während der Suche',
'type': 'checkbox',
'default': true
},
'meins_to_nachrichten':
{
'label': 'Nachrichten statt Anzeigen bei "Meins"',
'type': 'checkbox',
'default': true
},
'show_screenshot_mode_button':
{
'label': 'Screenshot Modus Button aktivieren',
'type': 'checkbox',
'default': true
},
'hide_paid_features':
{
'label': 'Verberge fast alle bezahlbare Zusatzoptionen',
'type': 'checkbox',
'default': false
},
'hide_newletter_checkbox':
{
'label': 'Verberge die Newsletter anmeldung über dem "Anzeige aufgeben" Button',
'type': 'checkbox',
'default': true
},
'disable_auto_categorize':
{
'label': 'Deaktiviere automatische Kategorieermittlung anhand des Titels',
'section': ['"Anzeige aufgeben" Standardwerte'],
'type': 'checkbox',
'default': false
},
'disable_buy_now':
{
'label': 'Direkt kaufen standardmäßig deaktivieren',
'type': 'checkbox',
'default': true
},
'default_price':
{
'label': 'Preis',
'type': 'text',
'default': ''
},
'default_price_type':
{
'label': 'Preistyp',
'type': 'select',
'options': ['Festpreis', 'VB', 'Zu verschenken'],
'default': 'Festpreis'
},
'default_only_pickup':
{
'label': 'Standardmäßig nur Abholung',
'type': 'checkbox',
'default': false
},
'default_description':
{
'label': 'Beschreibung',
'type': 'textarea',
'default': ''
},
'filter_active':
{
'label': 'Filterfunktion aktivieren',
'section': ['Suchfilter'],
'type': 'checkbox',
'default': false
},
'filter_search_containing_words':
{
'label': 'Filterbegriffe (jeder Begriff ein eine neue Zeile)',
'type': 'textarea',
'default': ''
},
},
'events': {
'init': () => {GM_config.set("filter_search_containing_words", GM_config.get("filter_search_containing_words").replace(/^\s*$(?:\r\n?|\n)/gm, ""))}, // To prevent blank lines
'save': () => {location.reload()},
},
'frame': frame,
'css': '#configuration {height:auto !important; width:auto !important; padding:20px !important;max-height: 600px !important;max-width:500px !important; border: 3px solid #000 !important} #configuration .section_header {background: unset; color:unset;} #configuration .config_header {font-size:17pt; font-weight:bold} #configuration .config_var {margin-top:10px; display: flex;} .config_var :nth-child(2) {order:-1; margin-right:10px;} #configuration_buttons_holder {text-align: center;} #configuration #configuration_resetLink {color:#fff;} #configuration #configuration_default_price_var, #configuration #configuration_default_price_type_var, #configuration #configuration_default_description_var, #configuration #configuration_filter_search_containing_words_var {display : block;}'
});
}
async function adblock() {
// Try 10 times to remove the ads
for(let i = 0; i < 10; i++) {
remove_single_element(".site-base--left-banner > div");
remove_single_element(".site-base--right-banner > div");
remove_single_element("#brws_banner-supersize");
remove_single_element("#btf-billboard");
remove_array_elements("[id^='liberty']");
//remove_array_elements("#srchrslt-adtable .ad-listitem:not(.lazyload-item)");
await Sleep(1000);
}
}
function remove_single_element(selector) {
let element = document.querySelector(selector);
if(element)
element.remove();
}
function remove_array_elements(selector) {
let elements = document.querySelectorAll(selector);
if(elements && elements.length > 0)
elements.forEach((element) => element.remove());
}
function image_enlarge_preview() {
let imageboxes = document.querySelectorAll(".ad-listitem .srpimagebox img");
styles += `
.enlarged-image {display: none; height: unset !important;position: absolute;top:0;left:0; z-index: 100 !important;min-width:200px; max-width: 400px !important; max-height: 400px !important; width: fit-content !important;}
.aditem-image:hover .enlarged-image {display : block;}
.ad-listitem .aditem-image {z-index: unset;}
.ad-listitem .aditem-image .imagebox.srpimagebox {overflow: unset}
.ad-listitem .aditem-image .imagebox.srpimagebox img {z-index:2}`;
imageboxes.forEach((element) => {
let data_imgsrc = element.getAttribute("src");
if(data_imgsrc) { // Check if an image exist
let img_url = `${data_imgsrc.split("?")[0]}?rule=$_59.JPG`;
let new_element = `<img src=${img_url} class='enlarged-image'>`;
element.insertAdjacentHTML("beforebegin", new_element);
}
});
}
function show_screenshot_mode_button() { // Credits go to Shirotaku who had the idea and gave me his script, I just added it here with a couple of changes
wait_for_element('.Messagebox .infinite-scroll-component').then(async () => {
let button = `<button id="button_screenshot_mode" class="Button--Body">Screenshotmodus aktivieren</button>`;
let top_bar = document.querySelector(".Messagebox .Messagebox--Grid--Row1");
top_bar.style.paddingRight = "10px";
top_bar.style.marginRight = "0%";
top_bar.insertAdjacentHTML("beforeend", button);
document.querySelector("#button_screenshot_mode").addEventListener("click", async () => {
if (!document.querySelector(".Messagebox--Grid--Row2--Col1").hidden) {
document.querySelector(".Messagebox--Grid--Row2--Col1").hidden = true;
document.querySelector(".Messagebox--Grid--Row2--Col2").style.width = "100%";
document.querySelector(".Messagebox--Grid--Row2").style.height = "100%";
document.querySelector(".Conversation--Grid--Row3").style.height = `\"${document.querySelector(".MessageList").scrollHeight}px\"`;
document.querySelector("#button_screenshot_mode").innerHTML = "Screenshotmodus deaktivieren";
} else {
document.querySelector(".Messagebox--Grid--Row2--Col1").hidden = false;
document.querySelector(".Messagebox--Grid--Row2").style.height = '';
document.querySelector(".Messagebox--Grid--Row2--Col2").style.width = '';
document.querySelector("#button_screenshot_mode").innerHTML = "Screenshotmodus aktivieren";
}
});
});
}
function hide_paid_features() {
// Produktseite Box ganz oben
// Meine Anzeigen
// Anzeige aufgeben "Verkaufschance erhöhen..."
styles += `#pvap-featrs #command,.manageaditem-featuretable,#postad-features {display : none;}`;
}
function hide_newletter_checkbox() {
styles += `#postad-publish .l-container-row .l-row.a-double-margin.l-container-row {display : none;}`;
}
async function anzeige_aufgeben_seite() {
let disable_auto_categorize = GM_config.get("disable_auto_categorize");
let disable_buy_now = GM_config.get("disable_buy_now");
let default_price = GM_config.get("default_price");
let default_price_type = GM_config.get("default_price_type");
let default_only_pickup = GM_config.get("default_only_pickup");
let default_description = GM_config.get("default_description");
// Disable auto categorize with title
if (disable_auto_categorize) {
await Sleep(1000); // Delay is required sadly bcs code that adds the events start after page loaded
document.querySelector("#postad-title").replaceWith(document.querySelector("#postad-title").cloneNode(true)); // Clone element to remove the event
}
// Disable buy now
if (disable_buy_now) {
wait_for_element('#radio-buy-now-no').then(async () => {
// document.querySelector("#radio-buy-now-yes").checked = false;
// document.querySelector("#radio-buy-now-no").checked = true
document.querySelector("#radio-buy-now-no").click();
});
// Old function
/*wait_for_element('#buy-now-toggle').then(async () => {
if(document.querySelector(".InfoBanner") !== null)
document.querySelector("#buy-now-toggle").click();
});*/
}
// Field Price
let field_price = document.querySelector("#pstad-price");
if (field_price)
field_price.value = default_price;
// Field Price Type
let field_pricetype = document.querySelector("#priceType");
if (default_price_type) {
let value;
switch(default_price_type) {
case "Festpreis":
value = "FIXED";
break;
case "VB":
value = "NEGOTIABLE";
break;
case "Zu verschenken":
value = "GIVE_AWAY";
break;
default:
value = "FIXED";
}
if(field_pricetype)
field_pricetype.value = value;
}
// Field Shipping
if(default_only_pickup) {
wait_for_element(".ShippingPickupSelector input[data-testid='radio-pickup']").then(async () => {
let radiobutton = document.querySelector(".ShippingPickupSelector input[data-testid='radio-pickup']");
if(radiobutton)
radiobutton.click();
});
}
// Field Description
let field_description = document.querySelector("#pstad-descrptn");
if (field_description)
field_description.value = default_description;
}
function meins_to_nachrichten() {
wait_for_element('#site-mainnav-my').then(async () => {
document.querySelector("#site-mainnav-my-link").innerHTML = document.querySelector("#site-subnav-msgbox").innerHTML;
document.querySelector("#site-mainnav-my-link").href = document.querySelector("#site-subnav-msgbox").href;
});
}
function filter_search_containing_words() {
let items = document.querySelectorAll(".ad-listitem.lazyload-item"); // Get all items from page
let words = GM_config.get("filter_search_containing_words").split("\n"); // Get filter words as array
if(words && words.length > 0 && words[0].trim() != "")
items.forEach(item => {
let title = item.querySelector(".ellipsis").textContent.toLowerCase().trim(); // Prepare the title for check
for(let i = 0; i < words.length; i++) {
if(title.includes(words[i].toLowerCase().trim())) { // Check if title contains a word from filter list
item.remove();
break;
}
}
});
}
// Add custom styles
styles += ``;
// Insert custom Styles
let style_sheet = document.createElement("style");
style_sheet.innerText = styles;
document.head.appendChild(style_sheet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment