mirror of
https://github.com/GoogleChrome/chrome-extensions-samples.git
synced 2026-03-26 13:19:49 +07:00
Add prettier and eslint (#831)
* Ignores archived samples * Uses eslint/recommended rules * Runs prettier and eslint (including --fix) pre-commit via husky * Adds new npm scripts: 'lint', 'lint:fix' and 'prettier' * Does not lint inline js code * Fix all prettier and eslint errors * Add custom prettier rules * Apply custom prettier rules * Update readme to explain how to setup the repo * addressed comments
This commit is contained in:
@@ -11,10 +11,6 @@
|
||||
"action": {
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
"host_permissions": [
|
||||
"https://developer.chrome.com/*"
|
||||
],
|
||||
"permissions": [
|
||||
"tabGroups"
|
||||
]
|
||||
"host_permissions": ["https://developer.chrome.com/*"],
|
||||
"permissions": ["tabGroups"]
|
||||
}
|
||||
|
||||
@@ -14,26 +14,26 @@
|
||||
|
||||
const tabs = await chrome.tabs.query({
|
||||
url: [
|
||||
"https://developer.chrome.com/docs/webstore/*",
|
||||
"https://developer.chrome.com/docs/extensions/*",
|
||||
],
|
||||
'https://developer.chrome.com/docs/webstore/*',
|
||||
'https://developer.chrome.com/docs/extensions/*'
|
||||
]
|
||||
});
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator
|
||||
const collator = new Intl.Collator();
|
||||
tabs.sort((a, b) => collator.compare(a.title, b.title));
|
||||
|
||||
const template = document.getElementById("li_template");
|
||||
const template = document.getElementById('li_template');
|
||||
const elements = new Set();
|
||||
for (const tab of tabs) {
|
||||
const element = template.content.firstElementChild.cloneNode(true);
|
||||
|
||||
const title = tab.title.split("-")[0].trim();
|
||||
const pathname = new URL(tab.url).pathname.slice("/docs".length);
|
||||
const title = tab.title.split('-')[0].trim();
|
||||
const pathname = new URL(tab.url).pathname.slice('/docs'.length);
|
||||
|
||||
element.querySelector(".title").textContent = title;
|
||||
element.querySelector(".pathname").textContent = pathname;
|
||||
element.querySelector("a").addEventListener("click", async () => {
|
||||
element.querySelector('.title').textContent = title;
|
||||
element.querySelector('.pathname').textContent = pathname;
|
||||
element.querySelector('a').addEventListener('click', async () => {
|
||||
// need to focus window as well as the active tab
|
||||
await chrome.tabs.update(tab.id, { active: true });
|
||||
await chrome.windows.update(tab.windowId, { focused: true });
|
||||
@@ -41,11 +41,11 @@ for (const tab of tabs) {
|
||||
|
||||
elements.add(element);
|
||||
}
|
||||
document.querySelector("ul").append(...elements);
|
||||
document.querySelector('ul').append(...elements);
|
||||
|
||||
const button = document.querySelector("button");
|
||||
button.addEventListener("click", async () => {
|
||||
const button = document.querySelector('button');
|
||||
button.addEventListener('click', async () => {
|
||||
const tabIds = tabs.map(({ id }) => id);
|
||||
const group = await chrome.tabs.group({ tabIds });
|
||||
await chrome.tabGroups.update(group, { title: "DOCS" });
|
||||
await chrome.tabGroups.update(group, { title: 'DOCS' });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user