From 484c119f663b9921c81320d382c5715466bf292f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 07:54:47 +0000 Subject: [PATCH 1/7] Initial plan From 70994f766cb047d9d1becf72ab53e3925ab9b40c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:02:59 +0000 Subject: [PATCH 2/7] Replace custom code in add-examples-to-dts.ts with ts-morph Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- add-examples-to-dts.ts | 179 ++++++++++++++++++++++------------------- package-lock.json | 75 +++++++++++++++++ package.json | 4 +- 3 files changed, 176 insertions(+), 82 deletions(-) diff --git a/add-examples-to-dts.ts b/add-examples-to-dts.ts index 4c03c060..a0332c7d 100644 --- a/add-examples-to-dts.ts +++ b/add-examples-to-dts.ts @@ -1,6 +1,7 @@ -/* eslint-disable n/prefer-global/process, unicorn/no-process-exit */ -import {readFileSync, writeFileSync} from 'node:fs'; +/* eslint-disable n/prefer-global/process, unicorn/no-process-exit, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */ +import {readFileSync} from 'node:fs'; import {execSync} from 'node:child_process'; +import {Project} from 'ts-morph'; // Import index.ts to populate the test data via side effect // eslint-disable-next-line import-x/no-unassigned-import import './index.ts'; @@ -17,16 +18,21 @@ if (dtsContent.includes(marker)) { process.exit(1); } -// Process each exported function -const lines = dtsContent.split('\n'); -const outputLines: string[] = []; +// Create a ts-morph project and load the file +const project = new Project(); +const sourceFile = project.createSourceFile('temp.d.ts', dtsContent, {overwrite: true}); + let examplesAdded = 0; -for (const line of lines) { - // Check if this is a function declaration - const match = /^export declare const (\w+):/.exec(line); - if (match) { - const functionName = match[1]; +// Process each exported variable declaration (these are the function declarations) +for (const statement of sourceFile.getVariableStatements()) { + // Only process exported statements + if (!statement.isExported()) { + continue; + } + + for (const declaration of statement.getDeclarations()) { + const functionName = declaration.getName(); // Get the tests/examples for this function const examples = getTests(functionName); @@ -37,104 +43,115 @@ for (const line of lines) { const urlExamples = examples.filter((url: string) => url.startsWith('http')); if (urlExamples.length > 0) { - // Check if there's an existing JSDoc block immediately before this line - let jsDocumentEndIndex = -1; - let jsDocumentStartIndex = -1; - let isSingleLineJsDocument = false; - - // Look backwards from outputLines to find JSDoc - for (let index = outputLines.length - 1; index >= 0; index--) { - const previousLine = outputLines[index]; - const trimmed = previousLine.trim(); - - if (trimmed === '') { - continue; // Skip empty lines + // Get or create JSDoc for this statement (not the declaration) + const jsDoc = statement.getJsDocs()[0]; + + if (jsDoc) { + // Add @example tags to existing JSDoc + const existingTags = jsDoc.getTags(); + const description = jsDoc.getDescription().trim(); + + // Build new JSDoc content + const newJsDocLines: string[] = []; + if (description) { + newJsDocLines.push(description); } - // Check for single-line JSDoc: /** ... */ - if (trimmed.startsWith('/**') && trimmed.endsWith('*/') && trimmed.length > 5) { - jsDocumentStartIndex = index; - jsDocumentEndIndex = index; - isSingleLineJsDocument = true; - break; + // Add existing tags (that aren't @example tags) + for (const tag of existingTags) { + if (tag.getTagName() !== 'example') { + newJsDocLines.push(tag.getText()); + } } - // Check for multi-line JSDoc ending - if (trimmed === '*/') { - jsDocumentEndIndex = index; - // Now find the start of this JSDoc - for (let k = index - 1; k >= 0; k--) { - if (outputLines[k].trim().startsWith('/**')) { - jsDocumentStartIndex = k; - break; - } - } + // Add new @example tags + for (const url of urlExamples) { + newJsDocLines.push(`@example ${url}`); + } - break; + // Replace the JSDoc + jsDoc.remove(); + statement.addJsDoc(newJsDocLines.join('\n')); + } else { + // Create new JSDoc with examples + const jsDocLines: string[] = []; + for (const url of urlExamples) { + jsDocLines.push(`@example ${url}`); } - // If we hit a non-JSDoc line, there's no JSDoc block - break; + statement.addJsDoc(jsDocLines.join('\n')); } - if (jsDocumentStartIndex >= 0 && jsDocumentEndIndex >= 0) { - // Extend existing JSDoc block - if (isSingleLineJsDocument) { - // Convert single-line to multi-line and add examples - const singleLineContent = outputLines[jsDocumentStartIndex]; - // Extract the comment text without /** and */ - const commentText = singleLineContent.trim().slice(3, -2).trim(); - - // Replace the single line with multi-line format - outputLines[jsDocumentStartIndex] = '/**'; - if (commentText) { - outputLines.splice(jsDocumentStartIndex + 1, 0, ` * ${commentText}`); - } + examplesAdded += urlExamples.length; + } + } + } +} - // Add examples after the existing content - const insertIndex = jsDocumentStartIndex + (commentText ? 2 : 1); - for (const url of urlExamples) { - outputLines.splice(insertIndex + urlExamples.indexOf(url), 0, ` * @example ${url}`); - } +// Also process exported type aliases (like RepoExplorerInfo) +for (const typeAlias of sourceFile.getTypeAliases()) { + if (!typeAlias.isExported()) { + continue; + } - outputLines.splice(insertIndex + urlExamples.length, 0, ' */'); - examplesAdded += urlExamples.length; - } else { - // Insert @example lines before the closing */ - for (const url of urlExamples) { - outputLines.splice(jsDocumentEndIndex, 0, ` * @example ${url}`); - } + const typeName = typeAlias.getName(); - examplesAdded += urlExamples.length; - } - } else { - // Add new JSDoc comment with examples before the declaration - outputLines.push('/**'); - for (const url of urlExamples) { - outputLines.push(` * @example ${url}`); + // Get the tests/examples for this type (unlikely but keeping consistency) + const examples = getTests(typeName); + + if (examples && examples.length > 0 && examples[0] !== 'combinedTestOnly') { + const urlExamples = examples.filter((url: string) => url.startsWith('http')); + + if (urlExamples.length > 0) { + const jsDoc = typeAlias.getJsDocs()[0]; + + if (jsDoc) { + const existingTags = jsDoc.getTags(); + const description = jsDoc.getDescription().trim(); + + const newJsDocLines: string[] = []; + if (description) { + newJsDocLines.push(description); + } + + for (const tag of existingTags) { + if (tag.getTagName() !== 'example') { + newJsDocLines.push(tag.getText()); } + } + + for (const url of urlExamples) { + newJsDocLines.push(`@example ${url}`); + } - outputLines.push(' */'); - examplesAdded += urlExamples.length; + jsDoc.remove(); + typeAlias.addJsDoc(newJsDocLines.join('\n')); + } else { + const jsDocLines: string[] = []; + for (const url of urlExamples) { + jsDocLines.push(`@example ${url}`); } + + typeAlias.addJsDoc(jsDocLines.join('\n')); } + + examplesAdded += urlExamples.length; } } - - outputLines.push(line); } -// Add marker at the beginning -const finalContent = `${marker}\n${outputLines.join('\n')}`; - // Validate that we added some examples if (examplesAdded === 0) { console.error('❌ Error: No examples were added. This likely indicates a problem with the script.'); process.exit(1); } +// Get the modified content and add marker +const modifiedContent = sourceFile.getFullText(); +const finalContent = `${marker}\n${modifiedContent}`; + // Write the modified content back -writeFileSync(dtsPath, finalContent, 'utf8'); +sourceFile.getProject().createSourceFile(dtsPath, finalContent, {overwrite: true}).saveSync(); console.log(`✓ Added ${examplesAdded} example URLs to index.d.ts`); diff --git a/package-lock.json b/package-lock.json index 2ab4f431..5479c857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,8 @@ "strip-indent": "^4.1.1", "svelte": "^5.46.1", "svelte-check": "^4.3.5", + "ts-morph": "^27.0.2", + "tsx": "^4.21.0", "typescript": "5.9.3", "vite": "^7.3.1", "vitest": "^4.0.17", @@ -1385,6 +1387,34 @@ "vite": "^6.3.0 || ^7.0.0" } }, + "node_modules/@ts-morph/common": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.28.1.tgz", + "integrity": "sha512-W74iWf7ILp1ZKNYXY5qbddNaml7e9Sedv5lvU1V8lftlitkc9Pq1A+jlH23ltDgWYeZFFEqGCD1Ies9hqu3O+g==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimatch": "^10.0.1", + "path-browserify": "^1.0.1", + "tinyglobby": "^0.2.14" + } + }, + "node_modules/@ts-morph/common/node_modules/minimatch": { + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.1.1.tgz", + "integrity": "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/brace-expansion": "^5.0.0" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/@tybys/wasm-util": { "version": "0.10.1", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz", @@ -2665,6 +2695,13 @@ "node": ">=6" } }, + "node_modules/code-block-writer": { + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-13.0.3.tgz", + "integrity": "sha512-Oofo0pq3IKnsFtuHqSF7TqBfr71aeyZDVJ0HpmqB7FBM2qEigL0iPONSCZSO9pE9dZTAxANe5XHG9Uy0YMv8cg==", + "dev": true, + "license": "MIT" + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -6644,6 +6681,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true, + "license": "MIT" + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -8014,6 +8058,17 @@ "typescript": ">=4.0.0" } }, + "node_modules/ts-morph": { + "version": "27.0.2", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-27.0.2.tgz", + "integrity": "sha512-fhUhgeljcrdZ+9DZND1De1029PrE+cMkIP7ooqkLRTrRLTqcki2AstsyJm0vRNbTbVCNJ0idGlbBrfqc7/nA8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@ts-morph/common": "~0.28.1", + "code-block-writer": "^13.0.3" + } + }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -8022,6 +8077,26 @@ "license": "0BSD", "optional": true }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 65067444..17696cb2 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build": "run-p build:*", "build:esbuild": "esbuild index.ts --bundle --external:github-reserved-names --outdir=distribution --format=esm --drop-labels=TEST", "build:typescript": "tsc", - "postbuild:typescript": "node add-examples-to-dts.ts", + "postbuild:typescript": "tsx add-examples-to-dts.ts", "build:demo": "vite build demo", "try": "esbuild index.ts --bundle --global-name=x --format=iife | pbcopy && echo 'Copied to clipboard'", "fix": "xo --fix", @@ -54,6 +54,8 @@ "strip-indent": "^4.1.1", "svelte": "^5.46.1", "svelte-check": "^4.3.5", + "ts-morph": "^27.0.2", + "tsx": "^4.21.0", "typescript": "5.9.3", "vite": "^7.3.1", "vitest": "^4.0.17", From 60950f1d0351dec7b665718d959a397098029857 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:05:14 +0000 Subject: [PATCH 3/7] Refactor: Extract duplicated JSDoc manipulation logic into helper function Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- add-examples-to-dts.ts | 118 ++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 72 deletions(-) diff --git a/add-examples-to-dts.ts b/add-examples-to-dts.ts index a0332c7d..c4a00691 100644 --- a/add-examples-to-dts.ts +++ b/add-examples-to-dts.ts @@ -1,7 +1,7 @@ /* eslint-disable n/prefer-global/process, unicorn/no-process-exit, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */ import {readFileSync} from 'node:fs'; import {execSync} from 'node:child_process'; -import {Project} from 'ts-morph'; +import {Project, type JSDocableNode} from 'ts-morph'; // Import index.ts to populate the test data via side effect // eslint-disable-next-line import-x/no-unassigned-import import './index.ts'; @@ -24,6 +24,49 @@ const sourceFile = project.createSourceFile('temp.d.ts', dtsContent, {overwrite: let examplesAdded = 0; +/** + * Add example URLs to a JSDocable node (e.g., variable statement or type alias) + */ +function addExamplesToNode(node: JSDocableNode, urlExamples: string[]): void { + const jsDoc = node.getJsDocs()[0]; + + if (jsDoc) { + // Add @example tags to existing JSDoc + const existingTags = jsDoc.getTags(); + const description = jsDoc.getDescription().trim(); + + // Build new JSDoc content + const newJsDocLines: string[] = []; + if (description) { + newJsDocLines.push(description); + } + + // Add existing tags (that aren't @example tags) + for (const tag of existingTags) { + if (tag.getTagName() !== 'example') { + newJsDocLines.push(tag.getText()); + } + } + + // Add new @example tags + for (const url of urlExamples) { + newJsDocLines.push(`@example ${url}`); + } + + // Replace the JSDoc + jsDoc.remove(); + node.addJsDoc(newJsDocLines.join('\n')); + } else { + // Create new JSDoc with examples + const jsDocLines: string[] = []; + for (const url of urlExamples) { + jsDocLines.push(`@example ${url}`); + } + + node.addJsDoc(jsDocLines.join('\n')); + } +} + // Process each exported variable declaration (these are the function declarations) for (const statement of sourceFile.getVariableStatements()) { // Only process exported statements @@ -43,45 +86,7 @@ for (const statement of sourceFile.getVariableStatements()) { const urlExamples = examples.filter((url: string) => url.startsWith('http')); if (urlExamples.length > 0) { - // Get or create JSDoc for this statement (not the declaration) - const jsDoc = statement.getJsDocs()[0]; - - if (jsDoc) { - // Add @example tags to existing JSDoc - const existingTags = jsDoc.getTags(); - const description = jsDoc.getDescription().trim(); - - // Build new JSDoc content - const newJsDocLines: string[] = []; - if (description) { - newJsDocLines.push(description); - } - - // Add existing tags (that aren't @example tags) - for (const tag of existingTags) { - if (tag.getTagName() !== 'example') { - newJsDocLines.push(tag.getText()); - } - } - - // Add new @example tags - for (const url of urlExamples) { - newJsDocLines.push(`@example ${url}`); - } - - // Replace the JSDoc - jsDoc.remove(); - statement.addJsDoc(newJsDocLines.join('\n')); - } else { - // Create new JSDoc with examples - const jsDocLines: string[] = []; - for (const url of urlExamples) { - jsDocLines.push(`@example ${url}`); - } - - statement.addJsDoc(jsDocLines.join('\n')); - } - + addExamplesToNode(statement, urlExamples); examplesAdded += urlExamples.length; } } @@ -103,38 +108,7 @@ for (const typeAlias of sourceFile.getTypeAliases()) { const urlExamples = examples.filter((url: string) => url.startsWith('http')); if (urlExamples.length > 0) { - const jsDoc = typeAlias.getJsDocs()[0]; - - if (jsDoc) { - const existingTags = jsDoc.getTags(); - const description = jsDoc.getDescription().trim(); - - const newJsDocLines: string[] = []; - if (description) { - newJsDocLines.push(description); - } - - for (const tag of existingTags) { - if (tag.getTagName() !== 'example') { - newJsDocLines.push(tag.getText()); - } - } - - for (const url of urlExamples) { - newJsDocLines.push(`@example ${url}`); - } - - jsDoc.remove(); - typeAlias.addJsDoc(newJsDocLines.join('\n')); - } else { - const jsDocLines: string[] = []; - for (const url of urlExamples) { - jsDocLines.push(`@example ${url}`); - } - - typeAlias.addJsDoc(jsDocLines.join('\n')); - } - + addExamplesToNode(typeAlias, urlExamples); examplesAdded += urlExamples.length; } } From ae26811a3846f2f9e33e795eae6906a4cb97e672 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:07:32 +0000 Subject: [PATCH 4/7] Simplify file writing and use actual file path in ts-morph Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- add-examples-to-dts.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/add-examples-to-dts.ts b/add-examples-to-dts.ts index c4a00691..713f83b9 100644 --- a/add-examples-to-dts.ts +++ b/add-examples-to-dts.ts @@ -1,5 +1,5 @@ /* eslint-disable n/prefer-global/process, unicorn/no-process-exit, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument */ -import {readFileSync} from 'node:fs'; +import {readFileSync, writeFileSync} from 'node:fs'; import {execSync} from 'node:child_process'; import {Project, type JSDocableNode} from 'ts-morph'; // Import index.ts to populate the test data via side effect @@ -20,7 +20,7 @@ if (dtsContent.includes(marker)) { // Create a ts-morph project and load the file const project = new Project(); -const sourceFile = project.createSourceFile('temp.d.ts', dtsContent, {overwrite: true}); +const sourceFile = project.createSourceFile(dtsPath, dtsContent, {overwrite: true}); let examplesAdded = 0; @@ -125,7 +125,7 @@ const modifiedContent = sourceFile.getFullText(); const finalContent = `${marker}\n${modifiedContent}`; // Write the modified content back -sourceFile.getProject().createSourceFile(dtsPath, finalContent, {overwrite: true}).saveSync(); +writeFileSync(dtsPath, finalContent, 'utf8'); console.log(`✓ Added ${examplesAdded} example URLs to index.d.ts`); From de02be9624f9ea86e4bae2275126e237922ce4f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:09:26 +0000 Subject: [PATCH 5/7] Use safer array access method with .at(0) Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- add-examples-to-dts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-examples-to-dts.ts b/add-examples-to-dts.ts index 713f83b9..42c98fe7 100644 --- a/add-examples-to-dts.ts +++ b/add-examples-to-dts.ts @@ -28,7 +28,7 @@ let examplesAdded = 0; * Add example URLs to a JSDocable node (e.g., variable statement or type alias) */ function addExamplesToNode(node: JSDocableNode, urlExamples: string[]): void { - const jsDoc = node.getJsDocs()[0]; + const jsDoc = node.getJsDocs().at(0); if (jsDoc) { // Add @example tags to existing JSDoc From 62d0611e0f69c8a8dc3fb2b89d198b96263ff616 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:34:02 +0000 Subject: [PATCH 6/7] Remove distribution from gitignore and commit distribution files Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- .gitignore | 1 - distribution/collector.d.ts | 5 + distribution/index.d.ts | 585 +++++++++++++++++++++++++++++++++++ distribution/index.js | 352 +++++++++++++++++++++ distribution/index.test.d.ts | 1 + 5 files changed, 943 insertions(+), 1 deletion(-) create mode 100644 distribution/collector.d.ts create mode 100644 distribution/index.d.ts create mode 100644 distribution/index.js create mode 100644 distribution/index.test.d.ts diff --git a/.gitignore b/.gitignore index 46cb338c..03721dd4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ Thumbs.db *.log logs *.map -distribution dist .cache .parcel-cache diff --git a/distribution/collector.d.ts b/distribution/collector.d.ts new file mode 100644 index 00000000..86aafcc7 --- /dev/null +++ b/distribution/collector.d.ts @@ -0,0 +1,5 @@ +/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */ +export declare const testableUrls: Map; +export declare function addTests(test: string, urls: string[]): void; +export declare function getTests(detectName: string): string[]; +export declare function getAllUrls(): Set; diff --git a/distribution/index.d.ts b/distribution/index.d.ts new file mode 100644 index 00000000..a07bdce2 --- /dev/null +++ b/distribution/index.d.ts @@ -0,0 +1,585 @@ +/* Examples added by add-examples-to-dts.ts */ +export declare const is404: () => boolean; +export declare const is500: () => boolean; +export declare const isPasswordConfirmation: () => boolean; +export declare const isLoggedIn: () => boolean; +/** @example https://github.com/sindresorhus/refined-github/blame/master/package.json */ +export declare const isBlame: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f + * @example https://github.com/sindresorhus/refined-github/commit/5b614 + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 + */ +export declare const isCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/commits/master?page=2 + * @example https://github.com/sindresorhus/refined-github/commits/test-branch + * @example https://github.com/sindresorhus/refined-github/commits/0.13.0 + * @example https://github.com/sindresorhus/refined-github/commits/230c2 + * @example https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63 + * @example https://github.com/sindresorhus/refined-github/commits?author=fregante + * @example https://github.com/sindresorhus/runs/commits/ + */ +export declare const isRepoCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/compare + * @example https://github.com/sindresorhus/refined-github/compare/ + * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name + * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1 + * @example https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1 + * @example https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1 + */ +export declare const isCompare: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/brookhong/Surfingkeys/wiki/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d + * @example https://github.com/brookhong/Surfingkeys/wiki/Color-Themes/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d + */ +export declare const isCompareWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/// + * @example https://github.com// + * @example https://github.com/ + * @example https://github.com + * @example https://github.com/orgs/test/dashboard + * @example https://github.com/dashboard/index/2 + * @example https://github.com//dashboard + * @example https://github.com/dashboard + * @example https://github.com/orgs/edit/dashboard + * @example https://github.big-corp.com/ + * @example https://not-github.com/ + * @example https://my-little-hub.com/ + * @example https://github.com/?tab=repositories + * @example https://github.com/?tab=stars + * @example https://github.com/?tab=followers + * @example https://github.com/?tab=following + * @example https://github.com/?tab=overview + * @example https://github.com?search=1 + * @example https://github.com/dashboard-feed + */ +export declare const isDashboard: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.big-corp.com/ + * @example https://not-github.com/ + * @example https://my-little-hub.com/ + * @example https://my-little-hub.com/gist + * @example https://my-little-hub.com/gist/in-fragrante + * @example https://gist.my-little-hub.com/in-fragrante + */ +export declare const isEnterprise: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://gist.github.com + * @example http://gist.github.com + * @example https://gist.github.com/new + * @example https://gist.github.com/fregante/2205329b71218fa2c1d3 + * @example https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad + * @example https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064 + * @example https://my-little-hub.com/gist + * @example https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions + * @example https://gist.github.com/fregante + * @example https://gist.github.com/github + * @example https://gist.github.com/babel + * @example https://my-little-hub.com/gist/in-fragrante + * @example https://gist.my-little-hub.com/in-fragrante + */ +export declare const isGist: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/issues + * @example https://github.com/issues?q=is%3Apr+is%3Aopen + * @example https://github.com/issues/assigned + * @example https://github.com/issues/mentioned + * @example https://github.com/pulls + * @example https://github.com/pulls?q=issues + * @example https://github.com/pulls/assigned + * @example https://github.com/pulls/mentioned + * @example https://github.com/pulls/review-requested + */ +export declare const isGlobalIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/search?q=refined-github&ref=opensearch */ +export declare const isGlobalSearchResults: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/issues/146 */ +export declare const isIssue: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isConversation: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/labels + * @example https://github.com/sindresorhus/refined-github/labels/ + */ +export declare const isLabelList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/kubernetes/kubernetes/milestone/56 */ +export declare const isMilestone: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/milestones */ +export declare const isMilestoneList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/new/main */ +export declare const isNewFile: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/issues/new */ +export declare const isNewIssue: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/releases/new */ +export declare const isNewRelease: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/tooomm/wikitest/wiki/_new */ +export declare const isNewWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/notifications */ +export declare const isNotifications: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isOrganizationProfile: () => boolean; +export declare const isOrganizationRepo: () => boolean; +/** + * @example https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1 + * @example https://github.com/orgs/refined-github/teams/core-team/discussions/1 + * @example https://github.com/orgs/refined-github/teams/core-team + */ +export declare const isTeamDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isOwnUserProfile: () => boolean; +export declare const isOwnOrganizationProfile: () => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/projects/3 + * @example https://github.com/orgs/RSSNext/projects/3 + */ +export declare const isProject: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/projects */ +export declare const isProjects: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/tophf/mpiv/discussions/50 + * @example https://github.com/orgs/community/discussions/11202 + */ +export declare const isDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/withastro/roadmap/discussions/new?category=proposal + * @example https://github.com/orgs/community/discussions/new?category=pull-requests + */ +export declare const isNewDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/tophf/mpiv/discussions + * @example https://github.com/orgs/community/discussions + */ +export declare const isDiscussionList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/files + * @example https://github.com/sindresorhus/refined-github/pull/148/files/e1aba6f + * @example https://github.com/sindresorhus/refined-github/pull/148/files/1e27d799..e1aba6f + * @example https://github.com/refined-github/refined-github/pull/148/changes + * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d799..e1aba6f + * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641..e1aba6febb3fe38aafd1137cff28b536eeeabe7e + * @example https://github.com/sindresorhus/refined-github/pull/148/commits + * @example https://github.com/sindresorhus/refined-github/pull/148 + */ +export declare const isPR: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/pull/148/conflicts */ +export declare const isPRConflicts: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * Any `isIssueOrPRList` can display both issues and PRs, prefer that detection. `isPRList` only exists because this page has PR-specific filters like the "Reviews" dropdown + * @example https://github.com/pulls + * @example https://github.com/pulls?q=issues + * @example https://github.com/sindresorhus/refined-github/pulls + * @example https://github.com/sindresorhus/refined-github/pulls/ + * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr + * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed + */ +export declare const isPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 + */ +export declare const isPRCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isPRCommit404: () => boolean; +export declare const isPRFile404: () => boolean; +/** @example https://github.com/sindresorhus/refined-github/pull/148 */ +export declare const isPRConversation: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/pull/148/commits */ +export declare const isPRCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 + * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 + * @example https://github.com/sindresorhus/refined-github/pull/148/files + * @example https://github.com/sindresorhus/refined-github/pull/148/files/e1aba6f + * @example https://github.com/sindresorhus/refined-github/pull/148/files/1e27d799..e1aba6f + * @example https://github.com/refined-github/refined-github/pull/148/changes + * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d799..e1aba6f + * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641..e1aba6febb3fe38aafd1137cff28b536eeeabe7e + */ +export declare const isPRFiles: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1 + * @example https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1 + * @example https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1 + */ +export declare const isQuickPR: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isMergedPR: () => boolean; +export declare const isDraftPR: () => boolean; +export declare const isOpenConversation: () => boolean; +export declare const isClosedConversation: () => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/releases + * @example https://github.com/sindresorhus/refined-github/releases?page=2 + */ +export declare const isReleases: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/tags + * @example https://github.com/sindresorhus/refined-github/tags?after=21.8.1 + */ +export declare const isTags: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/refined-github/refined-github/releases/tag/1.20.1 + * @example https://github.com/refined-github/refined-github/releases/tag/23.7.25 + */ +export declare const isSingleReleaseOrTag: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/releases + * @example https://github.com/sindresorhus/refined-github/releases?page=2 + * @example https://github.com/sindresorhus/refined-github/tags + * @example https://github.com/sindresorhus/refined-github/tags?after=21.8.1 + */ +export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/delete/master/readme.md + * @example https://github.com/sindresorhus/refined-github/delete/ghe-injection/source/background.ts + */ +export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/edit/master/readme.md + * @example https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts + */ +export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasFileEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/releases/edit/v1.2.3 */ +export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasReleaseEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/tooomm/wikitest/wiki/Getting-Started/_edit */ +export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasWikiPageEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/blame/master/package.json + * @example https://github.com/sindresorhus/refined-github/issues/146 + * @example https://github.com/sindresorhus/notifications/ + * @example https://github.com/sindresorhus/refined-github/pull/148 + * @example https://github.com/sindresorhus/refined-github/milestones/new + * @example https://github.com/sindresorhus/refined-github/milestones/1/edit + * @example https://github.com/sindresorhus/refined-github/issues/new/choose + * @example https://github.com/sindresorhus/refined-github/issues/templates/edit + */ +export declare const isRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasRepoHeader: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isEmptyRepoRoot: () => boolean; +export declare const isEmptyRepo: () => boolean; +export declare const isPublicRepo: () => boolean; +export declare const isArchivedRepo: () => boolean; +export declare const isBlank: () => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/labels/bug + * @example https://github.com/sindresorhus/refined-github/labels/implemented%20by%20github + * @example https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt + * @example https://github.com/sindresorhus/refined-github/milestones/1 + */ +export declare const isRepoTaxonomyIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isRepoIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/pulls + * @example https://github.com/sindresorhus/refined-github/pulls/ + * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr + * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed + */ +export declare const isRepoPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example http://github.com/sindresorhus/ava/issues + * @example https://github.com/sindresorhus/refined-github/issues + * @example https://github.com/sindresorhus/refined-github/issues/fregante + * @example https://github.com/sindresorhus/refined-github/issues/newton + * @example https://github.com/sindresorhus/refined-github/issues/wptemplates + * @example https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc + * @example https://github.com/sindresorhus/refined-github/labels/bug + * @example https://github.com/sindresorhus/refined-github/labels/implemented%20by%20github + * @example https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt + */ +export declare const isRepoIssueList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github + * @example https://github.com/sindresorhus/refined-github/ + * @example https://github.com/sindresorhus/notifications/ + * @example https://github.com/sindresorhus/edit + * @example https://github.com/sindresorhus///edit + * @example https://github.com/sindresorhus/search + * @example https://github.com/sindresorhus/branches + * @example https://github.com/sindresorhus/refined-github?files=1 + */ +export declare const isRepoHome: (url?: URL | HTMLAnchorElement | Location) => boolean; +export type RepoExplorerInfo = { + nameWithOwner: string; + branch: string; + filePath: string; +}; +/** + * @example https://github.com/sindresorhus/refined-github + * @example https://github.com/sindresorhus/refined-github/ + * @example https://github.com/sindresorhus/notifications/ + * @example https://github.com/sindresorhus/edit + * @example https://github.com/sindresorhus///edit + * @example https://github.com/sindresorhus/search + * @example https://github.com/sindresorhus/branches + * @example https://github.com/sindresorhus/refined-github?files=1 + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ + * @example https://github.com/sindresorhus/refined-github/tree/57bf4 + * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 + */ +export declare const isRepoRoot: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/search?q=diff + * @example https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues + * @example https://github.com/sindresorhus/refined-github/search + */ +export declare const isRepoSearch: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/settings + * @example https://github.com/sindresorhus/refined-github/settings/branches + */ +export declare const isRepoSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/settings */ +export declare const isRepoMainSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/settings/replies + * @example https://github.com/settings/replies/88491/edit + */ +export declare const isRepliesSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/settings/profile + * @example https://github.com/settings/replies + * @example https://github.com/settings/replies/88491/edit + */ +export declare const isUserSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github + * @example https://github.com/sindresorhus/refined-github/ + * @example https://github.com/sindresorhus/notifications/ + * @example https://github.com/sindresorhus/edit + * @example https://github.com/sindresorhus///edit + * @example https://github.com/sindresorhus/search + * @example https://github.com/sindresorhus/branches + * @example https://github.com/sindresorhus/refined-github?files=1 + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ + * @example https://github.com/sindresorhus/refined-github/tree/57bf4 + * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 + * @example https://github.com/sindresorhus/refined-github/tree/main/source + * @example https://github.com/sindresorhus/refined-github/tree/0.13.0/extension + * @example https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension + * @example https://github.com/sindresorhus/refined-github?search=1 + */ +export declare const isRepoTree: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/lukesampson/scoop/wiki + * @example https://github.com/tooomm/wikitest/wiki/_new + * @example https://github.com/tooomm/wikitest/wiki/Getting-Started/_edit + * @example https://github.com/brookhong/Surfingkeys/wiki/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d + * @example https://github.com/brookhong/Surfingkeys/wiki/Color-Themes/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d + */ +export declare const isRepoWiki: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f + * @example https://github.com/sindresorhus/refined-github/commit/5b614 + */ +export declare const isSingleCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/blob/master/.gitattributes + * @example https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css + * @example https://github.com/sindresorhus/refined-github/blob/master/edit.txt + */ +export declare const isSingleFile: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/find/master */ +export declare const isFileFinder: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea + * @example https://github.com/refined-github/refined-github/blob/some-non-existent-ref/source/features/bugs-tab.tsx + */ +export declare const isRepoFile404: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/network/members */ +export declare const isRepoForksList: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/network */ +export declare const isRepoNetworkGraph: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isForkedRepo: () => boolean; +/** @example https://github.com/refined-github/refined-github/fork */ +export declare const isForkingRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://gist.github.com/fregante/2205329b71218fa2c1d3 + * @example https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad + * @example https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064 + */ +export declare const isSingleGist: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions */ +export declare const isGistRevision: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/trending + * @example https://github.com/trending/developers + * @example https://github.com/trending/unknown + */ +export declare const isTrending: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/branches */ +export declare const isBranches: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante + * @example https://github.com/github + * @example https://github.com/babel + * @example https://github.com/fregante?tab=repositories + * @example https://github.com/fregante?tab=repositories&type=source + * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= + * @example https://github.com/fregante?tab=stars + * @example https://github.com/fregante?direction=desc&sort=updated&tab=stars + * @example https://github.com/fregante?tab=followers + * @example https://github.com/sindresorhus?tab=followers + * @example https://github.com/fregante?tab=following + * @example https://github.com/sindresorhus?tab=following + */ +export declare const isProfile: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://gist.github.com/fregante + * @example https://gist.github.com/github + * @example https://gist.github.com/babel + * @example https://my-little-hub.com/gist/in-fragrante + * @example https://gist.my-little-hub.com/in-fragrante + */ +export declare const isGistProfile: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isUserProfile: () => boolean; +export declare const isPrivateUserProfile: () => boolean; +export declare const isUserProfileMainTab: () => boolean; +/** + * @example https://github.com/fregante?tab=repositories + * @example https://github.com/fregante?tab=repositories&type=source + * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= + */ +export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante?tab=stars + * @example https://github.com/fregante?direction=desc&sort=updated&tab=stars + */ +export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante?tab=followers + * @example https://github.com/sindresorhus?tab=followers + */ +export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante?tab=following + * @example https://github.com/sindresorhus?tab=following + */ +export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/fregante?tab=repositories + * @example https://github.com/fregante?tab=repositories&type=source + * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= + * @example https://github.com/orgs/refined-github/repositories + * @example https://github.com/orgs/refined-github/repositories?q=&type=private&language=&sort= + */ +export declare const isProfileRepoList: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** Static code, not the code editor */ +export declare const hasCode: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * Covers blob, trees and blame pages + * @example https://github.com/sindresorhus/refined-github + * @example https://github.com/sindresorhus/refined-github/ + * @example https://github.com/sindresorhus/notifications/ + * @example https://github.com/sindresorhus/edit + * @example https://github.com/sindresorhus///edit + * @example https://github.com/sindresorhus/search + * @example https://github.com/sindresorhus/branches + * @example https://github.com/sindresorhus/refined-github?files=1 + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons + * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 + * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ + * @example https://github.com/sindresorhus/refined-github/tree/57bf4 + * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 + * @example https://github.com/sindresorhus/refined-github/tree/main/source + * @example https://github.com/sindresorhus/refined-github/tree/0.13.0/extension + * @example https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension + * @example https://github.com/sindresorhus/refined-github?search=1 + * @example https://github.com/sindresorhus/refined-github/blob/master/.gitattributes + * @example https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css + * @example https://github.com/sindresorhus/refined-github/blob/master/edit.txt + * @example https://github.com/sindresorhus/refined-github/blame/master/package.json + */ +export declare const isRepoGitObject: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** Has a list of files */ +export declare const hasFiles: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/marketplace/actions/urlchecker-action + * @example https://github.com/marketplace/actions/github-action-for-assignee-to-reviewer + * @example https://github.com/marketplace/actions/hugo-actions + */ +export declare const isMarketplaceAction: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/runs/639481849 + * @example https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true + */ +export declare const isActionJobRun: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/sindresorhus/refined-github/runs/639481849 + * @example https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true + * @example https://github.com/refined-github/github-url-detection/actions/runs/294962314 + */ +export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/sindresorhus/refined-github/actions/new */ +export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** + * @example https://github.com/refined-github/github-url-detection/actions + * @example https://github.com/refined-github/github-url-detection/actions/workflows/demo.yml + * @example https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml + */ +export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean; +export declare const isUserTheOrganizationOwner: () => boolean; +export declare const canUserAdminRepo: () => boolean; +/** @deprecated Use `canUserAdminRepo` */ +export declare const canUserEditRepo: () => boolean; +/** + * @example https://github.com/new + * @example https://github.com/organizations/npmhub/repositories/new + */ +export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; +/** @example https://github.com/fregante/browser-extension-template/generate */ +export declare const isNewRepoTemplate: (url?: URL | HTMLAnchorElement | Location) => boolean; +export type NameWithOwner = `${string}/${string}`; +export type RepositoryInfo = { + /** The repo owner/user */ + owner: string; + /** The repo name */ + name: string; + /** The 'user/repo' part from an URL */ + nameWithOwner: NameWithOwner; + /** A repo's subpage + @example '/user/repo/issues/' -> 'issues' + @example '/user/repo/' -> '' + @example '/settings/token/' -> undefined */ + path: string; + /** The `path` segments + @example '/user/repo/' -> [] + @example '/user/repo/issues/' -> ['issues'] + @example '/user/repo/issues/new' -> ['issues', 'new'] */ + pathParts: string[]; +}; +export declare const utils: { + getOrg: (url?: URL | HTMLAnchorElement | Location) => { + name: string; + path: string; + } | undefined; + /** @deprecated Use `getLoggedInUser` */ + getUsername: () => string | undefined; + getLoggedInUser: () => string | undefined; + getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string; + getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined; + getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined; + parseRepoExplorerTitle: (pathname: string, title: string) => RepoExplorerInfo | undefined; +}; diff --git a/distribution/index.js b/distribution/index.js new file mode 100644 index 00000000..36cab315 --- /dev/null +++ b/distribution/index.js @@ -0,0 +1,352 @@ +// index.ts +import reservedNames from "github-reserved-names/reserved-names.json" with { type: "json" }; +var $ = (selector) => document.querySelector(selector); +var exists = (selector) => Boolean($(selector)); +var is404 = () => /^(Page|File) not found · GitHub/.test(document.title); +var is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out"; +var isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access"; +var isLoggedIn = () => exists("body.logged-in"); +var isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/")); +var isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url); +var isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url); +var isRepoCommitList = (url = location) => Boolean(getRepo(url)?.path.startsWith("commits")); +var isCompare = (url = location) => Boolean(getRepo(url)?.path.startsWith("compare")); +var isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare"); +var isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(-feed)?(\/|$)/.test(getCleanPathname(url)); +var isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com"; +var isGist = (url = location) => typeof getCleanGistPathname(url) === "string"; +var isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]); +var isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null; +var isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub \xB7 Where software is built"; +var isIssueOrPRList = (url = location) => isGlobalIssueOrPRList(url) || isRepoIssueOrPRList(url) || isMilestone(url); +var isConversation = (url = location) => isIssue(url) || isPRConversation(url); +var isLabelList = (url = location) => getRepo(url)?.path === "labels"; +var isMilestone = (url = location) => /^milestone\/\d+/.test(getRepo(url)?.path); +var isMilestoneList = (url = location) => getRepo(url)?.path === "milestones"; +var isNewFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("new")); +var isNewIssue = (url = location) => getRepo(url)?.path === "issues/new"; +var isNewRelease = (url = location) => getRepo(url)?.path === "releases/new"; +var isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new"); +var isNotifications = (url = location) => getCleanPathname(url) === "notifications"; +var isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]'); +var isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]'); +var isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams")); +var isOwnUserProfile = () => getCleanPathname() === getLoggedInUser(); +var isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]'); +var isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path); +var isProjects = (url = location) => getRepo(url)?.path === "projects"; +var isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path); +var isNewDiscussion = (url = location) => getRepo(url)?.path === "discussions/new" || getOrg(url)?.path === "discussions/new"; +var isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions"; +var isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url); +var isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path); +var isPRList = (url = location) => url.pathname === "/pulls" || getRepo(url)?.path === "pulls"; +var isPRCommit = (url = location) => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path); +var isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found \xB7 Pull Request"); +var isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found \xB7 Pull Request"); +var isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path); +var isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path); +var isPRFiles = (url = location) => /^pull\/\d+\/(files|(changes(\/[\da-f]{7,40}..[\da-f]{7,40})?$))/.test(getRepo(url)?.path) || isPRCommit(url); +var isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search); +var getStateLabel = () => $([ + ".State", + // Old view + '[class^="StateLabel"]' + // React version +].join(","))?.textContent?.trim(); +var isMergedPR = () => getStateLabel() === "Merged"; +var isDraftPR = () => getStateLabel() === "Draft"; +var isOpenConversation = () => { + const status = getStateLabel(); + return status === "Open" || status === "Draft"; +}; +var isClosedConversation = () => { + const status = getStateLabel(); + return status === "Closed" || status === "Closed as not planned" || status === "Merged"; +}; +var isReleases = (url = location) => getRepo(url)?.path === "releases"; +var isTags = (url = location) => getRepo(url)?.path === "tags"; +var isSingleReleaseOrTag = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/tag")); +var isReleasesOrTags = (url = location) => isReleases(url) || isTags(url); +var isDeletingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("delete")); +var isEditingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("edit")); +var hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url); +var isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/edit")); +var hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url); +var isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit"); +var hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url); +var isRepo = (url = location) => { + const [user, repo, extra] = getCleanPathname(url).split("/"); + return Boolean(user && repo && !reservedNames.includes(user) && !url.hostname.startsWith("gist.") && extra !== "generate"); +}; +var hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url); +var isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]'); +var isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]'); +var isPublicRepo = () => exists('meta[name="octolytics-dimension-repository_public"][content="true"]'); +var isArchivedRepo = () => Boolean(isRepo() && $("main > .flash-warn")?.textContent.includes("archived")); +var isBlank = () => exists("main .blankslate:not([hidden] .blankslate)"); +var isRepoTaxonomyIssueOrPRList = (url = location) => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path); +var isRepoIssueOrPRList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyIssueOrPRList(url); +var isRepoPRList = (url = location) => Boolean(getRepo(url)?.path.startsWith("pulls")); +var isRepoIssueList = (url = location) => ( + // `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t + /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path) +); +var hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1"; +var isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url); +var titleParseRegex = /^(?:(?[^ ]+) at (?[^ ]+)|[^/ ]+(?:\/(?[^ ]*))? at (?[^ ]+)(?: · (?[^ ]+))?)$/; +var parseRepoExplorerTitle = (pathname, title) => { + const match = titleParseRegex.exec(title); + if (!match?.groups) { + return; + } + let { nameWithOwner, branch, filePath, nameWithOwner2, branch2 } = match.groups; + nameWithOwner ??= nameWithOwner2; + branch ??= branch2; + filePath ??= ""; + if (!nameWithOwner || !branch || !pathname.startsWith(`/${nameWithOwner}/tree/`)) { + return; + } + return { nameWithOwner, branch, filePath }; +}; +var _isRepoRoot = (url) => { + const repository = getRepo(url ?? location); + if (!repository) { + return false; + } + const path = repository.path ? repository.path.split("/") : []; + switch (path.length) { + case 0: { + return true; + } + case 2: { + return path[0] === "tree"; + } + default: { + if (url) { + return false; + } + const titleInfo = parseRepoExplorerTitle(location.pathname, document.title); + return titleInfo?.filePath === ""; + } + } +}; +var isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url); +var isRepoSearch = (url = location) => getRepo(url)?.path === "search"; +var isRepoSettings = (url = location) => Boolean(getRepo(url)?.path.startsWith("settings")); +var isRepoMainSettings = (url = location) => getRepo(url)?.path === "settings"; +var isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies"); +var isUserSettings = (url = location) => url.pathname.startsWith("/settings/"); +var isRepoTree = (url = location) => _isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith("tree/")); +var isRepoWiki = (url = location) => Boolean(getRepo(url)?.path.startsWith("wiki")); +var isSingleCommit = (url = location) => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path); +var isSingleFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("blob/")); +var isFileFinder = (url = location) => Boolean(getRepo(url)?.path.startsWith("find/")); +var isRepoFile404 = (url = location) => (isSingleFile(url) || isRepoTree(url)) && document.title.startsWith("File not found"); +var isRepoForksList = (url = location) => getRepo(url)?.path === "network/members"; +var isRepoNetworkGraph = (url = location) => getRepo(url)?.path === "network"; +var isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]'); +var isForkingRepo = (url = location) => getRepo(url)?.path === "fork"; +var isSingleGist = (url = location) => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url)); +var isGistRevision = (url = location) => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url)); +var isTrending = (url = location) => url.pathname === "/trending" || url.pathname.startsWith("/trending/"); +var isBranches = (url = location) => Boolean(getRepo(url)?.path.startsWith("branches")); +var doesLookLikeAProfile = (string) => typeof string === "string" && string.length > 0 && !string.includes("/") && !string.includes(".") && !reservedNames.includes(string); +var isProfile = (url = location) => !isGist(url) && doesLookLikeAProfile(getCleanPathname(url)); +var isGistProfile = (url = location) => doesLookLikeAProfile(getCleanGistPathname(url)); +var isUserProfile = () => isProfile() && !isOrganizationProfile(); +var isPrivateUserProfile = () => isUserProfile() && !exists('.UnderlineNav-item[href$="tab=stars"]'); +var isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab"); +var isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "repositories"; +var isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars"; +var isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers"; +var isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following"; +var isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(url)?.path === "repositories"; +var hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url); +var hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url); +var hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url); +var isRepoGitObject = (url = location) => isRepo(url) && [void 0, "blob", "tree", "blame"].includes(getCleanPathname(url).split("/")[2]); +var hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url); +var isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/"); +var isActionJobRun = (url = location) => Boolean(getRepo(url)?.path.startsWith("runs/")); +var isActionRun = (url = location) => /^(actions\/)?runs/.test(getRepo(url)?.path); +var isNewAction = (url = location) => getRepo(url)?.path === "actions/new"; +var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path); +var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]'); +var canUserAdminRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]'); +var canUserEditRepo = canUserAdminRepo; +var isNewRepo = (url = location) => !isGist(url) && (url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url))); +var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate"); +var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0; +var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1); +var getCleanGistPathname = (url = location) => { + const pathname = getCleanPathname(url); + if (url.hostname.startsWith("gist.")) { + return pathname; + } + const [gist, ...parts] = pathname.split("/"); + return gist === "gist" ? parts.join("/") : void 0; +}; +var getOrg = (url = location) => { + const [orgs, name, ...path] = getCleanPathname(url).split("/"); + if (orgs === "orgs" && name) { + return { name, path: path.join("/") }; + } + return void 0; +}; +var getRepo = (url) => { + if (!url) { + const canonical = $('[property="og:url"]'); + if (canonical) { + const canonicalUrl = new URL(canonical.content, location.origin); + if (getCleanPathname(canonicalUrl).toLowerCase() === getCleanPathname(location).toLowerCase()) { + url = canonicalUrl; + } + } + } + if (typeof url === "string") { + url = new URL(url, location.origin); + } + if (!isRepo(url)) { + return; + } + const [owner, name, ...pathParts] = getCleanPathname(url).split("/"); + return { + owner, + name, + pathParts, + nameWithOwner: `${owner}/${name}`, + path: pathParts.join("/") + }; +}; +var utils = { + getOrg, + /** @deprecated Use `getLoggedInUser` */ + getUsername: getLoggedInUser, + getLoggedInUser, + getCleanPathname, + getCleanGistPathname, + getRepositoryInfo: getRepo, + parseRepoExplorerTitle +}; +export { + canUserAdminRepo, + canUserEditRepo, + hasCode, + hasComments, + hasFileEditor, + hasFiles, + hasReleaseEditor, + hasRepoHeader, + hasRichTextEditor, + hasWikiPageEditor, + is404, + is500, + isActionJobRun, + isActionRun, + isArchivedRepo, + isBlame, + isBlank, + isBranches, + isClosedConversation, + isCommit, + isCommitList, + isCompare, + isCompareWikiPage, + isConversation, + isDashboard, + isDeletingFile, + isDiscussion, + isDiscussionList, + isDraftPR, + isEditingFile, + isEditingRelease, + isEditingWikiPage, + isEmptyRepo, + isEmptyRepoRoot, + isEnterprise, + isFileFinder, + isForkedRepo, + isForkingRepo, + isGist, + isGistProfile, + isGistRevision, + isGlobalIssueOrPRList, + isGlobalSearchResults, + isIssue, + isIssueOrPRList, + isLabelList, + isLoggedIn, + isMarketplaceAction, + isMergedPR, + isMilestone, + isMilestoneList, + isNewAction, + isNewDiscussion, + isNewFile, + isNewIssue, + isNewRelease, + isNewRepo, + isNewRepoTemplate, + isNewWikiPage, + isNotifications, + isOpenConversation, + isOrganizationProfile, + isOrganizationRepo, + isOwnOrganizationProfile, + isOwnUserProfile, + isPR, + isPRCommit, + isPRCommit404, + isPRCommitList, + isPRConflicts, + isPRConversation, + isPRFile404, + isPRFiles, + isPRList, + isPasswordConfirmation, + isPrivateUserProfile, + isProfile, + isProfileRepoList, + isProject, + isProjects, + isPublicRepo, + isQuickPR, + isReleases, + isReleasesOrTags, + isRepliesSettings, + isRepo, + isRepoCommitList, + isRepoFile404, + isRepoForksList, + isRepoGitObject, + isRepoHome, + isRepoIssueList, + isRepoIssueOrPRList, + isRepoMainSettings, + isRepoNetworkGraph, + isRepoPRList, + isRepoRoot, + isRepoSearch, + isRepoSettings, + isRepoTaxonomyIssueOrPRList, + isRepoTree, + isRepoWiki, + isRepositoryActions, + isSingleCommit, + isSingleFile, + isSingleGist, + isSingleReleaseOrTag, + isTags, + isTeamDiscussion, + isTrending, + isUserProfile, + isUserProfileFollowersTab, + isUserProfileFollowingTab, + isUserProfileMainTab, + isUserProfileRepoTab, + isUserProfileStarsTab, + isUserSettings, + isUserTheOrganizationOwner, + utils +}; diff --git a/distribution/index.test.d.ts b/distribution/index.test.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/distribution/index.test.d.ts @@ -0,0 +1 @@ +export {}; From 127bf09078926084d378219cc1c7e18a3f167aaa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:53:45 +0000 Subject: [PATCH 7/7] Revert "Remove distribution from gitignore and commit distribution files" Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- .gitignore | 1 + distribution/collector.d.ts | 5 - distribution/index.d.ts | 585 ----------------------------------- distribution/index.js | 352 --------------------- distribution/index.test.d.ts | 1 - 5 files changed, 1 insertion(+), 943 deletions(-) delete mode 100644 distribution/collector.d.ts delete mode 100644 distribution/index.d.ts delete mode 100644 distribution/index.js delete mode 100644 distribution/index.test.d.ts diff --git a/.gitignore b/.gitignore index 03721dd4..46cb338c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ Thumbs.db *.log logs *.map +distribution dist .cache .parcel-cache diff --git a/distribution/collector.d.ts b/distribution/collector.d.ts deleted file mode 100644 index 86aafcc7..00000000 --- a/distribution/collector.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */ -export declare const testableUrls: Map; -export declare function addTests(test: string, urls: string[]): void; -export declare function getTests(detectName: string): string[]; -export declare function getAllUrls(): Set; diff --git a/distribution/index.d.ts b/distribution/index.d.ts deleted file mode 100644 index a07bdce2..00000000 --- a/distribution/index.d.ts +++ /dev/null @@ -1,585 +0,0 @@ -/* Examples added by add-examples-to-dts.ts */ -export declare const is404: () => boolean; -export declare const is500: () => boolean; -export declare const isPasswordConfirmation: () => boolean; -export declare const isLoggedIn: () => boolean; -/** @example https://github.com/sindresorhus/refined-github/blame/master/package.json */ -export declare const isBlame: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f - * @example https://github.com/sindresorhus/refined-github/commit/5b614 - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 - */ -export declare const isCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/commits/master?page=2 - * @example https://github.com/sindresorhus/refined-github/commits/test-branch - * @example https://github.com/sindresorhus/refined-github/commits/0.13.0 - * @example https://github.com/sindresorhus/refined-github/commits/230c2 - * @example https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63 - * @example https://github.com/sindresorhus/refined-github/commits?author=fregante - * @example https://github.com/sindresorhus/runs/commits/ - */ -export declare const isRepoCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/compare - * @example https://github.com/sindresorhus/refined-github/compare/ - * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name - * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1 - * @example https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1 - * @example https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1 - */ -export declare const isCompare: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/brookhong/Surfingkeys/wiki/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d - * @example https://github.com/brookhong/Surfingkeys/wiki/Color-Themes/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d - */ -export declare const isCompareWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/// - * @example https://github.com// - * @example https://github.com/ - * @example https://github.com - * @example https://github.com/orgs/test/dashboard - * @example https://github.com/dashboard/index/2 - * @example https://github.com//dashboard - * @example https://github.com/dashboard - * @example https://github.com/orgs/edit/dashboard - * @example https://github.big-corp.com/ - * @example https://not-github.com/ - * @example https://my-little-hub.com/ - * @example https://github.com/?tab=repositories - * @example https://github.com/?tab=stars - * @example https://github.com/?tab=followers - * @example https://github.com/?tab=following - * @example https://github.com/?tab=overview - * @example https://github.com?search=1 - * @example https://github.com/dashboard-feed - */ -export declare const isDashboard: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.big-corp.com/ - * @example https://not-github.com/ - * @example https://my-little-hub.com/ - * @example https://my-little-hub.com/gist - * @example https://my-little-hub.com/gist/in-fragrante - * @example https://gist.my-little-hub.com/in-fragrante - */ -export declare const isEnterprise: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://gist.github.com - * @example http://gist.github.com - * @example https://gist.github.com/new - * @example https://gist.github.com/fregante/2205329b71218fa2c1d3 - * @example https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad - * @example https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064 - * @example https://my-little-hub.com/gist - * @example https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions - * @example https://gist.github.com/fregante - * @example https://gist.github.com/github - * @example https://gist.github.com/babel - * @example https://my-little-hub.com/gist/in-fragrante - * @example https://gist.my-little-hub.com/in-fragrante - */ -export declare const isGist: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/issues - * @example https://github.com/issues?q=is%3Apr+is%3Aopen - * @example https://github.com/issues/assigned - * @example https://github.com/issues/mentioned - * @example https://github.com/pulls - * @example https://github.com/pulls?q=issues - * @example https://github.com/pulls/assigned - * @example https://github.com/pulls/mentioned - * @example https://github.com/pulls/review-requested - */ -export declare const isGlobalIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/search?q=refined-github&ref=opensearch */ -export declare const isGlobalSearchResults: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/issues/146 */ -export declare const isIssue: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isConversation: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/labels - * @example https://github.com/sindresorhus/refined-github/labels/ - */ -export declare const isLabelList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/kubernetes/kubernetes/milestone/56 */ -export declare const isMilestone: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/milestones */ -export declare const isMilestoneList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/new/main */ -export declare const isNewFile: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/issues/new */ -export declare const isNewIssue: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/releases/new */ -export declare const isNewRelease: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/tooomm/wikitest/wiki/_new */ -export declare const isNewWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/notifications */ -export declare const isNotifications: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isOrganizationProfile: () => boolean; -export declare const isOrganizationRepo: () => boolean; -/** - * @example https://github.com/orgs/refined-github/teams/core-team/discussions?pinned=1 - * @example https://github.com/orgs/refined-github/teams/core-team/discussions/1 - * @example https://github.com/orgs/refined-github/teams/core-team - */ -export declare const isTeamDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isOwnUserProfile: () => boolean; -export declare const isOwnOrganizationProfile: () => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/projects/3 - * @example https://github.com/orgs/RSSNext/projects/3 - */ -export declare const isProject: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/projects */ -export declare const isProjects: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/tophf/mpiv/discussions/50 - * @example https://github.com/orgs/community/discussions/11202 - */ -export declare const isDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/withastro/roadmap/discussions/new?category=proposal - * @example https://github.com/orgs/community/discussions/new?category=pull-requests - */ -export declare const isNewDiscussion: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/tophf/mpiv/discussions - * @example https://github.com/orgs/community/discussions - */ -export declare const isDiscussionList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/files - * @example https://github.com/sindresorhus/refined-github/pull/148/files/e1aba6f - * @example https://github.com/sindresorhus/refined-github/pull/148/files/1e27d799..e1aba6f - * @example https://github.com/refined-github/refined-github/pull/148/changes - * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d799..e1aba6f - * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641..e1aba6febb3fe38aafd1137cff28b536eeeabe7e - * @example https://github.com/sindresorhus/refined-github/pull/148/commits - * @example https://github.com/sindresorhus/refined-github/pull/148 - */ -export declare const isPR: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/pull/148/conflicts */ -export declare const isPRConflicts: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * Any `isIssueOrPRList` can display both issues and PRs, prefer that detection. `isPRList` only exists because this page has PR-specific filters like the "Reviews" dropdown - * @example https://github.com/pulls - * @example https://github.com/pulls?q=issues - * @example https://github.com/sindresorhus/refined-github/pulls - * @example https://github.com/sindresorhus/refined-github/pulls/ - * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr - * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed - */ -export declare const isPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 - */ -export declare const isPRCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isPRCommit404: () => boolean; -export declare const isPRFile404: () => boolean; -/** @example https://github.com/sindresorhus/refined-github/pull/148 */ -export declare const isPRConversation: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/pull/148/commits */ -export declare const isPRCommitList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/commits/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641 - * @example https://github.com/sindresorhus/refined-github/pull/148/changes/1e27d79 - * @example https://github.com/sindresorhus/refined-github/pull/148/files - * @example https://github.com/sindresorhus/refined-github/pull/148/files/e1aba6f - * @example https://github.com/sindresorhus/refined-github/pull/148/files/1e27d799..e1aba6f - * @example https://github.com/refined-github/refined-github/pull/148/changes - * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d799..e1aba6f - * @example https://github.com/refined-github/refined-github/pull/148/changes/1e27d7998afdd3608d9fc3bf95ccf27fa5010641..e1aba6febb3fe38aafd1137cff28b536eeeabe7e - */ -export declare const isPRFiles: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/compare/master...branch-name?quick_pull=1 - * @example https://github.com/sindresorhus/refined-github/compare/branch-1...branch-2?quick_pull=1 - * @example https://github.com/sindresorhus/refined-github/compare/test-branch?quick_pull=1 - */ -export declare const isQuickPR: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isMergedPR: () => boolean; -export declare const isDraftPR: () => boolean; -export declare const isOpenConversation: () => boolean; -export declare const isClosedConversation: () => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/releases - * @example https://github.com/sindresorhus/refined-github/releases?page=2 - */ -export declare const isReleases: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/tags - * @example https://github.com/sindresorhus/refined-github/tags?after=21.8.1 - */ -export declare const isTags: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/refined-github/refined-github/releases/tag/1.20.1 - * @example https://github.com/refined-github/refined-github/releases/tag/23.7.25 - */ -export declare const isSingleReleaseOrTag: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/releases - * @example https://github.com/sindresorhus/refined-github/releases?page=2 - * @example https://github.com/sindresorhus/refined-github/tags - * @example https://github.com/sindresorhus/refined-github/tags?after=21.8.1 - */ -export declare const isReleasesOrTags: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/delete/master/readme.md - * @example https://github.com/sindresorhus/refined-github/delete/ghe-injection/source/background.ts - */ -export declare const isDeletingFile: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/edit/master/readme.md - * @example https://github.com/sindresorhus/refined-github/edit/ghe-injection/source/background.ts - */ -export declare const isEditingFile: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasFileEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/releases/edit/v1.2.3 */ -export declare const isEditingRelease: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasReleaseEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/tooomm/wikitest/wiki/Getting-Started/_edit */ -export declare const isEditingWikiPage: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasWikiPageEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/blame/master/package.json - * @example https://github.com/sindresorhus/refined-github/issues/146 - * @example https://github.com/sindresorhus/notifications/ - * @example https://github.com/sindresorhus/refined-github/pull/148 - * @example https://github.com/sindresorhus/refined-github/milestones/new - * @example https://github.com/sindresorhus/refined-github/milestones/1/edit - * @example https://github.com/sindresorhus/refined-github/issues/new/choose - * @example https://github.com/sindresorhus/refined-github/issues/templates/edit - */ -export declare const isRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasRepoHeader: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isEmptyRepoRoot: () => boolean; -export declare const isEmptyRepo: () => boolean; -export declare const isPublicRepo: () => boolean; -export declare const isArchivedRepo: () => boolean; -export declare const isBlank: () => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/labels/bug - * @example https://github.com/sindresorhus/refined-github/labels/implemented%20by%20github - * @example https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt - * @example https://github.com/sindresorhus/refined-github/milestones/1 - */ -export declare const isRepoTaxonomyIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isRepoIssueOrPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/pulls - * @example https://github.com/sindresorhus/refined-github/pulls/ - * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Aopen+is%3Apr - * @example https://github.com/sindresorhus/refined-github/pulls?q=is%3Apr+is%3Aclosed - */ -export declare const isRepoPRList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example http://github.com/sindresorhus/ava/issues - * @example https://github.com/sindresorhus/refined-github/issues - * @example https://github.com/sindresorhus/refined-github/issues/fregante - * @example https://github.com/sindresorhus/refined-github/issues/newton - * @example https://github.com/sindresorhus/refined-github/issues/wptemplates - * @example https://github.com/sindresorhus/refined-github/issues?q=is%3Aclosed+sort%3Aupdated-desc - * @example https://github.com/sindresorhus/refined-github/labels/bug - * @example https://github.com/sindresorhus/refined-github/labels/implemented%20by%20github - * @example https://github.com/sindresorhus/refined-github/labels/%3Adollar%3A%20Funded%20on%20Issuehunt - */ -export declare const isRepoIssueList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github - * @example https://github.com/sindresorhus/refined-github/ - * @example https://github.com/sindresorhus/notifications/ - * @example https://github.com/sindresorhus/edit - * @example https://github.com/sindresorhus///edit - * @example https://github.com/sindresorhus/search - * @example https://github.com/sindresorhus/branches - * @example https://github.com/sindresorhus/refined-github?files=1 - */ -export declare const isRepoHome: (url?: URL | HTMLAnchorElement | Location) => boolean; -export type RepoExplorerInfo = { - nameWithOwner: string; - branch: string; - filePath: string; -}; -/** - * @example https://github.com/sindresorhus/refined-github - * @example https://github.com/sindresorhus/refined-github/ - * @example https://github.com/sindresorhus/notifications/ - * @example https://github.com/sindresorhus/edit - * @example https://github.com/sindresorhus///edit - * @example https://github.com/sindresorhus/search - * @example https://github.com/sindresorhus/branches - * @example https://github.com/sindresorhus/refined-github?files=1 - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ - * @example https://github.com/sindresorhus/refined-github/tree/57bf4 - * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 - */ -export declare const isRepoRoot: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/search?q=diff - * @example https://github.com/sindresorhus/refined-github/search?q=diff&unscoped_q=diff&type=Issues - * @example https://github.com/sindresorhus/refined-github/search - */ -export declare const isRepoSearch: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/settings - * @example https://github.com/sindresorhus/refined-github/settings/branches - */ -export declare const isRepoSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/settings */ -export declare const isRepoMainSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/settings/replies - * @example https://github.com/settings/replies/88491/edit - */ -export declare const isRepliesSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/settings/profile - * @example https://github.com/settings/replies - * @example https://github.com/settings/replies/88491/edit - */ -export declare const isUserSettings: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github - * @example https://github.com/sindresorhus/refined-github/ - * @example https://github.com/sindresorhus/notifications/ - * @example https://github.com/sindresorhus/edit - * @example https://github.com/sindresorhus///edit - * @example https://github.com/sindresorhus/search - * @example https://github.com/sindresorhus/branches - * @example https://github.com/sindresorhus/refined-github?files=1 - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ - * @example https://github.com/sindresorhus/refined-github/tree/57bf4 - * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 - * @example https://github.com/sindresorhus/refined-github/tree/main/source - * @example https://github.com/sindresorhus/refined-github/tree/0.13.0/extension - * @example https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension - * @example https://github.com/sindresorhus/refined-github?search=1 - */ -export declare const isRepoTree: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/lukesampson/scoop/wiki - * @example https://github.com/tooomm/wikitest/wiki/_new - * @example https://github.com/tooomm/wikitest/wiki/Getting-Started/_edit - * @example https://github.com/brookhong/Surfingkeys/wiki/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d - * @example https://github.com/brookhong/Surfingkeys/wiki/Color-Themes/_compare/8ebb46b1a12d16fc1af442b7df0ca13ca3bb34dc...80e51eeabe69b15a3f23880ecc36f800b71e6c6d - */ -export declare const isRepoWiki: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/commit/5b614b9035f2035b839f48b4db7bd5c3298d526f - * @example https://github.com/sindresorhus/refined-github/commit/5b614 - */ -export declare const isSingleCommit: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/blob/master/.gitattributes - * @example https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css - * @example https://github.com/sindresorhus/refined-github/blob/master/edit.txt - */ -export declare const isSingleFile: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/find/master */ -export declare const isFileFinder: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante/GhostText/tree/3cacd7df71b097dc525d99c7aa2f54d31b02fcc8/chrome/scripts/InputArea - * @example https://github.com/refined-github/refined-github/blob/some-non-existent-ref/source/features/bugs-tab.tsx - */ -export declare const isRepoFile404: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/network/members */ -export declare const isRepoForksList: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/network */ -export declare const isRepoNetworkGraph: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isForkedRepo: () => boolean; -/** @example https://github.com/refined-github/refined-github/fork */ -export declare const isForkingRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://gist.github.com/fregante/2205329b71218fa2c1d3 - * @example https://gist.github.com/fregante/2205329b71218fa2c1d3/d1ebf7d9cfaba4d4596d2ea9174e202479a5f9ad - * @example https://gist.github.com/sindresorhus/0ea3c2845718a0a0f0beb579ff14f064 - */ -export declare const isSingleGist: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://gist.github.com/kidonng/0d16c7f17045f486751fad1b602204a0/revisions */ -export declare const isGistRevision: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/trending - * @example https://github.com/trending/developers - * @example https://github.com/trending/unknown - */ -export declare const isTrending: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/branches */ -export declare const isBranches: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante - * @example https://github.com/github - * @example https://github.com/babel - * @example https://github.com/fregante?tab=repositories - * @example https://github.com/fregante?tab=repositories&type=source - * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= - * @example https://github.com/fregante?tab=stars - * @example https://github.com/fregante?direction=desc&sort=updated&tab=stars - * @example https://github.com/fregante?tab=followers - * @example https://github.com/sindresorhus?tab=followers - * @example https://github.com/fregante?tab=following - * @example https://github.com/sindresorhus?tab=following - */ -export declare const isProfile: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://gist.github.com/fregante - * @example https://gist.github.com/github - * @example https://gist.github.com/babel - * @example https://my-little-hub.com/gist/in-fragrante - * @example https://gist.my-little-hub.com/in-fragrante - */ -export declare const isGistProfile: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isUserProfile: () => boolean; -export declare const isPrivateUserProfile: () => boolean; -export declare const isUserProfileMainTab: () => boolean; -/** - * @example https://github.com/fregante?tab=repositories - * @example https://github.com/fregante?tab=repositories&type=source - * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= - */ -export declare const isUserProfileRepoTab: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante?tab=stars - * @example https://github.com/fregante?direction=desc&sort=updated&tab=stars - */ -export declare const isUserProfileStarsTab: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante?tab=followers - * @example https://github.com/sindresorhus?tab=followers - */ -export declare const isUserProfileFollowersTab: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante?tab=following - * @example https://github.com/sindresorhus?tab=following - */ -export declare const isUserProfileFollowingTab: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/fregante?tab=repositories - * @example https://github.com/fregante?tab=repositories&type=source - * @example https://github.com/fregante?tab=repositories&q=&type=source&language=css&sort= - * @example https://github.com/orgs/refined-github/repositories - * @example https://github.com/orgs/refined-github/repositories?q=&type=private&language=&sort= - */ -export declare const isProfileRepoList: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasComments: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const hasRichTextEditor: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** Static code, not the code editor */ -export declare const hasCode: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * Covers blob, trees and blame pages - * @example https://github.com/sindresorhus/refined-github - * @example https://github.com/sindresorhus/refined-github/ - * @example https://github.com/sindresorhus/notifications/ - * @example https://github.com/sindresorhus/edit - * @example https://github.com/sindresorhus///edit - * @example https://github.com/sindresorhus/search - * @example https://github.com/sindresorhus/branches - * @example https://github.com/sindresorhus/refined-github?files=1 - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons - * @example https://github.com/sindresorhus/refined-github/tree/native-copy-buttons/ - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6 - * @example https://github.com/sindresorhus/refined-github/tree/03fa6b8b4d6e68dea9dc9bee1d197ef5d992fbd6/ - * @example https://github.com/sindresorhus/refined-github/tree/57bf4 - * @example https://github.com/sindresorhus/refined-github/tree/master?files=1 - * @example https://github.com/sindresorhus/refined-github/tree/main/source - * @example https://github.com/sindresorhus/refined-github/tree/0.13.0/extension - * @example https://github.com/sindresorhus/refined-github/tree/57bf435ee12d14b482df0bbd88013a2814c7512e/extension - * @example https://github.com/sindresorhus/refined-github?search=1 - * @example https://github.com/sindresorhus/refined-github/blob/master/.gitattributes - * @example https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css - * @example https://github.com/sindresorhus/refined-github/blob/master/edit.txt - * @example https://github.com/sindresorhus/refined-github/blame/master/package.json - */ -export declare const isRepoGitObject: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** Has a list of files */ -export declare const hasFiles: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/marketplace/actions/urlchecker-action - * @example https://github.com/marketplace/actions/github-action-for-assignee-to-reviewer - * @example https://github.com/marketplace/actions/hugo-actions - */ -export declare const isMarketplaceAction: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/runs/639481849 - * @example https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true - */ -export declare const isActionJobRun: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/sindresorhus/refined-github/runs/639481849 - * @example https://github.com/refined-github/github-url-detection/runs/1224552520?check_suite_focus=true - * @example https://github.com/refined-github/github-url-detection/actions/runs/294962314 - */ -export declare const isActionRun: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/sindresorhus/refined-github/actions/new */ -export declare const isNewAction: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** - * @example https://github.com/refined-github/github-url-detection/actions - * @example https://github.com/refined-github/github-url-detection/actions/workflows/demo.yml - * @example https://github.com/refined-github/github-url-detection/actions/workflows/esm-lint.yml - */ -export declare const isRepositoryActions: (url?: URL | HTMLAnchorElement | Location) => boolean; -export declare const isUserTheOrganizationOwner: () => boolean; -export declare const canUserAdminRepo: () => boolean; -/** @deprecated Use `canUserAdminRepo` */ -export declare const canUserEditRepo: () => boolean; -/** - * @example https://github.com/new - * @example https://github.com/organizations/npmhub/repositories/new - */ -export declare const isNewRepo: (url?: URL | HTMLAnchorElement | Location) => boolean; -/** @example https://github.com/fregante/browser-extension-template/generate */ -export declare const isNewRepoTemplate: (url?: URL | HTMLAnchorElement | Location) => boolean; -export type NameWithOwner = `${string}/${string}`; -export type RepositoryInfo = { - /** The repo owner/user */ - owner: string; - /** The repo name */ - name: string; - /** The 'user/repo' part from an URL */ - nameWithOwner: NameWithOwner; - /** A repo's subpage - @example '/user/repo/issues/' -> 'issues' - @example '/user/repo/' -> '' - @example '/settings/token/' -> undefined */ - path: string; - /** The `path` segments - @example '/user/repo/' -> [] - @example '/user/repo/issues/' -> ['issues'] - @example '/user/repo/issues/new' -> ['issues', 'new'] */ - pathParts: string[]; -}; -export declare const utils: { - getOrg: (url?: URL | HTMLAnchorElement | Location) => { - name: string; - path: string; - } | undefined; - /** @deprecated Use `getLoggedInUser` */ - getUsername: () => string | undefined; - getLoggedInUser: () => string | undefined; - getCleanPathname: (url?: URL | HTMLAnchorElement | Location) => string; - getCleanGistPathname: (url?: URL | HTMLAnchorElement | Location) => string | undefined; - getRepositoryInfo: (url?: URL | HTMLAnchorElement | Location | string) => RepositoryInfo | undefined; - parseRepoExplorerTitle: (pathname: string, title: string) => RepoExplorerInfo | undefined; -}; diff --git a/distribution/index.js b/distribution/index.js deleted file mode 100644 index 36cab315..00000000 --- a/distribution/index.js +++ /dev/null @@ -1,352 +0,0 @@ -// index.ts -import reservedNames from "github-reserved-names/reserved-names.json" with { type: "json" }; -var $ = (selector) => document.querySelector(selector); -var exists = (selector) => Boolean($(selector)); -var is404 = () => /^(Page|File) not found · GitHub/.test(document.title); -var is500 = () => document.title === "Server Error \xB7 GitHub" || document.title === "Unicorn! \xB7 GitHub" || document.title === "504 Gateway Time-out"; -var isPasswordConfirmation = () => document.title === "Confirm password" || document.title === "Confirm access"; -var isLoggedIn = () => exists("body.logged-in"); -var isBlame = (url = location) => Boolean(getRepo(url)?.path.startsWith("blame/")); -var isCommit = (url = location) => isSingleCommit(url) || isPRCommit(url); -var isCommitList = (url = location) => isRepoCommitList(url) || isPRCommitList(url); -var isRepoCommitList = (url = location) => Boolean(getRepo(url)?.path.startsWith("commits")); -var isCompare = (url = location) => Boolean(getRepo(url)?.path.startsWith("compare")); -var isCompareWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).split("/").slice(3, 5).includes("_compare"); -var isDashboard = (url = location) => !isGist(url) && /^$|^(orgs\/[^/]+\/)?dashboard(-feed)?(\/|$)/.test(getCleanPathname(url)); -var isEnterprise = (url = location) => url.hostname !== "github.com" && url.hostname !== "gist.github.com"; -var isGist = (url = location) => typeof getCleanGistPathname(url) === "string"; -var isGlobalIssueOrPRList = (url = location) => ["issues", "pulls"].includes(url.pathname.split("/", 2)[1]); -var isGlobalSearchResults = (url = location) => url.pathname === "/search" && new URLSearchParams(url.search).get("q") !== null; -var isIssue = (url = location) => /^issues\/\d+/.test(getRepo(url)?.path) && document.title !== "GitHub \xB7 Where software is built"; -var isIssueOrPRList = (url = location) => isGlobalIssueOrPRList(url) || isRepoIssueOrPRList(url) || isMilestone(url); -var isConversation = (url = location) => isIssue(url) || isPRConversation(url); -var isLabelList = (url = location) => getRepo(url)?.path === "labels"; -var isMilestone = (url = location) => /^milestone\/\d+/.test(getRepo(url)?.path); -var isMilestoneList = (url = location) => getRepo(url)?.path === "milestones"; -var isNewFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("new")); -var isNewIssue = (url = location) => getRepo(url)?.path === "issues/new"; -var isNewRelease = (url = location) => getRepo(url)?.path === "releases/new"; -var isNewWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_new"); -var isNotifications = (url = location) => getCleanPathname(url) === "notifications"; -var isOrganizationProfile = () => exists('meta[name="hovercard-subject-tag"][content^="organization"]'); -var isOrganizationRepo = () => exists('.AppHeader-context-full [data-hovercard-type="organization"]'); -var isTeamDiscussion = (url = location) => Boolean(getOrg(url)?.path.startsWith("teams")); -var isOwnUserProfile = () => getCleanPathname() === getLoggedInUser(); -var isOwnOrganizationProfile = () => isOrganizationProfile() && !exists('[href*="contact/report-abuse?report="]'); -var isProject = (url = location) => /^projects\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path); -var isProjects = (url = location) => getRepo(url)?.path === "projects"; -var isDiscussion = (url = location) => /^discussions\/\d+/.test(getRepo(url)?.path ?? getOrg(url)?.path); -var isNewDiscussion = (url = location) => getRepo(url)?.path === "discussions/new" || getOrg(url)?.path === "discussions/new"; -var isDiscussionList = (url = location) => getRepo(url)?.path === "discussions" || getOrg(url)?.path === "discussions"; -var isPR = (url = location) => /^pull\/\d+/.test(getRepo(url)?.path) && !isPRConflicts(url); -var isPRConflicts = (url = location) => /^pull\/\d+\/conflicts/.test(getRepo(url)?.path); -var isPRList = (url = location) => url.pathname === "/pulls" || getRepo(url)?.path === "pulls"; -var isPRCommit = (url = location) => /^pull\/\d+\/(commits|changes)\/[\da-f]{7,40}$/.test(getRepo(url)?.path); -var isPRCommit404 = () => isPRCommit() && document.title.startsWith("Commit range not found \xB7 Pull Request"); -var isPRFile404 = () => isPRFiles() && document.title.startsWith("Commit range not found \xB7 Pull Request"); -var isPRConversation = (url = location) => /^pull\/\d+$/.test(getRepo(url)?.path); -var isPRCommitList = (url = location) => /^pull\/\d+\/commits$/.test(getRepo(url)?.path); -var isPRFiles = (url = location) => /^pull\/\d+\/(files|(changes(\/[\da-f]{7,40}..[\da-f]{7,40})?$))/.test(getRepo(url)?.path) || isPRCommit(url); -var isQuickPR = (url = location) => isCompare(url) && /[?&]quick_pull=1(&|$)/.test(url.search); -var getStateLabel = () => $([ - ".State", - // Old view - '[class^="StateLabel"]' - // React version -].join(","))?.textContent?.trim(); -var isMergedPR = () => getStateLabel() === "Merged"; -var isDraftPR = () => getStateLabel() === "Draft"; -var isOpenConversation = () => { - const status = getStateLabel(); - return status === "Open" || status === "Draft"; -}; -var isClosedConversation = () => { - const status = getStateLabel(); - return status === "Closed" || status === "Closed as not planned" || status === "Merged"; -}; -var isReleases = (url = location) => getRepo(url)?.path === "releases"; -var isTags = (url = location) => getRepo(url)?.path === "tags"; -var isSingleReleaseOrTag = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/tag")); -var isReleasesOrTags = (url = location) => isReleases(url) || isTags(url); -var isDeletingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("delete")); -var isEditingFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("edit")); -var hasFileEditor = (url = location) => isEditingFile(url) || isNewFile(url) || isDeletingFile(url); -var isEditingRelease = (url = location) => Boolean(getRepo(url)?.path.startsWith("releases/edit")); -var hasReleaseEditor = (url = location) => isEditingRelease(url) || isNewRelease(url); -var isEditingWikiPage = (url = location) => isRepoWiki(url) && getCleanPathname(url).endsWith("/_edit"); -var hasWikiPageEditor = (url = location) => isEditingWikiPage(url) || isNewWikiPage(url); -var isRepo = (url = location) => { - const [user, repo, extra] = getCleanPathname(url).split("/"); - return Boolean(user && repo && !reservedNames.includes(user) && !url.hostname.startsWith("gist.") && extra !== "generate"); -}; -var hasRepoHeader = (url = location) => isRepo(url) && !isRepoSearch(url); -var isEmptyRepoRoot = () => isRepoHome() && !exists('link[rel="canonical"]'); -var isEmptyRepo = () => exists('[aria-label="Cannot fork because repository is empty."]'); -var isPublicRepo = () => exists('meta[name="octolytics-dimension-repository_public"][content="true"]'); -var isArchivedRepo = () => Boolean(isRepo() && $("main > .flash-warn")?.textContent.includes("archived")); -var isBlank = () => exists("main .blankslate:not([hidden] .blankslate)"); -var isRepoTaxonomyIssueOrPRList = (url = location) => /^labels\/.+|^milestones\/\d+(?!\/edit)/.test(getRepo(url)?.path); -var isRepoIssueOrPRList = (url = location) => isRepoPRList(url) || isRepoIssueList(url) || isRepoTaxonomyIssueOrPRList(url); -var isRepoPRList = (url = location) => Boolean(getRepo(url)?.path.startsWith("pulls")); -var isRepoIssueList = (url = location) => ( - // `issues/fregante` is a list but `issues/1`, `issues/new`, `issues/new/choose`, `issues/templates/edit` aren’t - /^labels\/|^issues(?!\/(\d+|new|templates)($|\/))/.test(getRepo(url)?.path) -); -var hasSearchParameter = (url) => new URLSearchParams(url.search).get("search") === "1"; -var isRepoHome = (url = location) => getRepo(url)?.path === "" && !hasSearchParameter(url); -var titleParseRegex = /^(?:(?[^ ]+) at (?[^ ]+)|[^/ ]+(?:\/(?[^ ]*))? at (?[^ ]+)(?: · (?[^ ]+))?)$/; -var parseRepoExplorerTitle = (pathname, title) => { - const match = titleParseRegex.exec(title); - if (!match?.groups) { - return; - } - let { nameWithOwner, branch, filePath, nameWithOwner2, branch2 } = match.groups; - nameWithOwner ??= nameWithOwner2; - branch ??= branch2; - filePath ??= ""; - if (!nameWithOwner || !branch || !pathname.startsWith(`/${nameWithOwner}/tree/`)) { - return; - } - return { nameWithOwner, branch, filePath }; -}; -var _isRepoRoot = (url) => { - const repository = getRepo(url ?? location); - if (!repository) { - return false; - } - const path = repository.path ? repository.path.split("/") : []; - switch (path.length) { - case 0: { - return true; - } - case 2: { - return path[0] === "tree"; - } - default: { - if (url) { - return false; - } - const titleInfo = parseRepoExplorerTitle(location.pathname, document.title); - return titleInfo?.filePath === ""; - } - } -}; -var isRepoRoot = (url) => !hasSearchParameter(url ?? location) && _isRepoRoot(url); -var isRepoSearch = (url = location) => getRepo(url)?.path === "search"; -var isRepoSettings = (url = location) => Boolean(getRepo(url)?.path.startsWith("settings")); -var isRepoMainSettings = (url = location) => getRepo(url)?.path === "settings"; -var isRepliesSettings = (url = location) => url.pathname.startsWith("/settings/replies"); -var isUserSettings = (url = location) => url.pathname.startsWith("/settings/"); -var isRepoTree = (url = location) => _isRepoRoot(url) || Boolean(getRepo(url)?.path.startsWith("tree/")); -var isRepoWiki = (url = location) => Boolean(getRepo(url)?.path.startsWith("wiki")); -var isSingleCommit = (url = location) => /^commit\/[\da-f]{5,40}$/.test(getRepo(url)?.path); -var isSingleFile = (url = location) => Boolean(getRepo(url)?.path.startsWith("blob/")); -var isFileFinder = (url = location) => Boolean(getRepo(url)?.path.startsWith("find/")); -var isRepoFile404 = (url = location) => (isSingleFile(url) || isRepoTree(url)) && document.title.startsWith("File not found"); -var isRepoForksList = (url = location) => getRepo(url)?.path === "network/members"; -var isRepoNetworkGraph = (url = location) => getRepo(url)?.path === "network"; -var isForkedRepo = () => exists('meta[name="octolytics-dimension-repository_is_fork"][content="true"]'); -var isForkingRepo = (url = location) => getRepo(url)?.path === "fork"; -var isSingleGist = (url = location) => /^[^/]+\/[\da-f]{20,32}(\/[\da-f]{40})?$/.test(getCleanGistPathname(url)); -var isGistRevision = (url = location) => /^[^/]+\/[\da-f]{20,32}\/revisions$/.test(getCleanGistPathname(url)); -var isTrending = (url = location) => url.pathname === "/trending" || url.pathname.startsWith("/trending/"); -var isBranches = (url = location) => Boolean(getRepo(url)?.path.startsWith("branches")); -var doesLookLikeAProfile = (string) => typeof string === "string" && string.length > 0 && !string.includes("/") && !string.includes(".") && !reservedNames.includes(string); -var isProfile = (url = location) => !isGist(url) && doesLookLikeAProfile(getCleanPathname(url)); -var isGistProfile = (url = location) => doesLookLikeAProfile(getCleanGistPathname(url)); -var isUserProfile = () => isProfile() && !isOrganizationProfile(); -var isPrivateUserProfile = () => isUserProfile() && !exists('.UnderlineNav-item[href$="tab=stars"]'); -var isUserProfileMainTab = () => isUserProfile() && !new URLSearchParams(location.search).has("tab"); -var isUserProfileRepoTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "repositories"; -var isUserProfileStarsTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "stars"; -var isUserProfileFollowersTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "followers"; -var isUserProfileFollowingTab = (url = location) => isProfile(url) && new URLSearchParams(url.search).get("tab") === "following"; -var isProfileRepoList = (url = location) => isUserProfileRepoTab(url) || getOrg(url)?.path === "repositories"; -var hasComments = (url = location) => isPR(url) || isIssue(url) || isCommit(url) || isTeamDiscussion(url) || isSingleGist(url); -var hasRichTextEditor = (url = location) => hasComments(url) || isNewIssue(url) || isCompare(url) || isRepliesSettings(url) || hasReleaseEditor(url) || isDiscussion(url) || isNewDiscussion(url); -var hasCode = (url = location) => hasComments(url) || isRepoTree(url) || isRepoSearch(url) || isGlobalSearchResults(url) || isSingleFile(url) || isGist(url) || isCompare(url) || isCompareWikiPage(url) || isBlame(url); -var isRepoGitObject = (url = location) => isRepo(url) && [void 0, "blob", "tree", "blame"].includes(getCleanPathname(url).split("/")[2]); -var hasFiles = (url = location) => isCommit(url) || isCompare(url) || isPRFiles(url); -var isMarketplaceAction = (url = location) => url.pathname.startsWith("/marketplace/actions/"); -var isActionJobRun = (url = location) => Boolean(getRepo(url)?.path.startsWith("runs/")); -var isActionRun = (url = location) => /^(actions\/)?runs/.test(getRepo(url)?.path); -var isNewAction = (url = location) => getRepo(url)?.path === "actions/new"; -var isRepositoryActions = (url = location) => /^actions(\/workflows\/.+\.ya?ml)?$/.test(getRepo(url)?.path); -var isUserTheOrganizationOwner = () => isOrganizationProfile() && exists('[aria-label="Organization"] [data-tab-item="org-header-settings-tab"]'); -var canUserAdminRepo = () => isRepo() && exists('.reponav-item[href$="/settings"], [data-tab-item$="settings-tab"]'); -var canUserEditRepo = canUserAdminRepo; -var isNewRepo = (url = location) => !isGist(url) && (url.pathname === "/new" || /^organizations\/[^/]+\/repositories\/new$/.test(getCleanPathname(url))); -var isNewRepoTemplate = (url = location) => Boolean(url.pathname.split("/")[3] === "generate"); -var getLoggedInUser = () => $('meta[name="user-login"]')?.getAttribute("content") ?? void 0; -var getCleanPathname = (url = location) => url.pathname.replaceAll(/\/\/+/g, "/").replace(/\/$/, "").slice(1); -var getCleanGistPathname = (url = location) => { - const pathname = getCleanPathname(url); - if (url.hostname.startsWith("gist.")) { - return pathname; - } - const [gist, ...parts] = pathname.split("/"); - return gist === "gist" ? parts.join("/") : void 0; -}; -var getOrg = (url = location) => { - const [orgs, name, ...path] = getCleanPathname(url).split("/"); - if (orgs === "orgs" && name) { - return { name, path: path.join("/") }; - } - return void 0; -}; -var getRepo = (url) => { - if (!url) { - const canonical = $('[property="og:url"]'); - if (canonical) { - const canonicalUrl = new URL(canonical.content, location.origin); - if (getCleanPathname(canonicalUrl).toLowerCase() === getCleanPathname(location).toLowerCase()) { - url = canonicalUrl; - } - } - } - if (typeof url === "string") { - url = new URL(url, location.origin); - } - if (!isRepo(url)) { - return; - } - const [owner, name, ...pathParts] = getCleanPathname(url).split("/"); - return { - owner, - name, - pathParts, - nameWithOwner: `${owner}/${name}`, - path: pathParts.join("/") - }; -}; -var utils = { - getOrg, - /** @deprecated Use `getLoggedInUser` */ - getUsername: getLoggedInUser, - getLoggedInUser, - getCleanPathname, - getCleanGistPathname, - getRepositoryInfo: getRepo, - parseRepoExplorerTitle -}; -export { - canUserAdminRepo, - canUserEditRepo, - hasCode, - hasComments, - hasFileEditor, - hasFiles, - hasReleaseEditor, - hasRepoHeader, - hasRichTextEditor, - hasWikiPageEditor, - is404, - is500, - isActionJobRun, - isActionRun, - isArchivedRepo, - isBlame, - isBlank, - isBranches, - isClosedConversation, - isCommit, - isCommitList, - isCompare, - isCompareWikiPage, - isConversation, - isDashboard, - isDeletingFile, - isDiscussion, - isDiscussionList, - isDraftPR, - isEditingFile, - isEditingRelease, - isEditingWikiPage, - isEmptyRepo, - isEmptyRepoRoot, - isEnterprise, - isFileFinder, - isForkedRepo, - isForkingRepo, - isGist, - isGistProfile, - isGistRevision, - isGlobalIssueOrPRList, - isGlobalSearchResults, - isIssue, - isIssueOrPRList, - isLabelList, - isLoggedIn, - isMarketplaceAction, - isMergedPR, - isMilestone, - isMilestoneList, - isNewAction, - isNewDiscussion, - isNewFile, - isNewIssue, - isNewRelease, - isNewRepo, - isNewRepoTemplate, - isNewWikiPage, - isNotifications, - isOpenConversation, - isOrganizationProfile, - isOrganizationRepo, - isOwnOrganizationProfile, - isOwnUserProfile, - isPR, - isPRCommit, - isPRCommit404, - isPRCommitList, - isPRConflicts, - isPRConversation, - isPRFile404, - isPRFiles, - isPRList, - isPasswordConfirmation, - isPrivateUserProfile, - isProfile, - isProfileRepoList, - isProject, - isProjects, - isPublicRepo, - isQuickPR, - isReleases, - isReleasesOrTags, - isRepliesSettings, - isRepo, - isRepoCommitList, - isRepoFile404, - isRepoForksList, - isRepoGitObject, - isRepoHome, - isRepoIssueList, - isRepoIssueOrPRList, - isRepoMainSettings, - isRepoNetworkGraph, - isRepoPRList, - isRepoRoot, - isRepoSearch, - isRepoSettings, - isRepoTaxonomyIssueOrPRList, - isRepoTree, - isRepoWiki, - isRepositoryActions, - isSingleCommit, - isSingleFile, - isSingleGist, - isSingleReleaseOrTag, - isTags, - isTeamDiscussion, - isTrending, - isUserProfile, - isUserProfileFollowersTab, - isUserProfileFollowingTab, - isUserProfileMainTab, - isUserProfileRepoTab, - isUserProfileStarsTab, - isUserSettings, - isUserTheOrganizationOwner, - utils -}; diff --git a/distribution/index.test.d.ts b/distribution/index.test.d.ts deleted file mode 100644 index cb0ff5c3..00000000 --- a/distribution/index.test.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {};