Skip to content

Commit

Permalink
(chore): biome lint + format
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Sep 7, 2024
1 parent 3ed303a commit 30f0ca1
Show file tree
Hide file tree
Showing 88 changed files with 3,278 additions and 3,317 deletions.
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

96 changes: 49 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
{
"name": "betterbuff",
"displayName": "BetterBuff",
"description": "Enhance your website experience on Buff163",
"author": "Rums",
"version": "1.0.0",
"license": "MIT",
"homepage": "https://github.com/GODrums/BetterBuff",
"scripts": {
"dev": "wxt",
"dev:firefox": "wxt -b firefox --mv3",
"build": "wxt build",
"build:firefox": "wxt build -b firefox --mv3",
"zip": "wxt zip",
"zip:firefox": "wxt zip -b firefox --mv3",
"update": "pnpm up --latest",
"check": "svelte-check --tsconfig ./tsconfig.json",
"postinstall": "wxt prepare",
"submit": "wxt submit",
"submit:dry": "wxt submit --dry-run"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@tailwindcss/typography": "^0.5.13",
"@tsconfig/svelte": "^5.0.4",
"autoprefixer": "^10.4.19",
"daisyui": "^4.11.1",
"postcss": "^8.4.38",
"publish-browser-extension": "^2.1.3",
"svelte": "^4.2.17",
"svelte-check": "^3.7.1",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"wxt": "^0.18.2"
},
"dependencies": {
"@types/chrome": "^0.0.268",
"bits-ui": "^0.21.9",
"clsx": "^2.1.1",
"decimal": "^0.0.2",
"decimal.js": "^10.4.3",
"svelte-radix": "^1.1.0",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1"
}
"name": "betterbuff",
"displayName": "BetterBuff",
"description": "Enhance your website experience on Buff163",
"author": "Rums",
"version": "1.0.0",
"license": "MIT",
"homepage": "https://github.com/GODrums/BetterBuff",
"scripts": {
"dev": "wxt",
"dev:firefox": "wxt -b firefox --mv3",
"build": "wxt build",
"build:firefox": "wxt build -b firefox --mv3",
"zip": "wxt zip",
"zip:firefox": "wxt zip -b firefox --mv3",
"update": "pnpm up --latest",
"check": "svelte-check --tsconfig ./tsconfig.json",
"postinstall": "wxt prepare",
"submit": "wxt submit",
"submit:dry": "wxt submit --dry-run",
"lint": "biome lint --write src/",
"format": "biome format --write src/ && biome check --write src/"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@tailwindcss/typography": "^0.5.13",
"@tsconfig/svelte": "^5.0.4",
"autoprefixer": "^10.4.19",
"daisyui": "^4.11.1",
"postcss": "^8.4.38",
"publish-browser-extension": "^2.1.3",
"svelte": "^4.2.17",
"svelte-check": "^3.7.1",
"tailwindcss": "^3.4.3",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"wxt": "^0.18.2"
},
"dependencies": {
"@types/chrome": "^0.0.268",
"bits-ui": "^0.21.9",
"clsx": "^2.1.1",
"decimal": "^0.0.2",
"decimal.js": "^10.4.3",
"svelte-radix": "^1.1.0",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1"
}
}
38 changes: 19 additions & 19 deletions src/entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { BetterBuff } from "$lib/@types/BetterBuff";
import type { BetterBuff } from '$lib/@types/BetterBuff';

export default defineBackground(() => {
browser.runtime.onInstalled.addListener(() => {
console.log('Extension installed, version: ', browser.runtime.getManifest().version);
});
browser.runtime.onInstalled.addListener(() => {
console.log('Extension installed, version: ', browser.runtime.getManifest().version);
});

browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
const url = new URL(tab.url || '');
if (url.hostname === "buff.163.com" && changeInfo.status === 'complete') {
const state: BetterBuff.URLState = {
path: url.pathname,
search: url.search,
hash: url.hash
};
console.log('[BetterBuff] URL changed to: ', state);
browser.tabs.sendMessage(tabId, {
type: 'BetterBuff_URL_CHANGED',
state
});
}
});
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
const url = new URL(tab.url || '');
if (url.hostname === 'buff.163.com' && changeInfo.status === 'complete') {
const state: BetterBuff.URLState = {
path: url.pathname,
search: url.search,
hash: url.hash,
};
console.log('[BetterBuff] URL changed to: ', state);
browser.tabs.sendMessage(tabId, {
type: 'BetterBuff_URL_CHANGED',
state,
});
}
});
});
123 changes: 61 additions & 62 deletions src/entrypoints/buff.content/index.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,91 @@
import { activateHandler } from "$lib/util/eventListeners";
import { activateURLHandler } from "$lib/util/urlListener";
import { ExtensionStorage, setBuffCrx } from "$lib/util/storage";
import { adjustTooltip } from "$lib/util/Adjust_Tooltip";
import { adjustTooltip } from '$lib/util/Adjust_Tooltip';
import { activateHandler } from '$lib/util/eventListeners';
import { ExtensionStorage, setBuffCrx } from '$lib/util/storage';
import { activateURLHandler } from '$lib/util/urlListener';

