Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
biw committed Nov 9, 2017
1 parent ccb3e7d commit 76ce51b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -2,11 +2,11 @@

## [Download on Chrome Store](https://chrome.google.com/webstore/detail/comic-sans-everything/oaehjhfpohkdjkpcdbblepomnflojfli)

Chrome Extention that turns all website font to Comic Sans MS. Now with the ablity to switch cases!
Chrome Extension that turns all website font to Comic Sans MS. Now with the ability to switch cases!

![screenshot](https://user-images.githubusercontent.com/6139501/29202148-f53b7fb0-7e19-11e7-903e-80b6a916e279.gif)
![screen-shot](https://user-images.githubusercontent.com/6139501/29202148-f53b7fb0-7e19-11e7-903e-80b6a916e279.gif)

## Non Windows or MacOS Systems
## Linux Systems

You probably need to [install Comic Sans](http://www.howtogeek.com/howto/15495/add-microsoft-core-fonts-to-ubuntu/).

Expand Down
3 changes: 2 additions & 1 deletion background.js
Expand Up @@ -3,7 +3,7 @@
let fontOverwrite = '* {font-family: Comic Sans MS !important}'
let transformOverwrite = '* {text-transform:uppercase}'

// if we dont have the styleDom, create it
// if we don't have the styleDom, create it
let styleDom = document.getElementById('comic-sans-everything-style')
if (!styleDom) {
styleDom = document.querySelector('head').appendChild(document.createElement('style'))
Expand All @@ -28,4 +28,5 @@ const updateStyle = () => {
// run once on file load
updateStyle()

// runs every time the `popup-script.js` file send a message to `background.js`
window.chrome.runtime.onMessage.addListener(updateStyle)
8 changes: 4 additions & 4 deletions manifest.json
@@ -1,17 +1,17 @@
{
"manifest_version": 2,
"name": "Comic Sans Everything",
"description": "Extention that turns all website font to Comic Sans MS.",
"version": "2.1.2",
"homepage_url": "https://www.twitter.com/719ben",
"description": "Extension that turns all website font to Comic Sans MS",
"version": "2.1.3",
"homepage_url": "https://github.com/719Ben/comic-sans-everything",
"icons": {
"16": "icons/16.png",
"48": "icons/48.png",
"128": "icons/128.png"
},
"browser_action": {
"default_icon": "icons/16.png",
"default_title": "Change Comic Sans settings",
"default_title": "Change Comic Sans Everything settings",
"default_popup": "popup.html"
},
"permissions": [
Expand Down
60 changes: 48 additions & 12 deletions popup-script.js
@@ -1,29 +1,61 @@
'use strict'

const setStatus = (status) => {
// this might seemed reversed, it is
// we want to show the user the opposite of what the current status is
if (status === true) {
document.getElementById('status').innerHTML = 'Off'
} else if (status === false) {
document.getElementById('status').innerHTML = 'On'
}
}

const setUppercase = (uppercase) => {
// this might seemed revered, it is, see `setStatus`
if (uppercase === true) {
document.getElementById('case_status').innerHTML = 'lowercase'
document.getElementById('case_switch').setAttribute(
'style', 'text-transform:lowercase;'
)
} else if (uppercase === false) {
document.getElementById('case_status').innerHTML = 'uppercase'
document.getElementById('case_switch').setAttribute(
'style', 'text-transform:uppercase;'
)
}
}

window.chrome.storage.sync.get(['status', 'uppercase'], (items) => {
// if there are no errors starting chrome calls
if (!window.chrome.runtime.error) {
// if this is the first time the extension starts
if (items.status === undefined) {
window.chrome.storage.sync.set({ 'status': true })
document.getElementById('status').innerHTML = 'Off'
setStatus(true)
} else if (items.status) {
document.getElementById('status').innerHTML = 'Off'
setStatus(false)
} else if (!items.status) {
document.getElementById('status').innerHTML = 'On'
setStatus(false)
}

// if this is the first time the extension starts
if (items.uppercase === undefined) {
window.chrome.storage.sync.set({ 'uppercase': false })
document.getElementById('case_status').innerHTML = 'uppercase'
document.getElementById('case_switch').setAttribute('style', 'text-transform:uppercase;')
setUppercase(false)
} else if (items.uppercase) {
document.getElementById('case_status').innerHTML = 'lowercase'
document.getElementById('case_switch').setAttribute('style', 'text-transform:lowercase;')
setUppercase(true)
} else if (!items.uppercase) {
document.getElementById('case_status').innerHTML = 'uppercase'
document.getElementById('case_switch').setAttribute('style', 'text-transform:uppercase;')
setUppercase(false)
}
}
})

// when people click the credit button
document.getElementById('twttr_button').onclick = () => {
window.chrome.tabs.create({ url: 'http://twitter.com/719ben' })
// open up a new tab with Github
window.chrome.tabs.create({
url: 'https://github.com/719ben/https://github.com/719Ben/comic-sans-everything'
})
}
document.getElementById('font_switch').onclick = () => {
window.chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
Expand All @@ -45,10 +77,14 @@ document.getElementById('case_switch').onclick = () => {
window.chrome.storage.sync.get('uppercase', (items) => {
if (items.uppercase) {
document.getElementById('case_status').innerHTML = 'uppercase'
document.getElementById('case_switch').setAttribute('style', 'text-transform:uppercase;')
document.getElementById('case_switch').setAttribute(
'style', 'text-transform:uppercase;'
)
} else {
document.getElementById('case_status').innerHTML = 'lowercase'
document.getElementById('case_switch').setAttribute('style', 'text-transform:lowercase;')
document.getElementById('case_switch').setAttribute(
'style', 'text-transform:lowercase;'
)
}
window.chrome.storage.sync.set({ 'uppercase': !items.uppercase })
window.chrome.tabs.sendMessage(activeTab.id, {'uppercase': !items.uppercase})
Expand Down
2 changes: 1 addition & 1 deletion popup.html
Expand Up @@ -9,7 +9,7 @@
<h1>Comic Sans Everything!</h1>
<button id="font_switch">Turn Comic Sans <span id="status"></span></button>
<button id="case_switch">Switch to <span id="case_status"></span></button>
<a id="twttr_button" href="https://twitter.com/719ben"><h2>Made with laughter by @719ben</h2></a>
<a id="twttr_button" href="#"><h2>GitHub Repo</h2></a>
</div>
<script type="text/javascript" src="popup-script.js"></script>
</body>
Expand Down

0 comments on commit 76ce51b

Please sign in to comment.