Skip to content

Commit 7100993

Browse files
committed
feat(plugin): thread raw headings
1 parent 63d7ea8 commit 7100993

File tree

12 files changed

+124
-16
lines changed

12 files changed

+124
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "complexity",
33
"displayName": "Complexity - Perplexity AI Supercharged",
4-
"version": "1.6.4.0",
4+
"version": "1.6.5.0",
55
"author": "pnd280",
66
"description": "Supercharge your Perplexity AI",
77
"type": "module",

src/data/plugins-data/plugins-data.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ export const PLUGINS_METADATA: CplxPluginMetadata = {
101101
dependentDomObservers: ["coreDomObserver:thread:messageBlocks"],
102102
dependentCorePlugins: ["spaRouter", "reactVdom"],
103103
},
104+
"thread:rawHeadings": {
105+
id: "thread:rawHeadings",
106+
routeSegment: "thread-raw-headings",
107+
title: "Thread: Raw Headings",
108+
description: "Prevent headings from being rendered as follow-up links",
109+
tags: ["new", "ui", "ux"],
110+
},
104111
"thread:betterMessageToolbars": {
105112
id: "thread:betterMessageToolbars",
106113
routeSegment: "thread-better-message-toolbars",
@@ -116,7 +123,7 @@ export const PLUGINS_METADATA: CplxPluginMetadata = {
116123
title: "Instant Thread Message Rewrite Buttons",
117124
description:
118125
"Rewrite messages with the same model without opening the original Rewrite dropdown menu",
119-
tags: ["new", "ui", "ux"],
126+
tags: ["ui", "ux"],
120127
uiGroup: ["thread:messageBlocks:queryHoverContainer"],
121128
dependentDomObservers: ["coreDomObserver:thread:messageBlocks"],
122129
dependentCorePlugins: ["spaRouter", "reactVdom"],
@@ -136,7 +143,7 @@ export const PLUGINS_METADATA: CplxPluginMetadata = {
136143
title: "Canvas",
137144
description:
138145
"Visualize and interact with generated content side by side. Similar to claude.ai's artifacts. Very experimental",
139-
tags: ["new", "experimental", "desktopOnly", "ui"],
146+
tags: ["experimental", "desktopOnly", "ui"],
140147
dependentPlugins: ["thread:betterCodeBlocks"],
141148
dependentDomObservers: [
142149
"coreDomObserver:thread:messageBlocks",

src/entrypoints/content-scripts/loaders/loaders.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import "@/plugins/thread-better-message-toolbars/message-words-and-characters-co
4040
import "@/plugins/thread-better-message-toolbars/collapsible-query/populate-original-height";
4141
import "@/plugins/instant-rewrite-button/native-btn-bind";
4242
import "@/plugins/custom-thread-container-width";
43+
import "@/plugins/thread-raw-headings";
4344

4445
// Home Plugins
4546
import "@/plugins/home-custom-slogan";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Image } from "@/components/ui/image";
2+
import { Switch } from "@/components/ui/switch";
3+
import useExtensionLocalStorage from "@/services/extension-local-storage/useExtensionLocalStorage";
4+
5+
export default function RawHeadingsPluginDetails() {
6+
const { settings, mutation } = useExtensionLocalStorage();
7+
const pluginSettings = settings?.plugins["thread:rawHeadings"];
8+
9+
if (!settings) return null;
10+
11+
return (
12+
<div className="x-flex x-max-w-lg x-flex-col x-gap-4">
13+
<Switch
14+
textLabel="Enable"
15+
checked={pluginSettings?.enabled ?? false}
16+
onCheckedChange={({ checked }) => {
17+
mutation.mutate((draft) => {
18+
draft.plugins["thread:rawHeadings"].enabled = checked;
19+
});
20+
}}
21+
/>
22+
23+
<div className="x-mx-auto x-w-full x-max-w-[700px]">
24+
<Image
25+
src="https://i.imgur.com/IQJbP39.png"
26+
alt="raw-headings"
27+
className="x-w-full"
28+
/>
29+
</div>
30+
</div>
31+
);
32+
}

src/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/plugins-details.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ExportThreadPluginDetails from "@/entrypoints/options-page/dashboard/page
1414
import FullWidthFollowUpQueryBoxPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/FullWidthFollowUpQueryBox";
1515
import InstantThreadMessageRewriteButtonsPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/InstantThreadMessageRewriteButtons";
1616
import PromptHistoryPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/PromptHistory";
17+
import RawHeadingsPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/RawHeadings";
1718
import SidebarToggleableRecentThreadsPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/SidebarToggleableRecentThreads";
1819
import SlashCommandMenuPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/SlashCommandMenu";
1920
import SpaceNavigatorPluginDetails from "@/entrypoints/options-page/dashboard/pages/plugins/components/plugin-details/content/SpaceNavigator";
@@ -37,6 +38,7 @@ export const PLUGIN_DETAILS: PluginPluginDetails = {
3738
spaceNavigator: <SpaceNavigatorPluginDetails />,
3839
commandMenu: <CommandMenuPluginDetails />,
3940
"thread:betterMessageToolbars": <BetterThreadMessageToolbarsPluginDetails />,
41+
"thread:rawHeadings": <RawHeadingsPluginDetails />,
4042
"thread:betterCodeBlocks": <BetterCodeBlocksPluginDetails />,
4143
"thread:toc": <ThreadToCPluginDetails />,
4244
"thread:canvas": <CanvasPluginDetails />,

src/hooks/useCopyPplxThread.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ async function copyMessageWithCitations({
124124
`${content.answer}\n\nCitations:\n${ThreadExport.formatWebResults(content.webResults)}`,
125125
);
126126
} else {
127-
navigator.clipboard.writeText(content.answer);
127+
const cleanAnswer = content.answer.replace(
128+
/\[(.*?)\]\(pplx:\/\/action\/followup\)/g,
129+
"$1",
130+
);
131+
132+
navigator.clipboard.writeText(cleanAnswer);
128133
}
129134
}
130135

src/plugins/export-thread/useObserver.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export default function useObserver() {
1111
deepEqual,
1212
);
1313

14-
const navbarChildren = useThreadDomObserverStore(
15-
(state) => state.$navbar?.find(">div").children().toArray() ?? null,
14+
const $navbar = useThreadDomObserverStore(
15+
(state) => state.$navbar,
1616
deepEqual,
1717
);
1818

19+
const $bookmarkButton = useMemo(() => {
20+
return $navbar?.find(`button[aria-label="Save to Bookmarks"]`) ?? null;
21+
}, [$navbar]);
22+
1923
const isAnyMessageBlockInFlight = useMemo(() => {
2024
return messageBlocks?.some((block) => block.states.isInFlight);
2125
}, [messageBlocks]);
@@ -29,18 +33,18 @@ export default function useObserver() {
2933
return null;
3034
}
3135

32-
return createPortalContainer(navbarChildren);
36+
return createPortalContainer($navbar, $bookmarkButton);
3337
}
3438

35-
function createPortalContainer(navbarChildren: HTMLElement[] | null) {
36-
if (navbarChildren == null) return null;
37-
38-
const $anchor = $(navbarChildren).last().children().first();
39-
40-
if (!$anchor.length) return null;
39+
function createPortalContainer(
40+
$navbar: JQuery<HTMLElement> | null,
41+
$bookmarkButton: JQuery<HTMLElement> | null,
42+
) {
43+
if ($navbar == null || !$navbar.length) return null;
44+
if ($bookmarkButton == null || !$bookmarkButton.length) return null;
4145

42-
const $existingPortalContainer = $(navbarChildren).find(
43-
`> [data-cplx-component="${INTERNAL_ATTRIBUTES.THREAD.NAVBAR_CHILD.EXPORT_THREAD_BUTTON}"]`,
46+
const $existingPortalContainer = $navbar?.find(
47+
`[data-cplx-component="${INTERNAL_ATTRIBUTES.THREAD.NAVBAR_CHILD.EXPORT_THREAD_BUTTON}"]`,
4448
);
4549

4650
if ($existingPortalContainer.length) return $existingPortalContainer[0];
@@ -49,7 +53,7 @@ function createPortalContainer(navbarChildren: HTMLElement[] | null) {
4953
INTERNAL_ATTRIBUTES.THREAD.NAVBAR_CHILD.EXPORT_THREAD_BUTTON,
5054
);
5155

52-
$anchor.before($portalContainer);
56+
$bookmarkButton.parent().prepend($portalContainer);
5357

5458
return $portalContainer[0];
5559
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { spaRouteChangeCompleteSubscribe } from "@/plugins/_api/spa-router/listeners";
2+
import styles from "@/plugins/thread-raw-headings/styles.css?inline";
3+
import { PluginsStatesService } from "@/services/plugins-states";
4+
import { csLoaderRegistry } from "@/utils/cs-loader-registry";
5+
import { insertCss, whereAmI } from "@/utils/utils";
6+
7+
let cleanup: () => void | null;
8+
9+
csLoaderRegistry.register({
10+
id: "plugin:thread:rawHeadings",
11+
dependencies: ["cache:pluginsStates"],
12+
loader: () => {
13+
const pluginsEnableStates =
14+
PluginsStatesService.getEnableStatesCachedSync();
15+
16+
if (!pluginsEnableStates["thread:rawHeadings"]) return;
17+
18+
rawHeadings(whereAmI());
19+
20+
spaRouteChangeCompleteSubscribe((url) => {
21+
rawHeadings(whereAmI(url));
22+
});
23+
},
24+
});
25+
26+
function rawHeadings(location: ReturnType<typeof whereAmI>) {
27+
cleanup?.();
28+
29+
if (location !== "thread") return;
30+
31+
const removeCss = insertCss({
32+
css: styles,
33+
id: "raw-headings",
34+
});
35+
36+
cleanup = () => removeCss();
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[location="thread"] {
2+
h2,
3+
h3,
4+
h4,
5+
h5,
6+
h6,
7+
strong {
8+
cursor: text;
9+
> button.hover\:duration-80 {
10+
user-select: text;
11+
pointer-events: none;
12+
text-decoration: none;
13+
}
14+
}
15+
}

src/services/extension-local-storage/plugins.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const PluginsSchema = z.object({
3131
spaceNavigator: PluginSettingsSchema,
3232
"sidebar:toggleableRecentThreads": PluginSettingsSchema,
3333
"thread:toc": PluginSettingsSchema,
34+
"thread:rawHeadings": PluginSettingsSchema,
3435
"thread:betterMessageToolbars": PluginSettingsSchema.extend({
3536
sticky: z.boolean(),
3637
editQueryButton: z.boolean(),

src/services/extension-local-storage/storage-defaults.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export const DEFAULT_STORAGE: ExtensionLocalStorage = {
4848
"thread:toc": {
4949
enabled: false,
5050
},
51+
"thread:rawHeadings": {
52+
enabled: false,
53+
},
5154
"thread:betterMessageToolbars": {
5255
enabled: false,
5356
sticky: true,

src/utils/cs-loader-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const LOADER_IDS = [
5454
"plugin:queryBox:fullWidthFollowUp",
5555
"plugin:home:customSlogan",
5656
"plugin:home:hideHomepageWidgets",
57+
"plugin:thread:rawHeadings",
5758

5859
"store:colorScheme",
5960
"store:pplxCookies",

0 commit comments

Comments
 (0)