Skip to content

Commit

Permalink
Lint all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrammond committed Feb 24, 2019
1 parent 01da4a6 commit 6d96b3c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
extends: 'standard',
globals: {

chrome: false
},
rules: {
'semi': [2, 'always'],
Expand All @@ -23,9 +23,9 @@ module.exports = {
},
overrides: [
{
files: ['src/scripts/*.js'],
files: ['src/scripts/content.js'],
globals: {
chrome: false,
marked: false
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

chrome.browserAction.setBadgeText({text: 'PR'});
chrome.browserAction.setBadgeText({ text: 'PR' });
37 changes: 16 additions & 21 deletions src/scripts/content.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

(function () {
var defaultUrl = 'https://raw.github.com/sprintly/sprint.ly-culture/master/pr-template.md';
var options, isCustom;
const defaultUrl = 'https://raw.github.com/sprintly/sprint.ly-culture/master/pr-template.md';
let options; let isCustom;

var isGH = window.location.href.match(/github.com/);
var isBB = window.location.href.match(/bitbucket.org/);
const isGH = window.location.href.match(/github.com/);
const isBB = window.location.href.match(/bitbucket.org/);

loadOptions(getTemplate);

Expand All @@ -30,8 +30,8 @@
}

function insertTemplate (template) {
var el = null;
var isBitbucketProseEditor = false;
let el = null;
let isBitbucketProseEditor = false;

if (isGH && options.githubEnabled) {
el = document.getElementById('pull_request_body');
Expand All @@ -40,37 +40,33 @@
if (window.location.href.indexOf('/update') !== -1) return;

// Check for new beta editor, falling back to default
var test = document.getElementById('ak_editor_description');
const test = document.getElementById('ak_editor_description');
isBitbucketProseEditor = !!test;

// Deal with bitbucket immediately since it's getting a bit bespoke now.
// One day, we'll re-write this whole thing..
if (isBitbucketProseEditor) {
setTimeout(function () {
el = document.getElementsByClassName('ProseMirror')[0];
insertContenteditable(el, template, options.bitbucketOverwrite)
insertContenteditable(el, template, options.bitbucketOverwrite);
}, 2500);
return;
} else {
el = document.getElementById('id_description');
insertInput(el, template, options.bitbucketOverwrite)
insertInput(el, template, options.bitbucketOverwrite);
}


} else if (isCustom && options.customEnabled && options.customRepoDescriptionID) {
el = document.getElementById(options.customRepoDescriptionID.toString());
}

if (el === null) return;

if (isGH)
return insertInput(el, template, true);
if (isGH) { return insertInput(el, template, true); }

// If this looks like an "Edit PR" page, do not insert the template.
if (window.location.href.indexOf('/update') !== -1) return;

if (isCustom)
insertInput(el, template, options.bitbucketOverwrite);
if (isCustom) { insertInput(el, template, options.bitbucketOverwrite); }
}

// Old textarea editor
Expand All @@ -86,19 +82,19 @@

// New contenteditable editor
function insertContenteditable (el, template, overwrite) {
console.log(el.innerHTML)
console.log(el.innerHTML);
setTimeout(function () {
if (overwrite) {
el.innerHTML = marked(template);
} else {
el.innerHTML = el.innerHTML + ((el.innerHTML && el.innerHTML.length ? '<br/>' : '') + marked(template));
}
}, 1000)
}, 1000);
}

function getTemplate () {
var templateToLoad;
var xhr = new XMLHttpRequest();
let templateToLoad;
const xhr = new XMLHttpRequest();

isCustom = (options.customRepoRegex) ? new RegExp(options.customRepoRegex).test(window.location.href) : false;

Expand All @@ -120,9 +116,8 @@
}

if (templateToLoad) {
xhr.open("GET", (templateToLoad), true);
xhr.open('GET', (templateToLoad), true);
xhr.send();
}

}
})();
53 changes: 24 additions & 29 deletions src/scripts/options.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
'use strict';
(function () {
var defaultUrl = 'https://raw.github.com/sprintly/sprint.ly-culture/master/pr-template.md';
const defaultUrl = 'https://raw.github.com/sprintly/sprint.ly-culture/master/pr-template.md';

// Saves options to chrome.storage
function save_options() {
function saveOptions () {
const githubEnabled = document.getElementById('githubEnabled').checked;
const githubTemplateUrl = document.getElementById('githubTemplateUrl').value;
const githubTemplateContent = document.getElementById('githubTemplateContent').value;
const bitbucketEnabled = document.getElementById('bitbucketEnabled').checked;
const bitbucketTemplateContent = document.getElementById('bitbucketTemplateContent').value;
const bitbucketTemplateUrl = document.getElementById('bitbucketTemplateUrl').value;
const bitbucketOverwrite = document.getElementById('bitbucketOverwrite').checked;

var githubEnabled = document.getElementById('githubEnabled').checked;
var githubTemplateUrl = document.getElementById('githubTemplateUrl').value;
var githubTemplateContent = document.getElementById('githubTemplateContent').value;
var bitbucketEnabled = document.getElementById('bitbucketEnabled').checked;
var bitbucketTemplateContent = document.getElementById('bitbucketTemplateContent').value
var bitbucketTemplateUrl = document.getElementById('bitbucketTemplateUrl').value;
var bitbucketOverwrite = document.getElementById('bitbucketOverwrite').checked;

var customEnabled = document.getElementById('customRepoEnabled').checked;
var customTemplateContent = document.getElementById('customRepoTemplateContent').value;
var customTemplateUrl = document.getElementById('customRepoTemplateUrl').value;
var customRepoRegex = document.getElementById('customRepoRegex').value;
var customRepoDescriptionID = document.getElementById('customRepoDescriptionID').value;
const customEnabled = document.getElementById('customRepoEnabled').checked;
const customTemplateContent = document.getElementById('customRepoTemplateContent').value;
const customTemplateUrl = document.getElementById('customRepoTemplateUrl').value;
const customRepoRegex = document.getElementById('customRepoRegex').value;
const customRepoDescriptionID = document.getElementById('customRepoDescriptionID').value;

chrome.storage.sync.set({
githubEnabled: githubEnabled,
githubTemplateUrl: githubTemplateUrl ? githubTemplateUrl : defaultUrl,
githubTemplateUrl: githubTemplateUrl || defaultUrl,
githubTemplateContent: githubTemplateContent || '',
bitbucketEnabled: bitbucketEnabled,
bitbucketTemplateUrl: bitbucketTemplateUrl ? bitbucketTemplateUrl : defaultUrl,
bitbucketTemplateUrl: bitbucketTemplateUrl || defaultUrl,
bitbucketTemplateContent: bitbucketTemplateContent || '',
customEnabled: customEnabled,
customTemplateUrl: customTemplateUrl ? customTemplateUrl : defaultUrl,
customTemplateUrl: customTemplateUrl || defaultUrl,
customTemplateContent: customTemplateContent || '',
customRepoRegex: customRepoRegex ? customRepoRegex : '',
customRepoDescriptionID: customRepoDescriptionID ? customRepoDescriptionID : '',
customRepoRegex: customRepoRegex || '',
customRepoDescriptionID: customRepoDescriptionID || '',
bitbucketOverwrite: bitbucketOverwrite

}, function () {
// Update status to let user know options were saved.
var result = document.getElementById('save-result');
result.className = result.className.replace(/\bhide\b/,'');
const result = document.getElementById('save-result');
result.className = result.className.replace(/\bhide\b/, '');

setTimeout(function () {
result.className = result.className + ' hide';
}, 1500);
});

}

// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {

function restoreOptions () {
chrome.storage.sync.get({
githubEnabled: true,
githubTemplateUrl: defaultUrl,
Expand Down Expand Up @@ -78,11 +75,9 @@
document.getElementById('customRepoTemplateContent').value = items.customTemplateContent;
document.getElementById('customRepoRegex').value = items.customRepoRegex;
document.getElementById('customRepoDescriptionID').value = items.customRepoDescriptionID;

});

}

document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
})();

0 comments on commit 6d96b3c

Please sign in to comment.