Skip to content

Commit

Permalink
feat: add data-textlint-editor-embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Apr 18, 2021
1 parent a65599a commit 252b594
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/@textlint/website-generator/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
}
</style>
</head>
<body>
<body data-textlint-editor-embedded>
<div class="content">
<main class="main">
<label for="input">Input text for linting:</label>
Expand All @@ -247,7 +247,7 @@
<div id="metadata" class="metadata"></div>
</div>
<aside class="side">
<div id="js-status" class="status"></div>
<div id="js-status" class="status">Loading...</div>
</aside>
<script type="module">
import { run } from "https://cdn.skypack.dev/textchecker-element/public-dist/textchecker-element.es.js";
Expand Down
4 changes: 2 additions & 2 deletions packages/textchecker-element/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
}
</style>
</head>
<body>
<body data-textlint-editor-embedded>
<div class="content">
<main class="main">
<label for="input">Input text for linting:</label>
Expand All @@ -247,7 +247,7 @@
<div id="metadata" class="metadata"></div>
</div>
<aside class="side">
<div id="js-status" class="status"></div>
<div id="js-status" class="status">Loading...</div>
</aside>
<script type="module">
import { run } from "/public/index.ts";
Expand Down
7 changes: 7 additions & 0 deletions packages/webextension/app/scripts/pageScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ const lintEngine: LintEngineAPI = {
const isHTMLTextAreaElement = (element: Element): element is HTMLTextAreaElement => {
return element.tagName.toLowerCase() === "textarea";
};
const shouldSkipPage = () => {
return document.body.dataset.textlintEditorEmbedded !== undefined;
};

async function contentScriptMain() {
if (shouldSkipPage()) {
logger.log("Skip @textlint/editor because this page already has been embedded.");
return;
}
const set = new WeakSet<HTMLTextAreaElement>();
const callback = (textAreaElement: HTMLTextAreaElement) => {
if (set.has(textAreaElement)) {
Expand Down

0 comments on commit 252b594

Please sign in to comment.