-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gem] Support DevTools modify attribute
- Loading branch information
Showing
9 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import { devtools } from 'webextension-polyfill'; | ||
|
||
import { execution } from './common'; | ||
import { observeSelectedElement } from './scripts/observer'; | ||
|
||
devtools.panels.elements.createSidebarPane('Gem').then((sidebar) => { | ||
// sidebar.setPage('test.html'); | ||
sidebar.setPage('sidebarpanel.html'); | ||
}); | ||
|
||
devtools.panels.elements.onSelectionChanged.addListener(() => { | ||
execution(observeSelectedElement, []); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
declare let $0: any; | ||
|
||
export function observeSelectedElement() { | ||
const { __GEM_DEVTOOLS__STORE__ } = window; | ||
if (!__GEM_DEVTOOLS__STORE__ || !$0) return; | ||
|
||
const observer = (__GEM_DEVTOOLS__STORE__.domAttrMutation ||= new MutationObserver((mutationList) => { | ||
for (const mutation of mutationList) { | ||
if (mutation.type === 'attributes') { | ||
const ele = mutation.target as Element; | ||
const attr = ele.getAttribute(mutation.attributeName!); | ||
if (attr === null) { | ||
ele.removeAttribute(mutation.attributeName!); | ||
} else if (attr !== mutation.oldValue) { | ||
ele.setAttribute(mutation.attributeName!, attr); | ||
} | ||
} | ||
} | ||
})); | ||
observer.disconnect(); | ||
observer.observe($0, { attributeOldValue: true }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Debug | ||
|
||
GemElement is a standard custom element that can be inspected and debugged in the browser DevTools. You can also install the [Gem Devtools](https://chrome.google.com/webstore/detail/gem-devtools/lgfpciakeemopebkmjajengljoakjfle) extension, which allows you to more intuitively inspect and modify the data of Gem elements. | ||
GemElement is a standard custom element that can be inspected and debugged in the browser DevTools. You can also install the [Gem DevTools](https://chrome.google.com/webstore/detail/gem-devtools/lgfpciakeemopebkmjajengljoakjfle) extension, which allows you to more intuitively inspect and modify the data of Gem elements. | ||
|
||
## Use Gem Devtools | ||
## Use Gem DevTools | ||
|
||
![Gem Devtools](https://raw.githubusercontent.com/mantou132/gem/master/packages/gem-devtools/screenshot/firefox.jpg) | ||
![Gem DevTools](https://raw.githubusercontent.com/mantou132/gem/master/packages/gem-devtools/screenshot/firefox.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# 调试 | ||
|
||
GemElement 是标准的自定义元素,能在浏览器 DevTools 中检查和调试。也可以安装 [Gem Devtools](https://chrome.google.com/webstore/detail/gem-devtools/lgfpciakeemopebkmjajengljoakjfle) 扩展,它能让你更直观的检查和修改 Gem 元素的数据。 | ||
GemElement 是标准的自定义元素,能在浏览器 DevTools 中检查和调试。也可以安装 [Gem DevTools](https://chrome.google.com/webstore/detail/gem-devtools/lgfpciakeemopebkmjajengljoakjfle) 扩展,它能让你更直观的检查和修改 Gem 元素的数据。 | ||
|
||
## 使用 Gem Devtools | ||
## 使用 Gem DevTools | ||
|
||
![Gem Devtools](https://raw.githubusercontent.com/mantou132/gem/master/packages/gem-devtools/screenshot/firefox.jpg) | ||
![Gem DevTools](https://raw.githubusercontent.com/mantou132/gem/master/packages/gem-devtools/screenshot/firefox.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters