Skip to content

Instantly share code, notes, and snippets.

@kohki-shikata
Last active September 21, 2024 03:51
Show Gist options
  • Save kohki-shikata/8c11efbedd7393931c409ee8c0e18b3c to your computer and use it in GitHub Desktop.
Save kohki-shikata/8c11efbedd7393931c409ee8c0e18b3c to your computer and use it in GitHub Desktop.
content.ts
const title = document.querySelector('h1')
if(title) {
title.style.color = 'red'
}
// interface Request {
// fontSize: number;
// }
// // 例えば、requestを以下のように定義する
// const request: Request = {
// fontSize: 16, // 任意の値
// };
// src/content/contentScript.js
chrome.runtime.onMessage.addListener((request, _sender, _sendResponse) => {
if (request.action === "updateFontSize") {
const allElements = document.querySelectorAll('body *')
allElements.forEach((el) => {
(el as HTMLElement).style.cssText = `font-size: ${request.fontSize}% !important`;
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment