Linkvertise try number 2

This commit is contained in:
Hieuhuy Pham 2025-03-12 14:16:08 -04:00
parent 5082135d62
commit b1c3d9ef84
4 changed files with 20 additions and 13 deletions

1
global.d.ts vendored
View File

@ -19,6 +19,5 @@ declare namespace NodeJS {
enableServices: () => void;
};
}
function linkvertise(id: number, options: { whitelist: string[]; blacklist: string[] }): void;
}
export {};

View File

@ -1,6 +1,6 @@
import { fetchEarlyRelease } from "@/lib/api";
import { Chapter } from "@/lib/types";
import { encodeId } from "@/lib/utils";
import { encodeId, linkvertise } from "@/lib/utils";
import { Ad } from "@/lib/types";
export type searchParams = Promise<{ bookId: string }>;
@ -67,7 +67,7 @@ export default async function BookPage({ searchParams }: { searchParams: searchP
</div>
{early_chapter_from_params && <div className="mt-10 mb-6 text-center">
<a
href={`/early/${encodeId(early_chapter_from_params.book?.documentId || "")}/${encodeId(early_chapter_from_params.documentId)}`}
href={linkvertise(1318261,`https://nulltranslation.com/early/${encodeId(early_chapter_from_params.book?.documentId || "")}/${encodeId(early_chapter_from_params.documentId)}`)}
className="block bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 hover:shadow-xl transition duration-300"
>
<h3 className="text-xl font-semibold text-gray-900 dark:text-white truncate">
@ -87,7 +87,7 @@ export default async function BookPage({ searchParams }: { searchParams: searchP
{early_chapters.map((chapter) => (
<li key={chapter.id}>
<a
href={`/early/${encodeId(chapter.book?.documentId || "")}/${encodeId(chapter.documentId)}`}
href={linkvertise(1318261,`https://nulltranslation.com/early/${encodeId(chapter.book?.documentId || "")}/${encodeId(chapter.documentId)}`)}
className="block bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6 hover:shadow-xl transition duration-300"
>
<h3 className="text-xl font-semibold text-gray-900 dark:text-white truncate">

View File

@ -88,15 +88,6 @@ export default function RootLayout({ children }: { children: React.ReactNode })
});
}}
/>
<Script
src="https://publisher.linkvertise.com/cdn/linkvertise.js"
strategy="afterInteractive"
onLoad={() => {
if (typeof linkvertise === "function") {
linkvertise(1318261, { whitelist: ["https://nulltranslation.com/early/"], blacklist: [] });
}
}}
/>
</head>
<body className="bg-gray-100 dark:bg-gray-900 text-gray-900 dark:text-gray-100 min-h-screen">
<KofiWidget />

View File

@ -38,4 +38,21 @@ export function encodeId(documentId: string): string {
export function decodeId(encodedId: string): string {
const salt = "salty_aff"
return Buffer.from(encodedId, 'base64').toString().replace(salt, '')
}
export function btoa(str: string): string {
let buffer: Buffer;
if (Buffer.isBuffer(str)) {
buffer = str;
} else {
buffer = Buffer.from(str, "binary");
}
return buffer.toString("base64");
}
export function linkvertise(userid: number, link: string): string {
let base_url = `https://link-to.net/${userid}/${Math.floor(Math.random() * 1000)}/dynamic`;
let href = `${base_url}?r=${btoa(encodeURI(link))}`;
return href;
}