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

Feature: Replace followed threads links with my posts link #12

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as CONFIG from "./globals-config";
import * as SITE from "./globals-site";

export function isLoggedIn(): boolean {
return (document.head.textContent as string).includes(`'visitorType': 'member'`);
}

export function isOnBSCPreferencesPage(): boolean {
return CONFIG.PATH.PREFERENCES(SITE.PATH.SETTINGS) === document.location.pathname;
}
Expand Down
3 changes: 2 additions & 1 deletion src/globals-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const EXTRA_TAB_MARGIN = `${8}px`;
export const ID = {
siteHeader: "siteHeader",
signoutButton: "signoutForm",
signinButton: "btnSignin",
textarea: "__laika_cnt.textarea.0",
newsTicker: "newsticker",
carousel: "carousel",
Expand Down Expand Up @@ -60,6 +59,7 @@ export const CLASS = {
toolbarButton: "tbButton iconButton noselect",
toolbarButtonIcon: "btnIcon",
toolbarHeadingButton: "header",
hasUnread: "hasUnread",
};

export const PATH = {
Expand All @@ -68,6 +68,7 @@ export const PATH = {
EDIT_MODE_PM: /^\/pm\/(.+\/svara|nytt\-meddelande)/,
EDIT_MODE_REPORT: /^\/(forum|marknad|pm)\/.+\/anmal$/,
SETTINGS: "/profil/installningar",
MY_POSTS: "/profil/inlagg",
SIGNOUT: "/konto/rpc",
ARTICLE: /^\/artikel\//,
GUIDE: /^\/guide\//,
Expand Down
12 changes: 10 additions & 2 deletions src/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SELECTOR from "./selectors";
import { Preferences } from "userscripter/preference-handling";
import P from "preferences";
import {
isLoggedIn,
isInEditMode,
isOnBSCPreferencesPage,
isOnSweclockersSettingsPage,
Expand All @@ -23,6 +24,7 @@ import INSERT_QUOTE_SIGNATURE_BUTTONS from "./operations/insert-quote-signature-
import PREVENT_ACCIDENTAL_SIGNOUT from "./operations/prevent-accidental-signout";
import PREVENT_ACCIDENTAL_UNLOAD from "./operations/prevent-accidental-unload";
import ADAPT_CORRECTIONS_LINK from "./operations/adapt-corrections-link";
import REPLACE_FOLLOWED_THREADS_LINK from "./operations/replace-followed-threads-link";
import MANAGE_CARET_POSITION from "./operations/manage-caret-position";
import REMOVE_MOBILE_SITE_DISCLAIMER from "./operations/remove-mobile-site-disclaimer";
import KEYBOARD_SHORTCUT_PREVIEW from "./operations/keyboard-shortcuts/preview";
Expand Down Expand Up @@ -149,8 +151,8 @@ const OPERATIONS: ReadonlyArray<Operation> = [
}),
new DependentOperation({
description: "prevent accidental signout",
condition: Preferences.get(P.advanced._.prevent_accidental_signout) && !isOnBSCPreferencesPage(),
selectors: { siteHeader: SELECTOR.siteHeader },
condition: Preferences.get(P.advanced._.prevent_accidental_signout) && isLoggedIn(),
selectors: { signoutButton: "#" + SITE.ID.signoutButton },
action: PREVENT_ACCIDENTAL_SIGNOUT,
}),
new DependentOperation({
Expand Down Expand Up @@ -187,6 +189,12 @@ const OPERATIONS: ReadonlyArray<Operation> = [
selectors: { correctionsLink: "#" + SITE.ID.correctionsLink },
action: ADAPT_CORRECTIONS_LINK,
}),
new DependentOperation({
description: "replace followed threads link with a link to my posts",
condition: Preferences.get(P.general._.replace_followed_threads_link) && isLoggedIn(),
selectors: { followedThreadsLink: SELECTOR.followedThreadsLink },
action: REPLACE_FOLLOWED_THREADS_LINK,
}),

// Keyboard shortcuts
new IndependentOperation({
Expand Down
8 changes: 2 additions & 6 deletions src/operations/prevent-accidental-signout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import * as SITE from "globals-site";
import * as CONFIG from "globals-config";
import * as T from "text";

export default (e: { siteHeader: HTMLElement }) => {
const signinButton = e.siteHeader.querySelector("#" + SITE.ID.signinButton);
const signoutButton = e.siteHeader.querySelector("#" + SITE.ID.signoutButton);
if (signoutButton === null) {
return signinButton !== null;
}
export default (e: { signoutButton: HTMLElement }) => {
const signoutButton = e.signoutButton;
const parent = signoutButton.parentElement as HTMLElement;
const safeSignoutForm = signoutButton.cloneNode(true);
signoutButton.remove();
Expand Down
9 changes: 9 additions & 0 deletions src/operations/replace-followed-threads-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as SITE from "globals-site";
import * as T from "text";

export default (e: { followedThreadsLink: HTMLElement }) => {
const link = e.followedThreadsLink as HTMLLinkElement;
link.textContent = T.general.my_posts;
link.href = SITE.PATH.MY_POSTS;
link.classList.remove(SITE.CLASS.hasUnread);
}
5 changes: 5 additions & 0 deletions src/preferences/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default {
default: true,
label: T.preferences.general.insert_web_search_button,
}),
replace_followed_threads_link: new BooleanPreference({
key: "replace_followed_threads_link",
default: false,
label: T.preferences.general.replace_followed_threads_link,
}),
search_engine: new MultichoicePreference({
key: "search_engine",
default: SearchEngine.GOOGLE,
Expand Down
1 change: 1 addition & 0 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export default {
forumLink: `.subForums a[href^="/forum/"]`,
forumPostAuthorLink: `.name a`,
quickReplyForm: `#quickreply form`,
followedThreadsLink: `#${SITE.ID.siteHeader} .profile .option.watched a.label`,
};
4 changes: 4 additions & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ const STYLESHEET_MODULES: ReadonlyArray<StylesheetModule> = [
condition: ALWAYS,
css: filterNewInForum(Preferences.get(P.interests._.uninteresting_subforums)),
},
{
condition: Preferences.get(P.general._.replace_followed_threads_link),
css: require("styles/replace-followed-threads-link"),
},

// Customize content:
{
Expand Down
3 changes: 3 additions & 0 deletions src/styles/replace-followed-threads-link.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
##{getGlobal("SITE.ID.siteHeader")} .profile .watched .icon {
background-position: -250px -100px;
}
2 changes: 2 additions & 0 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const general = {
textarea_size_large: `Stor textruta`,
web_search_button_tooltip: (engine: SearchEngine) => `Sök med ${engine}`,
tooltip_h: `Rubrik`,
my_posts: `Mina inlägg`,
};

export const preferences = {
Expand All @@ -60,6 +61,7 @@ export const preferences = {
improved_corrections: `Bättre rättelsegränssnitt`,
insert_preferences_shortcut: `Genväg till inställningar för ${CONFIG.USERSCRIPT_NAME}`,
insert_web_search_button: `Webbsökknapp`,
replace_followed_threads_link: `Ersätt knappen <em>Följda trådar</em> med <em>Mina inlägg</em>`,
search_engine: {
label: `Sökmotor`,
},
Expand Down