diff --git a/Archive.zip b/Archive.zip new file mode 100644 index 0000000..f40634e Binary files /dev/null and b/Archive.zip differ diff --git a/manifest.json b/manifest.json index 71ac637..2d4a67e 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Custom Elements Locator", "description": "This extension will find any custom element on a page.", - "version": "1.4.0", + "version": "1.3.0", "icons": { "16": "meta_assets/icon16.png", "48": "meta_assets/icon48.png", @@ -14,12 +14,9 @@ }, "content_scripts": [ { - "matches": [ - "https://*/*" - ], - "js": [ - "dist/content_script.js" - ] + "matches": ["https://*/*"], + "js": ["dist/content_script.js"], + "run_at": "document_end" } ], "background": { diff --git a/package.json b/package.json index 9184ab4..13e5981 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "custom-elements-locator", - "version": "1.4.0", + "version": "1.3.0", "description": "", "main": "content_script.js", "scripts": { diff --git a/src/background_script.js b/src/background_script.js index aa7d58c..e3f99cb 100644 --- a/src/background_script.js +++ b/src/background_script.js @@ -2,26 +2,27 @@ const metaAssets = '../meta_assets/'; var selectedId = -1; function getIconPath(response) { - const suffix = response.length ? '' : '_without'; + const suffix = response ? '' : '_without'; return `${metaAssets}icon${suffix}.png`; } function updateIcon() { - chrome.tabs.sendMessage(selectedId, {msg: "findAll"}, (response = []) => { + chrome.tabs.sendMessage(selectedId, {msg: "findAll"}, (response = false) => { chrome.browserAction.setIcon({ path: getIconPath(response), tabId: selectedId - }); + }, (e) => {console.log(e)}); }); } chrome.tabs.onUpdated.addListener(function(tabId, props) { - if (props.status == "complete" && tabId == selectedId) - updateIcon(); + if (props.status == "complete" && tabId == selectedId) { + updateIcon(); + } }); chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { - selectedId = tabId; + selectedId = tabId; updateIcon(); }); diff --git a/src/content_script.js b/src/content_script.js index a29bf67..7d82bd4 100644 --- a/src/content_script.js +++ b/src/content_script.js @@ -1,39 +1,54 @@ import { querySelectorAllDeep } from 'query-selector-shadow-dom'; -let allCustomElements = []; let lastElements = []; let lastElement = ''; let index = 0; -function isCustomElement(el) { - const isAttr = el.getAttribute('is'); - return el.localName.includes('-') || isAttr && isAttr.includes('-'); -} - -function findAllCustomElements(nodes) { - for (let i = 0, el; el = nodes[i]; ++i) { - if (isCustomElement(el) && el.localName !== 'style' && !allCustomElements.find(ce => ce === el.localName)) { - allCustomElements.push(el.localName); - } - - if (el.shadowRoot) { - findAllCustomElements(el.shadowRoot.querySelectorAll('*')); - } - } -} - chrome.runtime.onConnect.addListener(function(port) { port.onMessage.addListener(function(msg) { port.postMessage({counter: msg.counter+1}); }); }); +let allCustomElements = []; chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if(request.msg === "findAll") { - allCustomElements = []; - findAllCustomElements(document.querySelectorAll('*')); - sendResponse(allCustomElements) + const s = document.createElement('script'); + s.innerHTML = ` + requestIdleCallback(() => { + function isCustomElement(el) { + const isAttr = el.getAttribute('is'); + return customElements.get(el.localName) && el.localName.includes('-') || isAttr && isAttr.includes('-'); + } + + const allCustomElements = []; + + function findAllCustomElements(nodes) { + for (let i = 0, el; el = nodes[i]; ++i) { + if (isCustomElement(el) && el.localName !== 'style' && !allCustomElements.find(ce => ce === el.localName)) { + allCustomElements.push(el.localName); + } + + if (el.shadowRoot) { + findAllCustomElements(el.shadowRoot.querySelectorAll('*')); + } + } + } + + findAllCustomElements(document.querySelectorAll('*')); + document.dispatchEvent(new CustomEvent('__GET_CUSTOM_ELEMENTS', { + detail: allCustomElements + })); + }, {timeout: 1000});`; + document.head.append(s); + s.onload = () => s.remove(); + + document.addEventListener('__GET_CUSTOM_ELEMENTS', ({detail}) => { + allCustomElements = detail; + sendResponse(allCustomElements.length > 0); + }, {once: true}); + return true } if(request.msg === "init") { diff --git a/src/main.js b/src/main.js index b645a26..cc09592 100644 --- a/src/main.js +++ b/src/main.js @@ -11,6 +11,11 @@ firebase.initializeApp({ projectId: "locator-a6a89", }); +const denyList = [ + 'localhost', + '127.0.0.1', +] + const col = firebase.firestore().collection("sites"); class CustomElementsLocator extends LitElement { @@ -36,7 +41,7 @@ class CustomElementsLocator extends LitElement { firstUpdated() { chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { chrome.tabs.sendMessage(tabs[0].id, {msg: "init"}, ({customElements, host}) => { - if(!host.includes('localhost')) { + if(!denyList.includes(host)) { col.doc(host).get().then((doc) => { // doc exists, but doesnt use CE anymore -> delete @@ -78,7 +83,7 @@ class CustomElementsLocator extends LitElement { render() { return html`