Skip to content

Commit 2ca6ed4

Browse files
committed
Implement toggle for marquee, fix #79
1 parent f095ff5 commit 2ca6ed4

File tree

6 files changed

+70
-14
lines changed

6 files changed

+70
-14
lines changed

src/css/redditChanges.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ html.res-nightmode {
111111
#sr-header-area {
112112
display: none;
113113
}
114+
.redditMarqueEnabled #sr-header-area {
115+
position: fixed !important;
116+
top: 0;
117+
left: 0;
118+
display: block;
119+
overflow-x: scroll !important;
120+
max-width: calc(100vw - 69px);
121+
color: var(--md-sys-color-on-surface-variant);
122+
background-color: var(--md-sys-color-surface);
123+
}
124+
125+
.sr-bar a {
126+
color: var(--md-sys-color-on-surface-variant);
127+
}
114128
[data-event-action="title"],
115129
[data-event-action="title"]:visited {
116130
color: var(--md-sys-color-on-surface) !important;

src/css/resCompat.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@
5353
#NREMail {
5454
/* NREMail doesn't work on mobile devices */
5555
display: none;
56+
}
57+
.redditMarqueEnabled #RESShortcutsEditContainer {
58+
position: fixed;
59+
top: 0;
60+
right: 0;
61+
height: 19px;
62+
color: var(--md-sys-color-on-surface-variant);
63+
background-color: var(--md-sys-color-surface);
64+
}
65+
#RESShortcutsEditContainer * {
66+
background: transparent !important;
5667
}

src/features/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ConsoleSave from "./console_dump";
22
import Expandos from "./expandos";
3+
import Marquee from "./marquee";
34
import RESButtons from "./resButtons";
45
import Sidebar from "./sidebar";
5-
export default [ConsoleSave, Expandos, Sidebar, RESButtons];
6+
export default [ConsoleSave, Expandos, Sidebar, RESButtons, Marquee];

src/features/marquee.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import querySelectorAsync from "../utility/querySelectorAsync";
2+
import { waitForElement } from "../utility/waitForElement";
3+
import { OLFeature, SettingToggle } from "./base";
4+
5+
const marqueeSettingId = "marquee";
6+
7+
export default class Marquee extends OLFeature {
8+
moduleId = "marquee";
9+
moduleName = "Subreddit marquee list";
10+
async init() {
11+
this.settingOptions.push(
12+
new SettingToggle("Marquee toggle", "Enables old reddit marquee", marqueeSettingId, async (toggle) => {
13+
document.documentElement.classList.toggle("redditMarqueEnabled", toggle)
14+
})
15+
);
16+
waitForElement("#sr-header-area", (element) => {
17+
document.body.appendChild(element)
18+
})
19+
}
20+
}

src/features/sidebar/index.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ function setEventListener(type: string, listener: (event: Event) => void) {
2020
}
2121

2222
const swipeIgnoreTags = ["PRE", "CODE"]
23-
23+
const swipeIgnoreMatches = ["#sr-header-area"]
2424
const toggleAbles = [
2525
{name: "Disable random NSFW", settingId: "disableNSFW", className: "ol_noRandNsfw"},
2626
{name: "Disable random", settingId: "disableRandom", className: "ol_noRandom"},
2727
]
28+
function swipeWrapper(callback: ((event: Event) => void)): ((event: Event) => void) {
29+
function wrapped(event: Event) {
30+
const target = event.target as HTMLElement;
31+
if (target && swipeIgnoreTags.includes(target.tagName)) {
32+
return
33+
}
34+
for (const selector of swipeIgnoreMatches) {
35+
if (target.closest(selector) !== null) {
36+
return
37+
}
38+
}
39+
callback(event);
40+
}
41+
return wrapped;
42+
}
2843

2944
export default class Sidebar extends OLFeature {
3045
moduleName = "Sidebar";
@@ -67,27 +82,19 @@ export default class Sidebar extends OLFeature {
6782
console.log("Setting up sidebar events, handlers:", this.subToggle, this.userToggle)
6883
setEventListener("toggleSub", this.subToggle);
6984
setEventListener("toggleUser", this.userToggle);
70-
setEventListener("swiped-right", (event) => {
71-
const target = event.target as HTMLElement;
72-
if (target && swipeIgnoreTags.includes(target.tagName)) {
73-
return
74-
}
85+
setEventListener("swiped-right", swipeWrapper((event) => {
7586
if (this.subSide && this.subSide.classList.contains("active")) {
7687
this.subToggle();
7788
} else if (this.userSide && !this.userSide.classList.contains("active")) {
7889
this.userToggle();
7990
}
80-
});
81-
setEventListener("swiped-left", (event) => {
82-
const target = event.target as HTMLElement;
83-
if (target && swipeIgnoreTags.includes(target.tagName)) {
84-
return
85-
}
91+
}));
92+
setEventListener("swiped-left", swipeWrapper((event) => {
8693
if (this.userSide && this.userSide.classList.contains("active")) {
8794
this.userToggle();
8895
} else if (this.subSide && !this.subSide.classList.contains("active")) {
8996
this.subToggle();
9097
}
91-
});
98+
}));
9299
}
93100
}

src/header/header.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
left: 0;
2020
z-index: 10;
2121
}
22+
.redditMarqueEnabled #ol-header {
23+
top: 18px !important;
24+
}
2225
#ol-header .sort-mode {
2326
color: var(--md-sys-color-on-surface-variant);
2427
font-family: var(--md-sys-typescale-title-small-font-family-name);

0 commit comments

Comments
 (0)