Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
"message": "For example:",
"description": "Info text with an example JIRA URL. URL is followed after the sentence"
},
"bb_baseURL": {
"message": "Bitbucket base URL",
"description": "base URL you need to enter for a valid repo URL"
},
"bb_baseURLDescription": {
"message": "Please enter here the Bitbucket URL for the Quick Search. Please keep in mind that the URL should end with a forward slash.",
"description": "Description text of the bitbucket base URL"
},
"bb_baseURLExample": {
"message": "For example:",
"description": "Info text with an example Bitbucket URL. URL is followed after the sentence"
},
"baseURLMoreInfo": {
"message": " More information regarding the JIRA Quick Search can be found here:",
"description": "Info text for the JIRA QuickSearch function. URL is followed after the sentence"
Expand Down
7 changes: 7 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ select {
input[type='text'].quiji-options-jira-url {
max-width: 600px;
}
input[type='text'].quiji-options-bitbucket-url {
max-width: 600px;
}

input[type='text'].quiji-options-bitbucket-prefix {
max-width: 200px;
}

select {
max-width: 250px;
Expand Down
21 changes: 21 additions & 0 deletions src/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ <h2 class="h3" data-i18n="baseURL"></h2>
pattern="[Hh][Tt][Tt][Pp][Ss]?:\/\/(?:(?:[a-zA-Z\u00a1-\uffff0-9]+-?)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]+-?)*[a-zA-Z\u00a1-\uffff0-9]+)*(?:\.(?:[a-zA-Z\u00a1-\uffff]{2,}))(?::\d{2,5})?(?:\/[^\s]*)?"
/>

<!-- Bitbucket Base URL Section -->
<h2 class="h3" data-i18n="bb_baseURL"></h2>
<p data-i18n="bb_baseURLDescription"></p>
<p>
<span class="quiji-options-url-text" data-i18n="bb_baseURLExample"></span>
<span class="quiji-url-highlight">https://bitbucket.org/</span>
</p>
<input
type="text"
class="quiji-options-bitbucket-url"
required
placeholder="https://bitbucket.org/"
pattern="[Hh][Tt][Tt][Pp][Ss]?:\/\/(?:(?:[a-zA-Z\u00a1-\uffff0-9]+-?)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]+-?)*[a-zA-Z\u00a1-\uffff0-9]+)*(?:\.(?:[a-zA-Z\u00a1-\uffff]{2,}))(?::\d{2,5})?(?:\/[^\s]*)?"
/>
<input
type="text"
class="quiji-options-bitbucket-prefix"
required
placeholder="bb:"
/>

<!-- Default Action Section -->
<h2 class="h3" data-i18n="defaultAction"></h2>
<p data-i18n="defaultActionDescription"></p>
Expand Down
19 changes: 19 additions & 0 deletions src/js/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,34 @@ async function openTicket(ticket: string, newTab: boolean) {
{
jiraURL: '',
trimSpaces: 0,
bitbucketURL: '',
bitbucketPrefix: '',
},
(options) => {
const jiraURL = (options as Options).jiraURL;
const bitbucketURL = (options as Options).bitbucketURL;

let bitbucketPrefix = (options as Options).bitbucketPrefix;
bitbucketPrefix = encodeURIComponent(bitbucketPrefix);

const trimSpaces = options.trimSpaces !== 0;
let newURL: string;

if (trimSpaces) {
ticket = decodeURIComponent(ticket).replace(/\s/g, '');
}

if (ticket.startsWith(bitbucketPrefix)) {
console.log('Bitbucket ticket detected');
if (!bitbucketURL) {
void _browser.runtime.openOptionsPage();
} else {
newURL = ticket.replace(bitbucketPrefix, bitbucketURL);
void openURLInTab(newTab, newURL);
return;
}
}

void storage.set({
lastTicket: ticket,
});
Expand Down
2 changes: 2 additions & 0 deletions src/js/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const _browser: BrowserType = isFirefox ? browser : chrome;
export const storage = _browser.storage.sync || _browser.storage.local;

export interface Options {
bitbucketURL: string;
bitbucketPrefix: string;
jiraURL: string;
defaultOption: number;
trimSpaces: number;
Expand Down
27 changes: 27 additions & 0 deletions src/js/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ const saveOptions = async (event: Event) => {

const jiraInput = document.querySelector<HTMLInputElement>('.quiji-options-jira-url');

const bitBucketInput = document.querySelector<HTMLInputElement>('.quiji-options-bitbucket-url');
const bitBucketPrefixInput = document.querySelector<HTMLInputElement>('.quiji-options-bitbucket-prefix');

if (bitBucketInput && bitBucketPrefixInput) {
const bitbucket = bitBucketInput.value;
const prefix = bitBucketPrefixInput.value;

await storage.set({
bitbucketURL: bitbucket,
bitbucketPrefix: prefix,
});
}

if (jiraInput) {
// Check for null before accessing properties
const jira = jiraInput.value;
Expand Down Expand Up @@ -53,6 +66,8 @@ const restoreOptions = async () => {
jiraURL: '',
defaultOption: 0,
trimSpaces: 0,
bitbucketURL: '',
bitbucketPrefix: '',
} as Options,
(options) => {
// Type the options parameter
Expand All @@ -61,6 +76,18 @@ const restoreOptions = async () => {
jiraInput.value = (options as Options).jiraURL || '';
}

// Type the options parameter
const bitbucketInput = document.querySelector<HTMLInputElement>('.quiji-options-bitbucket-url');
if (bitbucketInput) {
bitbucketInput.value = (options as Options).bitbucketURL || '';
}

// Type the options parameter
const prefixInput = document.querySelector<HTMLInputElement>('.quiji-options-bitbucket-prefix');
if (prefixInput) {
prefixInput.value = (options as Options).bitbucketPrefix || '';
}

// Map 0 to currentTab and 1 to newTab
const selectElement = document.querySelector<HTMLSelectElement>('select');
if (selectElement) {
Expand Down
Loading