Skip to content

Instantly share code, notes, and snippets.

@Brandhand
Last active January 27, 2023 10:28
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 Brandhand/9b72c1735db082d2443ade0bff4fc52b to your computer and use it in GitHub Desktop.
Save Brandhand/9b72c1735db082d2443ade0bff4fc52b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name aaaas
// @description make Listing-Choices; remove doubleEntries in listing
// @version 230127.1
//
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
//
// @match https://www.allesausseraas.de/*
// @exclude https://www.allesausseraas.de/impressum/*
// @exclude https://www.allesausseraas.de/listing/*
// @exclude https://www.allesausseraas.de/maschinenraum/*
// @exclude https://www.allesausseraas.de/meta-wtf/*
// @exclude https://www.allesausseraas.de/spiele/*
// @exclude https://www.allesausseraas.de/spiele/rl/*
// @exclude https://www.allesausseraas.de/streams/*
// @require http://derry/jquery/jquery-3.3.1.min.js
// inject-into content
// ==/UserScript==
/*global console */
// const $ = el => document.querySelector(el);
const $$ = el => document.querySelectorAll(el);
function main() {
rmDoubleEntries();
sportsChoice();
// abbrevMessages();
}
function abbrevMessages() {
function countLines(target) {
const el = target;
const divHeight = el.offsetHeight;
const lineHeight = $(el).css('line-height').replace('px','');
const lines = divHeight / lineHeight;
return lines;
}
// $('ol.comment-list li.comment .comment-content ').each( function() {
$('ol.comment-list li.comment').each( function() {
const lines = countLines(this);
if ( lines > 10 ) {
$(this).css({ "background-color": "yellow" });
}
});
}
function rmDoubleEntries() {
let lastEntry;
function checkText(el) {
const cleanText = el.innerText.replace(/\+$/, '').trim();
if (lastEntry == cleanText) {
el.hidden = true;
} else {
lastEntry = cleanText;
}
}
$$('div.aas_listing > div').forEach((el) => {
checkText(el);
});
$$('div.aas_listing > div > div').forEach((el) => {
checkText(el);
});
}
function sportsChoice() {
if ( $('div.aas_listing').length > 0 ) {
addCss();
makeCheckboxes();
}
function makeCheckboxes() {
const cb = $('<div id="gm_chkbox"></div>');
$('.menu div.aas_form_field select[name="sport"] option').each( function() {
const name = $(this).text();
const val = $(this).attr('value');
if ( val === "0" ) {
return;
}
let newVal;
if ( GM_getValue(val,'unknown') == 'unknown' ) {
newVal = true;
GM_setValue(val,"set");
}
if ( GM_getValue(val) == 'unset' ) {
$(`.aas_listing div.sport-${val}`).hide();
}
const checked = GM_getValue(val) == 'set' ? true : false;
const box = $(`<input type="checkbox" value=${val}>`)
.prop('checked', checked)
.click( function(){
const checked = $(this).prop('checked');
const val = $(this).attr('value');
console.log(`Check: ${checked} Value: ${val}`);
if ( checked ) {
GM_setValue(val,"set");
$(`.aas_listing div.sport-${val}`).show();
} else {
GM_setValue(val,"unset");
$(`.aas_listing div.sport-${val}`).hide();
}
});
$(`<label>${name}<br /></label>`).css('background-color',newVal?'yellow':'').prepend(box).appendTo(cb);
});
cb.prependTo('#sidebar-left');
const alpha_sort = function(a,b) {
return ($(b).text().toUpperCase()) < ($(a).text().toUpperCase()) ? 1 : -1;
};
$('#gm_chkbox label').sort(alpha_sort).appendTo('#gm_chkbox');
}
function addCss(){
GM_addStyle('#gm_chkbox { background-color: lightgreen; position: absolute; width: 15em; }');
GM_addStyle('#gm_chkbox label { font-size: 80%; margin: 0 0 0 5px;}');
GM_addStyle('#gm_chkbox input { margin: 0 3px 0 0; }');
}
}
main();
@Brandhand
Copy link
Author

Brandhand commented Jan 11, 2020

Ich nutze Firefox mit Violentmonkey. Es funktioniert aber auch Tampermonkey.

Screenshot:
Screenshot_2020-01-11

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