Używam tego już ze dwa miesiące i polecam - aby zainstalować musisz mieć rozszerzenie tampermonkey, dodać nowy skrypt i wkleić w całości to co jest poniżej. #hejto #programowanie #dyskusja
// ==UserScript==
// @name HejtoSeenFilter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.hejto.pl/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const localStorageKey = "commFilter";
const cleanupTimeMS = 86400000;//24h
function filterItems()
{
let articles = document.querySelectorAll('article:not(.parsed)');
let articlesLen = articles.length;
while (articlesLen--) {
let article = articles[articlesLen];
let articleId = getArticleId(article);
if (!articleId) return;
article.setAttribute('article-id', articleId);
let shouldHide = _checkIfItemExists(articleId);
if (shouldHide) {
article.classList.add("hidden");
}
addHideButton(article, shouldHide);
article.classList.add("parsed");
}
}
function hideUnhide(articleId) {
if (!articleId) return;
let article = document.querySelector("article[article-id='"+articleId+"']");
if (!article) return;
var exists = _checkIfItemExists(articleId);
if (!exists) {
_addItem(articleId);
article.classList.add("hidden");
} else {
_removeItem(articleId);
article.classList.remove("hidden");
}
let hideUnhideButton = document.querySelector("a[hide-id='"+articleId+"']");
if (!hideUnhideButton) return;
hideUnhideButton.innerText = exists ? '
}
function getArticleId(article){
if (!article) return;
var articleLink = article.querySelector('div.items-start a.text-grey-500');
if (!articleLink) {
articleLink = article.querySelector('a.text-textPrimary-light');
if (!articleLink) return;
};
return articleLink.getAttribute('href');
}
function addHideButton(article, isHidden = false){
if (!article) return;
let articleId = getArticleId(article);
if (!articleId) return;
//
let innerText = isHidden ? '
return article.insertAdjacentHTML("beforebegin", '<a style="margin-left: auto;" href="javascript:void(0);" title="Ukryj" hide-id="'+articleId+'" onclick="hideUnhide(\\''+articleId+'\\');">'+innerText+'</a>');
}
function _addItem(item){
var items = localStorage[localStorageKey];
if (!items) {
items = JSON.stringify(new Array());
localStorage[localStorageKey] = items;
}
var arr = JSON.parse(items);
var itemObj = {_item: item, _timestamp: new Date()};
var exists = _checkIfItemExists(item);
if (!exists) {
arr.push(itemObj);
items = JSON.stringify(arr);
localStorage[localStorageKey] = items;
}
_cleanLocalStorageExpiredValues();
}
function _removeItem(item){
var items = localStorage[localStorageKey];
if (!items) {
items = JSON.stringify(new Array());
localStorage[localStorageKey] = items;
}
var arr = JSON.parse(items);
var idx = arr.findIndex(x => x._item == item);
if (idx > -1) {
arr.splice(idx, 1);
localStorage[localStorageKey] = JSON.stringify(arr);
}
_cleanLocalStorageExpiredValues();
}
function _checkIfItemExists(item){
var items = localStorage[localStorageKey];
if (!items) return false;
var arr = JSON.parse(items);
var exists = arr.some((elem) => elem._item == item);
return exists;
}
function _cleanLocalStorageExpiredValues(){
var items = localStorage[localStorageKey];
if (!items) {
items = JSON.stringify(new Array());
localStorage[localStorageKey] = items;
}
var arr = JSON.parse(items);
var arrLen = arr.length;
var date = new Date();
while(arrLen--){
var diff = date - new Date(arr[arrLen]._timestamp);
if (diff > cleanupTimeMS) {
arr.splice(arrLen, 1);
}
}
items = JSON.stringify(arr);
localStorage[localStorageKey] = items;
}
function init(){
window.hideUnhide = hideUnhide;
window.setInterval(filterItems, 500);
}
window.addEventListener('load', init);
//window.addEventListener('focus', init);
})();
Zaloguj się aby komentować