Skip to content

Instantly share code, notes, and snippets.

@pudelkoM
Last active August 29, 2015 14:09
Show Gist options
  • Save pudelkoM/ee2cfeb69e5a4c31f48c to your computer and use it in GitHub Desktop.
Save pudelkoM/ee2cfeb69e5a4c31f48c to your computer and use it in GitHub Desktop.
KC catalog enhancement
// ==UserScript==
// @name KC Catalog Search
// @namespace https://gist.github.com/genericname462
// @icon https://krautchan.net/favicon.ico
// @include https://krautchan.net/catalog/*
// @match https://*.krautchan.net/catalog/*
// @updateURL https://gist.github.com/genericname462/ee2cfeb69e5a4c31f48c/raw/kc_ce.user.js
// @downloadURL https://gist.github.com/genericname462/ee2cfeb69e5a4c31f48c/raw/kc_ce.user.js
// @version 0.0.15
// @grant none
// ==/UserScript==
function filterThreads() {
if (e.value == '') {
refreshCatalog();
return 0;
}
refreshCatalog();
for (var i = 0; i < listTeaser.length; i++) {
if (listTeaser[i].textContent.toLowerCase().indexOf(e.value.toLowerCase()) < 0) {
listTeaser[i].style.display = 'none';
}
}
}
var e = document.createElement('input');
e.name = 'Search';
e.type = 'text';
e.onkeyup = filterThreads;
e.onclick = function () {
e.value = '';
filterThreads();
};
e.placeholder = 'Search';
e.style.float = 'right';
e.style.border = '1px solid #B0B0B0';
e.style.marginBottom = '0.2em';
e.style.textAlign = 'right';
e.style.width = '8em';
document.getElementsByClassName('page_head') [0].appendChild(e);
//-----------------------------------------------------------------
var board = window.location.pathname;
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
function hideThread(id) {
var tList = JSON.parse(localStorage.getItem('threadlist'+board));
if (tList == null) {
localStorage.setItem('threadlist'+board, JSON.stringify([]));
tList = JSON.parse(localStorage.getItem('threadlist'+board));
}
if (!contains(tList, id)) {
tList.push(id);
localStorage.setItem('threadlist'+board, JSON.stringify(tList));
}
return false;
}
function refreshCatalog() {
var tList = JSON.parse(localStorage.getItem('threadlist'+board));
if (tList == null) {
localStorage.setItem('threadlist'+board, JSON.stringify([]));
tList = JSON.parse(localStorage.getItem('threadlist'+board));
}
for (var i = 0; i < listOP.length; i++) {
if (contains(tList, listOP[i].id)) {
listOP[i].parentElement.style.display = 'none';
} else {
listOP[i].parentElement.style.display = '';
}
}
}
function contains(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] == obj) {
return true;
}
}
return false;
}
var listTeaser = document.getElementsByClassName('thread teaser');
var listPost = document.getElementsByClassName('post');
var listOP = document.getElementsByClassName('thread_OP');
for (var i = 0; i < listPost.length; i++) {
var f = document.createElement('div');
f.innerHTML = '[ - ]';
f.style.float = 'right';
f.style.color = 'black';
f.style.zIndex = '10000';
f.onclick = function () {
hideThread(this.parentElement.parentElement.parentElement.parentElement.parentElement.id);
refreshCatalog();
return false;
};
listPost[i].children[0].children[0].firstChild.appendChild(f);
}
var r = document.createElement('div');
r.innerHTML = '[Reset]';
r.style.float = 'right';
r.style.color = 'black';
r.style.fontWeight = 'bold';
r.style.color = 'rgb(34, 59, 187)';
r.style.marginRight = '0.2em';
r.style.cursor = 'pointer';
r.onclick = function () {
localStorage.removeItem('threadlist'+board);
refreshCatalog();
};
insertAfter(r, document.getElementsByName('Search') [0])
refreshCatalog()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment