-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdmb-tweaker-2.user.js
142 lines (135 loc) · 4.97 KB
/
sdmb-tweaker-2.user.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ==UserScript==
// @name SDMB Tweaker 2
// @namespace BigTSDMB
// @version 2.1.3
// @description New tweaks for the new(er) Discourse SDMB
// @author BigTSDMB
// @updateURL https://openuserjs.org/meta/BigTSDMB/SDMB_Tweaker_2.meta.js
// @downloadURL https://openuserjs.org/install/BigTSDMB/SDMB_Tweaker_2.user.js
// @license MIT
// @match https://boards.straightdope.com/*
// @grant none
// @run-at document-start
// @require https://openuserjs.org/src/libs/BigTSDMB/setStyle.js
// ==/UserScript==
/* jshint esversion: 6 */
/* globals setStyle */
let optionsList = JSON.parse(localStorage.getItem('sdmb-tweaker-options') || '{}');
let style = `
.cooked a:not(.mention)/*, .d-editor-preview a:not(.mention)*/ {
text-decoration: underline;
text-decoration-skip: trailing-spaces; /* currently doesn't work. used gradient workaround */
}
.cooked :not(.source) > a:not(.mention):visited, aside.onebox .onebox-body a[href]:visited {
color: var(--success-hover);
}
a:hover, .title a:hover {
text-decoration: underline !important;
}
.title a, .menu-panel a:hover {
text-decoration: none !important;
}
.badge-notification.clicks {
left: -0.7ch;
margin-right: -0.7ch;
border-radius: 10px 10px 10px 0px;
background: radial-gradient(67% 79%, var(--primary-low) 68%, transparent 73%),
linear-gradient(to left, var(--primary-low) 60%, var(--secondary) 60%);
}
.MJXc-TeX-sans-R {
font-family: var(--font-family) !important;
}
`;
if (!optionsList['sticky-avatars']) { style += `
.topic-post.sticky-avatar .topic-avatar {
position: unset !important;
}
`; }
if (optionsList['bolder-titles']) { style +=`
.topic-list .main-link a.title {
font-weight: bold;
}
.visited .main-link a.title {
font-weight: normal;
}
`; }
setStyle(style, 'sdmb-tweaker');
addEventListener('DOMContentLoaded', () => {
if (document.querySelector('[data-theme-name="straight dope light"]')) {
setStyle(`
a, .cooked :not(.source) > a:active:not(.mention), /*aside.onebox .onebox-body a[href],*/
.cooked :not(.source) > a:hover:not(.mention) {
color: var(--tertiary-high);
}
.cooked :not(.source) > a:not(.mention):visited, aside.onebox .onebox-body a[href]:visited {
color: #551a8b; /* default visited color in most browsers */
}
`, 'sdmb-tweaker-SDL');
} else if (document.querySelector('[data-theme-name="minima"]')) {
setStyle(`
.MJXc-TeX-sans-R {
font-family: sans-serif !important;
}
`, 'sdmb-tweaker-Min');
}
});
//add option(s)
function createOptionHTML(optionList) {
let output = '<legend class="control-label">SDMB Tweaker</legend>';
for (let key in optionList) {
output += `
<div class="controls">
<label class="checkbox-label">
<input id="${key}" type="checkbox" class="ember-checkbox sdmb-tweaker-setting">
${optionList[key]}
</label>
</div>
`;
};
return output;
}
function addOptions() {
let observer = new MutationObserver( () => {
if (document.querySelector('fieldset.sdmb-tweaker-preferences')) { return; }
let fieldset = document.querySelector('fieldset.other');
if (fieldset) {
observer.disconnect();
let additionalOptions = document.createElement('fieldset');
additionalOptions.className = 'control-group sdmb-tweaker-preferences';
fieldset.after(additionalOptions);
additionalOptions.innerHTML = createOptionHTML({
'bolder-titles': 'Make unread thread titles more bold',
'sticky-avatars': 'Enable sticky avatars',
});
let optionsList = JSON.parse(localStorage.getItem('sdmb-tweaker-options') || '{}');
let settingsList = document.getElementsByClassName('sdmb-tweaker-setting');
for (let option of settingsList) {
if (optionsList[option.id]) { option.checked = true; }
option.addEventListener('change', () => {
optionsList[option.id] = option.checked;
localStorage.setItem('sdmb-tweaker-options', JSON.stringify(optionsList) );
});
}
}
}); observer.observe(document.body, { childList:true, subtree: true });
}
if (location.href.endsWith('/interface')) { addEventListener('DOMContentLoaded', addOptions); }
addEventListener('popstate', addOptions); //detects back/forward buttons
window.history.pushState = new Proxy(window.history.pushState, { //detects URL changes
apply: (target, thisArg, argArray) => {
addOptions();
return target.apply(thisArg, argArray);
},
});
/* apply to all DOM mutations. Hopefully unneeded:
addEventListener('DOMContentLoaded', () => {
var observer = new MutationObserver(main_script);
observer.observe(document, { childList:true, subtree: true });
});
function main_script(mutation) {
document.querySelectorAll('.badge-notification.clicks').forEach( badge => {
let spacer = badge.previousSibling;
if(spacer.textContent == ' ') { spacer.textContent = ''; }
});
}
*/