export default defineContentScript({
cssInjectionMode: "ui",
matches: ["*://*.buff.163.com/*"],
runAt: 'document_end',
async main(ctx) {
initContentScript(await ExtensionStorage.enabled.getValue(), ctx);
cssInjectionMode: 'ui',
matches: ['*://*.buff.163.com/*'],
runAt: 'document_end',
async main(ctx) {
initContentScript(await ExtensionStorage.enabled.getValue(), ctx);

ExtensionStorage.enabled.watch((enabled) => {
initContentScript(enabled, ctx);
});
}
ExtensionStorage.enabled.watch((enabled) => {
initContentScript(enabled, ctx);
});
},
});

function initContentScript(enabled: boolean | null, ctx: InstanceType<typeof ContentScriptContext>) {
if (!enabled) {
console.debug('[BetterBuff] Extension is disabled, not running.');
return;
}
console.debug('[BetterBuff] Initializing content script...');
if (!enabled) {
console.debug('[BetterBuff] Extension is disabled, not running.');
return;
}
console.debug('[BetterBuff] Initializing content script...');

activateHandler();
activateURLHandler();
addStorageListeners();
addMutationObserver();
activateHandler();
activateURLHandler();
addStorageListeners();
addMutationObserver();

setTimeout(async () => {
await applyStaticAdjustments();
setBuffCrx(ctx);
}, 50);
setTimeout(async () => {
await applyStaticAdjustments();
setBuffCrx(ctx);
}, 50);
}


function addStorageListeners() {
ExtensionStorage.darkMode.watch((value) => {
applyDarkMode(value ?? false);
});
ExtensionStorage.hideFloatBar.watch((value) => {
hideFloatBar(value ?? false);
});
ExtensionStorage.layoutFix.watch((value) => {
applyLayoutFix(value ?? false);
});
ExtensionStorage.darkMode.watch((value) => {
applyDarkMode(value ?? false);
});
ExtensionStorage.hideFloatBar.watch((value) => {
hideFloatBar(value ?? false);
});
ExtensionStorage.layoutFix.watch((value) => {
applyLayoutFix(value ?? false);
});
}

function addMutationObserver() {
const observer = new MutationObserver((mutations) => {
const url = new URL(location.href);
mutations.forEach((mutation) => {
for (let i = 0; i < mutation.addedNodes.length; i++) {
const node = mutation.addedNodes[i];
if (node instanceof HTMLElement && node.className === 'tooltip-hover' && url.pathname === '/market/csgo') {
adjustTooltip(node);
}
}
});
});
const observer = new MutationObserver((mutations) => {
const url = new URL(location.href);
mutations.forEach((mutation) => {
for (let i = 0; i < mutation.addedNodes.length; i++) {
const node = mutation.addedNodes[i];
if (node instanceof HTMLElement && node.className === 'tooltip-hover' && url.pathname === '/market/csgo') {
adjustTooltip(node);
}
}
});
});

observer.observe(document.body, { attributes: false, childList: true, subtree: false });
observer.observe(document.body, { attributes: false, childList: true, subtree: false });
}

async function applyStaticAdjustments() {
// apply dark mode
if (await ExtensionStorage.darkMode.getValue()) {
applyDarkMode(true);
}
// apply dark mode
if (await ExtensionStorage.darkMode.getValue()) {
applyDarkMode(true);
}

if (await ExtensionStorage.hideFloatBar.getValue()) {
hideFloatBar(true);
}
if (await ExtensionStorage.hideFloatBar.getValue()) {
hideFloatBar(true);
}

// apply layout fix
if (await ExtensionStorage.layoutFix.getValue()) {
applyLayoutFix(true);
}
// apply layout fix
if (await ExtensionStorage.layoutFix.getValue()) {
applyLayoutFix(true);
}
}

function applyDarkMode(darkMode: boolean) {
document.body.classList.toggle('bb-dark-mode', darkMode);
document.body.classList.toggle('bb-dark-mode', darkMode);
}

function hideFloatBar(hide: boolean) {
document.querySelector('.floatbar')?.setAttribute('style', hide ? 'display: none;' : '');
document.querySelector('.floatbar')?.setAttribute('style', hide ? 'display: none;' : '');
}

function applyLayoutFix(layoutFix: boolean) {
document.body.classList.toggle('bb-layout-fix', layoutFix);
document.body.classList.toggle('bb-layout-fix', layoutFix);
}
Loading

0 comments on commit 30f0ca1

Please sign in to comment.