Skip to content

Commit

Permalink
eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Darran Boyd committed Nov 21, 2024
1 parent e95ddb1 commit e92aad4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { getExtensionConfig, TCConfig } from './popup/config';
import { logDebugMessage } from '../debugLogger';

const tcButtonText = 'View in Threat Composer'
const tcButtonId = 'threatComposerButton'
const tcButtonText = 'View in Threat Composer';
const tcButtonId = 'threatComposerButton';

interface TCJSONSimplifiedSchema {
schema?: string;
Expand Down Expand Up @@ -99,10 +99,10 @@ async function getTCJSONCandidate(url: string, element: HTMLElement, config: TCC

async function handleRawFile(config: TCConfig) {
const element = document.getElementsByTagName('pre');
const tcButton = document.createElement('button')
tcButton.textContent = tcButtonText
tcButton.id = tcButtonId
tcButton.disabled = true
const tcButton = document.createElement('button');
tcButton.textContent = tcButtonText;
tcButton.id = tcButtonId;
tcButton.disabled = true;
if (element) {
document.body.prepend(tcButton);
window.scrollTo(0, 0); //Scroll to top
Expand All @@ -113,14 +113,12 @@ async function handleRawFile(config: TCConfig) {
};

function isRawSite(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationRawUrlRegexes))
return true
if (matchesAnyRegex(window.location.href, tcConfig.integrationRawUrlRegexes)) {return true;}
return false;
}

function isGitLabSite(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationGitLabCodeBrowserUrlRegexes))
return true;
if (matchesAnyRegex(window.location.href, tcConfig.integrationGitLabCodeBrowserUrlRegexes)) {return true;}

// Check for the presence of the GitLab logo or branding
const gitlabLogo = document.querySelector('img[src*="gitlab.com/assets/logo"]');
Expand All @@ -146,26 +144,22 @@ function isGitLabSite(tcConfig: TCConfig) {
}

function isGitHubSite(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationGitHubCodeBrowserUrlRegexes))
return true;
if (matchesAnyRegex(window.location.href, tcConfig.integrationGitHubCodeBrowserUrlRegexes)) {return true;}
return false;
}

function isCodeCatalystSite(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationCodeCatalystCodeBrowserUrlRegexes))
return true;
if (matchesAnyRegex(window.location.href, tcConfig.integrationCodeCatalystCodeBrowserUrlRegexes)) {return true;}
return false;
}

function isAmazonCodeBrowser(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationAmazonCodeBrowserUrlRegexes))
return true;
if (matchesAnyRegex(window.location.href, tcConfig.integrationAmazonCodeBrowserUrlRegexes)) {return true;}
return false;
}

