Skip to content

Commit

Permalink
feat: bitbucket support 💥
Browse files Browse the repository at this point in the history
  • Loading branch information
shatgupt committed Jun 24, 2017
1 parent ccca21a commit f562b97
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
## Supported Websites
1. [Github](https://github.com/shatgupt/runmycode-test/blob/master/ruby.rb)
2. [Gitlab](https://gitlab.com/shatgupt/runmycode-test/blob/master/ruby.rb)
3. [Go by Example](https://gobyexample.com/hello-world)
4. [BitBucket](https://bitbucket.org) (soon)
3. [BitBucket](https://bitbucket.org/shatgupt/runmycode-test/src/c9cda15cb3fa1144e53f199e6ac6003ee5bdb25b/ruby.rb) - Editor not supported
4. [Go by Example](https://gobyexample.com/hello-world)
5. [Github Gist](https://gist.github.com) (soon)
6. [Gitlab Snippets](https://gitlab.com/snippets) (soon)
7. [BitBucket Snippets](https://bitbucket.org/snippets) (soon)
Expand Down
2 changes: 1 addition & 1 deletion build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
'description': 'Run code online from sites like Github, Gitlab and more',
'author': 'Shatrughn Gupta',
'homepage_url': 'https://runmycode.online',
'version': '1.3.0',
'version': '1.3.1',
'icons': { '128': 'icon128.png' },
'manifest_version': 2,
'content_scripts': [
Expand Down
74 changes: 49 additions & 25 deletions content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,32 @@ const platformMap = {
getCode: () => getCodeFromLines($('table').querySelectorAll('.code>.highlight>pre'))
}
}
},
bitbucket: {
getLang: () => getLangFromPathExt(),
getPage: () => {
if ($('#editor-container>#source-view')) return 'show'
},
injectRunButton: () => {
$('.file-source-container>.toolbar>.secondary').insertAdjacentHTML('afterbegin', '<div class="aui-buttons"><button id="runmycode-popup-runner" class="aui-button aui-button-primary" style="font-weight: normal;">Run</button></div>')
},
pages: {
show: {
getCode: () => $('.code').textContent
}
}
}
}

const platform = getPlatform()
let runnerAdded = false
let lang, page
let lang, page, runner, runnerCloseBtn, runBtn, runInput, runOutput
let runnerVisible = false

const initRunner = () => {
if (runnerAdded) return

if ($('#runmycode-popup-runner')) return // Run button is already added
platformMap[platform].injectRunButton()
runnerAdded = true
const runnerWidth = 350

const runnerWidth = 350
const runnerMarkup = `<style>
#runmycode-runner {
width: ${runnerWidth}px;
Expand Down Expand Up @@ -154,26 +166,39 @@ const initRunner = () => {
</div>
`
// inject runner styles and markup
body.insertAdjacentHTML('afterbegin', runnerMarkup)
let justRunBtnToBeInjected = false
if ($('#runmycode-runner')) justRunBtnToBeInjected = true
else body.insertAdjacentHTML('afterbegin', runnerMarkup)

/* *** Start Movable popup https://gist.github.com/akirattii/9165836 ****/
let runnerVisible = false
const runner = $('#runmycode-runner')
const runnerCloseBtn = $('#runmycode-close-runner')
const runBtn = $('#runmycode')
const runInput = $('#runmycode-run-input')
const runOutput = $('#runmycode-run-output')
runner = $('#runmycode-runner')
runnerCloseBtn = $('#runmycode-close-runner')
runBtn = $('#runmycode')
runInput = $('#runmycode-run-input')
runOutput = $('#runmycode-run-output')

$('#runmycode-popup-runner').addEventListener('click', (e) => {
e.preventDefault()
if (runnerVisible) {
runnerCloseBtn.click()
} else {
runnerVisible = true
runner.style.display = 'block'
}
})
// injected Run btn and added click listener, no more work to do if justRunBtnToBeInjected
if (justRunBtnToBeInjected) return

let runnerOffset = { x: 0, y: 0 }
runner.style.left = `${(window.innerWidth - runnerWidth) / 2}px` // have popup in the center of the screen

runnerCloseBtn.addEventListener('click', (e) => {
runnerCloseBtn.addEventListener('click', () => {
runner.style.display = 'none'
runnerVisible = false
})
window.addEventListener('keydown', (e) => {
if (e.keyCode === 27) { // if ESC key pressed
runnerCloseBtn.click(e)
runnerCloseBtn.click()
}
})

Expand All @@ -192,16 +217,6 @@ const initRunner = () => {
window.addEventListener('mousemove', popupMove, true)
e.preventDefault() // disable text selection
})

$('#runmycode-popup-runner').addEventListener('click', (e) => {
e.preventDefault()
if (runnerVisible) {
runnerCloseBtn.click(e)
} else {
runnerVisible = true
runner.style.display = 'block'
}
})
/* *** End Movable popup ****/

// collapse input, output panels
Expand Down Expand Up @@ -277,12 +292,21 @@ const initRunner = () => {
})
}

const cleanUpRunner = () => {
if (runner) {
runInput.value = ''
runOutput.value = ''
runnerCloseBtn.click()
}
}

const handlePageUpdate = () => {
// console.log('platform:', platform)
if (platformMap[platform]) {
page = platformMap[platform].getPage()
lang = platformMap[platform].getLang()
// console.log('page:', page, ' lang:', lang)
cleanUpRunner()
if (lang && page) initRunner()
}
}
Expand Down
1 change: 1 addition & 0 deletions runmycode-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
margin: 0;
font-size: 14px;
font-weight: 600;
line-height: inherit;
}

#runmycode-runner .panel-title>a {
Expand Down

0 comments on commit f562b97

Please sign in to comment.