Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ScrollToLast #209

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions plugins/scrollToLast.plugin.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
//META { "name": "scrollToLast" } *//
/**
* @name ScrollToLatest
* @version 1.0.0
* @description Allows you to automatically scroll down to the most recent messages in the current channel.
* @author square,imafrogowo
*/
Copy link
Owner

@Inve1951 Inve1951 Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add the version number and desciption to the meta


var scrollToLast = function() {
const {
findModuleByProps,
Patcher,
Webpack: { getModule },
} = BdApi;

var Keybinds, onSwitch, cancels = [];
class ScrollToLatest {
constructor() {
this.Name = ScrollToLatest.name;
this.Keybinds = findModuleByProps("MARK_CHANNEL_READ");
this.FluxDispatch = getModule(
(e) => e.dispatch && !e.emitter && !e.commands
);

Keybinds = BdApi.findModuleByProps("MARK_CHANNEL_READ");
this.onSwitch = this.onSwitch.bind(this);
}

onSwitch = (ev) => {
if(("CHANNEL_SELECT" === ev.type || "GUILD_SELECT" === ev.type) && /^\/channels\/(?:@me|\d+)\/\d+$/.test(window.location.pathname))
Keybinds.MARK_CHANNEL_READ.action();
};
onSwitch(Gullible) {
if (Gullible != undefined) {
this.Keybinds.MARK_CHANNEL_READ.action({ target: Gullible });
}
}

return {
getName: () => "Scroll-To-Last",
getDescription: () => "When entering any text channel, scrolls to the bottom and marks it as read.",
getAuthor: () => "square",
getVersion: () => "1.0.2",
start() {
this.FluxDispatch.subscribe("CHANNEL_SELECT", this.onSwitch);
this.FluxDispatch.subscribe("GUILD_SELECT", this.onSwitch);
}

start: () => {
var _ = BdApi.findModuleByProps("_orderedActionHandlers");
_.subscribe("CHANNEL_SELECT", onSwitch); cancels.push(_.unsubscribe.bind(_, "CHANNEL_SELECT", onSwitch));
_.subscribe("GUILD_SELECT", onSwitch); cancels.push(_.unsubscribe.bind(_, "GUILD_SELECT", onSwitch));
},
stop() {
this.FluxDispatch.unsubscribe("CHANNEL_SELECT", this.onSwitch);
this.FluxDispatch.unsubscribe("GUILD_SELECT", this.onSwitch);
}
}

stop: () => {
cancels.forEach(c => c());
cancels = [];
}
};
};
module.exports = ScrollToLatest;