-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathignore-annoying-threads.js
More file actions
79 lines (59 loc) · 1.88 KB
/
ignore-annoying-threads.js
File metadata and controls
79 lines (59 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ==UserScript==
// @name Ignore Annoying Threads
// @namespace https://github.com/LittleBitwise/
// @version 0.5
// @description Adds an option to ignore threads by title, which should not be displayed in discovery feeds. Todo: Undo ignores without manually clearing LocalStorage.
// @author LittleBitwise
// @match https://community.secondlife.com/discover/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=secondlife.com
// @grant none
// ==/UserScript==
'use strict';
const LOCAL_STORAGE_KEY = 'ignoredTitles';
const IGNORE_BUTTON_CLASS = 'ipsTag_prefix';
const IGNORE_BUTTON_TEXT = 'Ignore';
// Main element selector
function selectedElements() {
let result = document.querySelectorAll(
'li.ipsStreamItem'
);
return result;
}
// Process each main element
selectedElements().forEach((element) => {
let title = element.querySelector('.ipsStreamItem_header .ipsContained > a').textContent;
let isIgnored = isIgnoredCheck(title);
if (isIgnored) {
element.remove();
} else {
element.appendChild(createButton(title, element));
}
})
// Utility functions
function isIgnoredCheck(title) {
let storage = localStorage.getItem(LOCAL_STORAGE_KEY);
storage = JSON.parse(storage);
if (storage) {
return storage?.includes(title) ?? false;
}
return false;
}
function addToIgnore(title, element) {
let storage = localStorage.getItem(LOCAL_STORAGE_KEY);
if (storage) {
storage = JSON.parse(storage);
storage.push(title);
} else {
storage = [title];
}
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(storage));
element.remove();
}
function createButton(title, element) {
let button = document.createElement('button');
button.addEventListener('click', () => addToIgnore(title, element));
button.classList.add(IGNORE_BUTTON_CLASS);
button.textContent = IGNORE_BUTTON_TEXT;
button.style.marginTop = '10px';
return button;
}