function isBitbucketSite(tcConfig: TCConfig) {
if (matchesAnyRegex(window.location.href, tcConfig.integrationBitBucketCodeBrowserUrlRegexes))
return true;
if (matchesAnyRegex(window.location.href, tcConfig.integrationBitBucketCodeBrowserUrlRegexes)) {return true;}

// Check for the presence of Bitbucket-specific elements
const bitbucketMeta = document.querySelectorAll('meta[name="application-name"][content="Bitbucket"]');
Expand All @@ -178,7 +172,7 @@ function isBitbucketSite(tcConfig: TCConfig) {
}

function ViewInThreatComposerButtonExists() {
return document.getElementById(tcButtonId)
return document.getElementById(tcButtonId);
}

async function handleGitHubCodeBrowser(gitHubState: TCGitHubState, tcConfig: TCConfig) {
Expand All @@ -189,22 +183,21 @@ async function handleGitHubCodeBrowser(gitHubState: TCGitHubState, tcConfig: TCC
gitHubState.stopProcessing = false;
}

if (ViewInThreatComposerButtonExists())
return;
if (ViewInThreatComposerButtonExists()) {return;}

var regExCheck = new RegExp(tcConfig.fileExtension);

if (window.location.href.match(regExCheck)) {
let element = document.querySelector('[aria-label="Copy raw content"]');

if (element && !gitHubState.stopProcessing) {
logDebugMessage(tcConfig, `Element (copy raw content) found and stopProcessing = false... lets do it`)
logDebugMessage(tcConfig, 'Element (copy raw content) found and stopProcessing = false... lets do it');
gitHubState.stopProcessing = true;
const rawButton = document.querySelector('[aria-label="Copy raw content"]');
const tcButton = document.createElement('button')
tcButton.textContent = tcButtonText
tcButton.id = tcButtonId
tcButton.disabled = true
const tcButton = document.createElement('button');
tcButton.textContent = tcButtonText;
tcButton.id = tcButtonId;
tcButton.disabled = true;
tcButton.setAttribute('type', 'button');
tcButton.setAttribute('class', rawButton?.classList.toString());
tcButton.setAttribute('data-size', 'small');
Expand All @@ -219,8 +212,7 @@ async function handleGitHubCodeBrowser(gitHubState: TCGitHubState, tcConfig: TCC

async function handleAmazonCodeBrowser(codeBrowserState: TCCodeBrowserState, config: TCConfig) {

if (ViewInThreatComposerButtonExists())
return;
if (ViewInThreatComposerButtonExists()) {return;}

const element = document.getElementsByClassName('file_header');
if (element && !codeBrowserState.stopProcessing) {
Expand All @@ -229,9 +221,9 @@ async function handleAmazonCodeBrowser(codeBrowserState: TCCodeBrowserState, con
if (fileActionsDiv) {
const fileActionsButtonGroup = fileActionsDiv.getElementsByClassName('button_group')[0];
const tcListItem = document.createElement('li');
const tcButton = document.createElement('a')
tcButton.textContent = tcButtonText
tcButton.id = tcButtonId
const tcButton = document.createElement('a');
tcButton.textContent = tcButtonText;
tcButton.id = tcButtonId;
tcButton.setAttribute('class', 'minibutton');
tcButton.textContent = tcButtonText;
tcButton.style.pointerEvents = 'none';
Expand Down Expand Up @@ -263,8 +255,7 @@ function checkNoPresentation(element: HTMLElement) {

async function handleBitbucketCodeBrowser(bitBucketState: TCBitBucketState, config: TCConfig) {

if (ViewInThreatComposerButtonExists())
return;
if (ViewInThreatComposerButtonExists()) {return;}

const element = document.querySelectorAll("[data-testid='file-actions']")[0];

Expand Down Expand Up @@ -296,19 +287,18 @@ async function handleGitLabBrowser(gitLabState: TCGitLabState, tcConfig: TCConfi
gitLabState.stopProcessing = false;
}

if (ViewInThreatComposerButtonExists())
return;
if (ViewInThreatComposerButtonExists()) {return;}

var regExCheck = new RegExp(tcConfig.fileExtension);
if (window.location.href.match(regExCheck)) {
const element = (document.querySelectorAll("a[title='Open raw']")[0] as HTMLElement);
if (element && !gitLabState.stopProcessing) {
logDebugMessage(tcConfig, 'Triggering UI update for GitLab');
gitLabState.stopProcessing = true;
const tcButton = document.createElement('a')
tcButton.id = tcButtonId
const tcButton = document.createElement('a');
tcButton.id = tcButtonId;
tcButton.setAttribute('class', element.classList.toString());
tcButton.innerText = tcButtonText
tcButton.innerText = tcButtonText;
tcButton.style.pointerEvents = 'none';
element.parentNode?.insertBefore(tcButton, element);
const rawPath = location.href.replace(/\/\-\/blob/, '/-/raw');
Expand All @@ -320,16 +310,15 @@ async function handleGitLabBrowser(gitLabState: TCGitLabState, tcConfig: TCConfi

async function handleCodeCatalystCodeViewer(codeCatalystState: TCCodeCatalystState, config: TCConfig) {

if (ViewInThreatComposerButtonExists())
return;
if (ViewInThreatComposerButtonExists()) {return;}

const element = document.getElementsByClassName(
'cs-Tabs__tab-header-actions',
)[0];
if (element && element.hasChildNodes() && !codeCatalystState.stopProcessing) {
codeCatalystState.stopProcessing = true;
const tcButton = document.createElement('a')
tcButton.id = tcButtonId
const tcButton = document.createElement('a');
tcButton.id = tcButtonId;
const currentAnchor = element.firstChild;
tcButton.setAttribute(
'class',
Expand All @@ -340,7 +329,7 @@ async function handleCodeCatalystCodeViewer(codeCatalystState: TCCodeCatalystSta

const tcSpan = document.createElement('span');
tcSpan.setAttribute('class', currentSpan.classList.toString());
tcSpan.textContent = tcButtonText
tcSpan.textContent = tcButtonText;

tcButton.appendChild(tcSpan);

Expand Down Expand Up @@ -403,12 +392,12 @@ async function ContentScriptInScope(tcConfig: TCConfig) {
});
}

let match = false
let match = false;

inScopeRegexes.forEach(entry => {
if (window.location.href.match(entry)) {
logDebugMessage(tcConfig, 'Got a URL match for regex entry: ' + entry);
match = true
match = true;
}
});
return match;
Expand Down Expand Up @@ -473,7 +462,7 @@ export default defineContentScript({
tcConfig.integrationGitHubCodeBrowser && isGitHubSite(tcConfig)
) {
logDebugMessage(tcConfig,
'Assuming GitHub code browser'
'Assuming GitHub code browser',
);
await handleGitHubCodeBrowser(gitHubState, tcConfig);
let observerForGitHubCodeViewer = new MutationObserver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const DefaultConfig: TCConfig = {
integrationGitLabCodeBrowser: true,
integrationGitLabCodeBrowserUrlRegexes: [/gitlab.com/],
integrationRaw: true,
integrationRawUrlRegexes: [/raw.githubusercontent.com/,/raw=1/,/raw/],
integrationRawUrlRegexes: [/raw.githubusercontent.com/, /raw=1/, /raw/],
target: ThreatComposerTarget.BUILT_IN,
};

Expand Down

0 comments on commit e92aad4

Please sign in to comment.